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
StefanStefan 

Button to open new custom object from Account

I have created a new button on the related list on account to a custom object. When I save the new object I want the object to close and return to the account.
 
The following code opens the new object but throws an error: /a0E/e?retURL=%2F{!Account.Id}&saveURL=%2F{!Account.Id}&CF00N40000001fj0E={!Account.Id}
 
Account: 0014000000FurVB
Error: no matches found
 
0014000000FurVB is a valid Account ID
werewolfwerewolf
For lookups you have to set 2 values, the name and the ID.  You do that by setting the custom field to the name, and the custom field appended with "_lkid" to the ID.

CF00N40000001fj0E should be {!Account.Name}.  CF00N40000001fj0E_lkid should be {!Account.Id}. 
StefanStefan

Hi Werewolf, that's brilliant, thanks.

For anyone who is having the same problem, I couldn't get the code quite right until I put the original button and the custom back on the related list on the Account page.

Clicking on new from the related list gave me:

https://na2.salesforce.com/a0E/e?CF00N40000001fj0E=XYZCompany&CF00N40000001fj0E_lkid=0014000000FSSPf&retURL=%2F0014000000FSSPf%3Fnewid%3Da0E40000000pCb2

I edited thisone step at a time in the custom button to get to:
 
/a0E/e?CF00N40000001fj0E={!Account.Name}&CF00N40000001fj0E_lkid={!Account.Id}&retURL=%2F0014000000FurVB&saveURL=%2F{!Account.Id}
 
It's easy when you know how.
 
Thanks once again Werewolf for pointing me in the right direction.