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
Laytro80Laytro80 

Auto populate a lookup

Hi,

 

I have a record which has both an account and a contact lookup.

 

If the contact lookup is populated I would like to automatically pull through the account name the contact is linked to.

 

Is this possible, maybe using an APEX trigger to fire when the record is saved?

 

Any tips would be appreciated very new to APEX development.

 

Thanks

 

Ross

DonSpilkyDonSpilky

If you just want to display the account name, you can use a formula field for that.  Otherwise, for sure you can use an apex class/method to set accountid on your custom object.

Laytro80Laytro80

Thanks for the post.   Use the formula method first off but the users need to be able to have records just assigned to the contact level.  They just don't seem to happy about having to looking a contact and then the contacts account.  Even though they want the record displayed against both.

 

I very new to APEX code, any one have some pointers on this type of trigger.

 

Ideally I would like the account field to populate if and as soon as someone enters a contact.

 

But I think I will need to create and APEX trigger that fires after the records has been saved.

 

Thanks

 

Ross

DonSpilkyDonSpilky

Have you tried doing a field update from the workflow?

Laytro80Laytro80

The fields are not available in the field update workflow.

 

I suspect I cannot change a account or contact lookup that way.

 

Looks like an Apex trigger is the only solution so I will have to do some reading!

 

Thanks for trying to help.