Progress on Appexchanging record types
I wrote the other day about how I was being stymied by the Winter ‘07 Appexchange. In my post I never used the word bug, because I didn’t really see the issues I was having as technical flaws in their Appexchange implementation, but more a disconnect between my process and the tool. I’m happy to say that with a nudge in the right direction from Salesforce.com (more bout that later), I was able to overcome the Record Type issue and found a possible solution to the custom field problem.
If you type Record Type Ids in your code, the Appexchange validator picks them up and won’t let you continue. In the past we were just storing those Ids in the code and changing them when we switched instances. It was quick and dirty and worked with the old Appexhcange. I wrote a simple function that will pull those Ids programatically and it doesn’t cause the validator halt.
var DonationLabel = "Gift";
var MembershipLabel = "Membership";
var oOppRecordTypes = getRecrodTypesforObjects("Opportunity");
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;
}
We’re getting all the Record Types on an object and calling them by name. This has the added benefit of needing no touches if we switch instances and the Record Types are named correctly. Hooray!
I also noticed as I loaded this code to the Appexchange that the 10 custom fields I am calling were not seen as references by the validator. I think this is because the field names are created on the fly–they are names like MembershipFY2006, MembershipFY2007, etc. So we may be able to fool the validator by using variables whenever we’re referencing custom fields. I’ll have to try some tests to find out just how smart the validator is. So this may be a hooray as well. I’ll reserve judgement until further testing.
So the Appexchange isn’t really crippled, it’s just that changes I didn’t understand happened to the platform and my previous work processes were foiled by those changes. I may be able to get back to full functioning on the Appexchange with a couple changes to process and coding style. That would be great.
It’s also been a very real example of the challenges of relying on technology to get our work done. As technology changes the way we work often needs to change. Sometimes subtly, like with my new routine for getting Record Types. Sometimes the changes are really big, like when you go from Excel for tracking donor prospects to using a full-fledged donor management system. Change is hard, and hardest when you don’t see it coming and it forces you to change the way you work, even if the new way of working is better!
