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
Mike FitchMike Fitch 

Related list for a custom object not auto populating lookup fields

I created a custom object in my org and created custom lookup fields for account and contact so they would show up in the respective related list. When i create a new record for my custom object via the related list in either account or contact it does not pre populate the lookup field. The users have to click the lookup magnifying glass and select the account or contact themselves. How do I fix this?
@LaceySnr - Matt Lacey@LaceySnr - Matt Lacey
Do you mean it doesn't populate both? It should always populate the field for the record you're coming from, i.e. the account lookup if you came from the related list on an account page and vice versa.

The system will never populate both as it doesn't know what value should be used for the second field. If you come from an account page would it know which is the desired contact to use? You could facilitate the population of the alternative field on save, either through workflow or a trigger.
Kevin Dal PortoKevin Dal Porto
I thought Flows do not allow updates to a Lookup field.  I'm trying to do something similar to the above.  While viewing standard Contact object, I press new to create a new record in a custom related list object.  The New Custom object record populates the Contact lookup field, but does not populate the Account Lookup field.  What is the best way to accomplish this knowing that you plan to create a managed package which would proclude any use of URL hacking or other non-Salesforce accepted practices?
@LaceySnr - Matt Lacey@LaceySnr - Matt Lacey
Hey Kevin,

Assuming the account field is going to lookup to the contact's account, is it really needed? You'd have access to the account id via the contact, MyObj__c.Contact__r.AccountId. If it is required, is the user going to need to edit it from the new record screen or could you just hide it and fill it in on save via trigger?
Kevin Dal PortoKevin Dal Porto
Hi Matt, Below is a video which illustrates what I'm trying to accomplish. The video is titled URL Hack but in fact I can’t use a hack method because I plan to package the app. Also, it is not critical to show the Account field on the new record page. It would be fine If it inserted or populated the Account name in the background. I need to populate both the contact field (which happens natively) and the Account field because I need both object to show same related records in related lists.
mayuri patil 6mayuri patil 6
I am also facing the same issue. Can anyone update on this?
Steven HulsSteven Huls
I had the same issue and solved it by using Flow to pass the IDs to both records.

Object 1 Record 1 -> populate Lookup to Object 2 Record 2 ID
Object 2 Record 2 -> populate Lookup to Object 1 Record 1 ID

So if they both have lookups pointing to each other, they'll populate their respective related lists.

If that makes sense.