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 BoralJun 22, 2017 at 14:15
1 Answer
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.
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/19.0/apex.js")}
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");