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

Mimic how account is automatically populated when contact is selected in case

    Hello all,

Please hepl! I am struggling with this one.

I have created a new object that contains 2 lookups: Contact and Account. I would like the Account field to automatically populate when the Contact is selected. Exactly the same ways as it is working when creating a new case.

Does anyone knows how to do this?


First question:

Why not just use a record type of case, rather than creating a whole new object?  I guarantee you that'll be easier.

For a custom object, you can only do this with an Apex trigger.
Thanks for your prompt answer warewolf.

However, I really need to use a custom object and when I try to use a trigger, it only populates the Account field when I save my object. I would like to have the same behaviour as in the case object. That is, without saving, as soon as the contact lookup popup closes, the account field is populated.

Is that possible?

No, you can only populate the account field on save.  If you're always going to autopopulate the account, though, why even show it on the edit page layout?  Just let it autopopulate with your trigger and show it on the detail layout only.
Thanks for your valuable input. This suggestion is a good idea.

But how do you hide a field in the edit page layout only?

Make a new section on the page layout, put that field in your new section, and set that section to show itself only in Detail mode (by clicking on the Edit link on the right hand side of the section). 

Or you can leave the account on the section it's in but in the layout editor click it and hit the Properties button and turn it to read-only.  That way people can't edit it through that layout.