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
Chris760Chris760 

Custom Button Guru's... How do you find out the parameter field ID, *dynamically*?

When you create a custom button that pre-populates various fields with values, you have to specify the salesforce record ID of the field itself in your button parameters and then put "=" (equals), and then follow that up with your merge field to specify the value of that parameter.

 

Normally I get the record ID by just using Google Chrome, right clicking on the field while in Edit view, clicking "Inspect Element" (which gives me the salesforce ID) and then pasting that ID in my button code as the parameter needing to be populated.  I know that other people go a longer route by going to the object in question, clicking on the field name itself, and copying the salesforce ID from the URL (after the "salesforce.com/" part) to extract the custom field salesforce ID.

 

Both of these methods seem rediculously inefficient.  More importantly though, you're hard-coding the field ID into the button itself.  That means, if your company ever moves orgs, OR if you're creating a packaged app, your button will essentially "break" once it's installed in a new org, because the field ID's in your button parameters will no longer match the ID's that salesforce assignes to those fields once you install that package somewhere else.

 

So my question is this... is there some special trick, either using the "URLFOR" function or something else (formula functon, action, etc), that allows you to dynamically generate the salesforce ID of a field that you need to include in your parameters?

 

Essentially, it would allow your buttons to look something like the following (this example would be a list button for Contacts, placed on the Account page layout):

 

{!URLFOR($Action.Contact.New,Account.Id,[FIELDID($ObjectType.Contact,"Contact_Status__c")="New",retURL=Account.Id],true)}

 

So in the above example, I invented a functon called "FIELDID", which takes the Sobject type and API name of the field on that object, does a DescribeSobject() call in the background, and spits out the salesforce ID of that particular field, as opposed to hard coding it perminantly.  No hunting around for salesforce ID's, no hacks, just using the tools available in the Custom Button section.

 

So... that being said, is there some way to do pretty much that, using the button functions available to salesforce users?  If not, then what is the "official" way that Salesforce recommends you use to go about extracting field ID's for the parameters you use in your custom buttons?