Sunday, February 28, 2016

UI: Launching Standard Forms with predefined values

From time to time, you come across requirements which require you to launch a SF form with values pre-populated say from formulas.

Solution

Every Object has a code in Salesforce and every field has an ID.
Using the combination of 2 along with the instance URL will help you launch
the page.

Create a custom button under the desired object.
Place it on the desired page; set it to execute Javascript.

Place a URL as follow and we will deconstruct what it means:

https://xxx.salesforce.com/a0m/e?CF00NZ0000001kUmV={!Case.Related_Account__c}&00NZ0000001gnrk={!Case.Account_Cost_Center__c}&CF00NZ0000001gnsT={!Case.CaseNumber}&retURL=/{!Case.Id}


https://xxx.salesforce.com  -- is the instance URL

a0m - stands for the object code for your object. One way to find it click on the screen tab for your object and note the URL; it will look something like this https://xxx.salesforce.com/a0m/o and that is what gives you the object ID or code

00NZ0000001gnrk  - stands for the field id, one way to find it is go to your object definition under setup and then click on the field hyperlink. From the URL, please locate the field ID

{!Case.Account_Cost_Center__c} - value that you need to populate the field with

For picklist fields; put the literal 'CF' before the field ID; see example above CF00NZ0000001kUmV={!Case.Related_Account__c}

Another way of pre-populating fields would be of course to write some kind of a pre-insert trigger but occassionally you can get away with this kind of a hack depending on your situation.

No comments:

Post a Comment