function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gokubigokubi 

Dealing with Record Types in a way that will load to Appexchange

Winter '07 added some validation on the upload of Appexchange packages that affected some of my code. Any S-Controls that had explicit references to Record Type Ids wouldn't load to the Appexchange. I would often write code like this:

var PurchaseRecordTypeId = "0000000000fff55";

When I needed this code in another instance, I would Appexchange it, install it, and then change the hard-coded reference.

Here's more elegant code that gets Record Type Ids dynamically, and doesn't trip the Appexchange validator:
var oOppRecordTypes = getRecrodTypesforObjects("Opportunity");

var DonationLabel = "Gift";
var MembershipLabel = "Membership";
var DonationRecordType = oOppRecordTypes[DonationLabel].Id;
var MembershipRecordType = oOppRecordTypes[MembershipLabel].Id;

function getRecrodTypesforObjects(ObjectName) {
 var RecordTypesArray = new Array();
 sfc = sforce.connection;

 var result = sfc.query("Select r.Id, r.Name, r.SobjectType from
 RecordType r where r.IsActive=true and r.SobjectType='"+ ObjectName +"'");

 var RecordTypesArray = result.getArray("records");
 oRecordTypes = new Object();
 for (var i=0;i<RecordTypesArray.length;i++) {
  var oSingleRecordType = new Object();
  oSingleRecordType.Name=RecordTypesArray[i].Name;
  oSingleRecordType.Id=RecordTypesArray[i].Id;
  oRecordTypes[RecordTypesArray[i].Name]=oSingleRecordType;
 }
 return oRecordTypes;
}

 I'd love to hear feedback if you have suggestions on how this code could do the job better.

Enjoy!

cheenathcheenath
Nice sample. Do you mind if I add this to my list of samples in Ajax Tools?

Thanks.





gokubigokubi
Feel free!