URL Hacking in Salesforce – Episode 3


HEY!!! Welcome back, previously in URL Hacking Episode 2 we see how to make possible and working of the pre-populated field values via custom button.

Now in this episode, we will make clear some interesting queries about pre-populating custom fields and lookup fields.
As we know that Salesforce gives us a wonderful ability to create custom fields for every sobject so that our data would be strong for any CRM database. Salesforce holds up many data related to any record in its database.
Let’s suppose you want to pre-populate that custom fields and it comprises of any field type so
How can you achieve this?
Are you using the same method as shown in previous episodes?
Do they work similarly as the standard fields?
Is there any difference between them?
Many such questions may arise  in your mind. So lets play around this and know how it really works.

Salesforce identifies everything on the basis of their “ID”. So we have to get the custom field ID to pre-populate it. In Salesforce there are many ways to get an ID. Previously, we described the method of getting ID’s through Inspect, you can use that also. Or you can use another method also for getting custom field Ids. This is also a simple process, you just want to open your created custom field in your browser which you want to populate. You will get an URL like this.
https://xxxxx.my.salesforce.com/00N2800000CjzMp?setupid=OpportunityFields
00N2800000CjzMp — This is your custom field Id.
So you can append this in your custom button code. Like
var url =”/006/e?retURL={!Account.Id}&accid={!Account.Id}&opp9=1/7/2018&opp3=Pre+Populate+Opportunity&opp7=12345&00N2800000CjzMp=text”

window.open(url,”_self”);

This will pre-populate your custom field while creating a record.
Now let’s have a look on how we can do the same for lookup custom fields. It’s little bit different and a way more interesting. This time not only the field ID will help you. You have to add “CF” in prefix and “_lkid” in suffix. These parameters tells salesforce that this is a custom lookup field.
For example: If we want Account’s Battle Station(Lookup Field) to be populated on its related Opportunity Battle Station (Lookup Field), we need to change our custom button code as follows
var url =”/006/e?retURL={!Account.Id}&accid={!Account.Id}&opp9=1/7/2018&opp3=Pre+Populate+Opportunity&opp7=12345&00N2800000CjzMp=text&CF00N0K00000K04Ol={!Account.pack_age_test__Battle_Station__c}&CF00N0K00000K04Ol_lkid={!Account.pack_age_test__Battle_StationId__c}”
window.open(url,”_self”);

Now we can have a test run to see what is the outcome of our Episode in the below screenshot.
NOTE:
  • If something went wrong, Please check the URL after clicking the custom button what comes in that.
  • It is not very helpful in complex logics, for that you should try APEX.
  • It does not make any field read-only, so user can manually change the pre-populated value whenever he/she wants.
  • It uses hard coded ID’s of fields so if the running environment of Salesforce changes then this will not work accurately.

Comments