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

Autofill custom field on Contact with most recent value from Custom Object

I have a custom object related to the Contact that I need to take the value from the most recent record in the custom object and display it on the contact.


The field on the custom object is a picklist. 


So when a new record is adding to the custom object, I want the picklist value to be put on the contact in a custom field.


Can I do this?

Glenn at MvistaGlenn at Mvista

You can using an Apex insert trigger.  Whenever an insert occurs on the custom object, select the Contact.<custom field> based on the <Custom Object>.Contact__c lookup. Then update the Contact custom field with the custom object picklist.  Here is an untested shot at it as an example:


trigger updateContactCustomField on <Custom Object> (after insert) {

for (<Custom Object> co: {

Contact c = [select Id, <custom field> from Contact where Id = :co.Contact__c];

  c.<custom field> = co.<custom picklist>;
update c;