If I have Object A with related list of Objects B, when I make a new object B in this list, can I populate some fields automatically with data from related object A?

  • is my answer solved your purpose? I didn't hear back – Santanu Boral Jun 22 '17 at 14:15

You need to do URLhacking.

So, find the respective parent field in the Child object's page layout and through javascript button, pass the value as URL parameter.

Here is an sample example of auto populating Account's field into Child Object's page layout when it is opened for related list (Custom button click).

You need to identify specific key like CF00N1600000EhWcc= doing View Page source.

This value is org specific, so before deploying this code of production, you have identify proper entry in production.

var url2 = "/a1Q/e?"; 

document.location.href = '{!$Site.CurrentSiteUrl}'; 

var callingURL = document.location.href; 
var position = callingURL.lastIndexOf("/"); 
var recordId = callingURL.substring(position + 1,position + 1+ 15); 

if(recordId.length==15 && recordId.startsWith('001')) 
    var accountRec = sforce.connection.query("select Name from Account where Id='" + recordId + "'"); 
    var records1 = accountRec.getArray('records'); 
    if(records1 !=null) 
        var strURL = url2 + "&" + "CF00N1600000EhWcc=" + encodeURIComponent("{!$User.FirstName}" + " " + "{!$User.LastName}") 
        + "&" + "CF00N1600000EhWcD=" + encodeURIComponent(accountRec.records.Name) + "&" + "CF00N1600000EhWcD_lkid=" + recordId 
        + "&" + 'retURL=' + recordId; 

window.open(strURL, "_self");
  • Or you could just use a URL button and no need for all the JS – Eric Jun 9 '17 at 21:41
  • I check that then – Santanu Boral Jun 9 '17 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.