1

I am trying to automatically update an account level field once an associated contact's field is updated. The use case is someone completes a Pardot web form to register their products. This data goes onto the lead or contact level field as Pardot can not update account fields. I have it configured that if a lead is created net new with this form field, once converted to a contact the data carries over to the contact level and it also writes it to the associated Account. I can not get the data to push from contact to account when the form submission updates an existing contact.

I have looked at the Apex code for how to update an account from a case (a different question in the forum and I've also looked into workflow rules which wouldn't jump from contact to account. I also just tried to learn Apex through the wizard and then a developer account access...it's frankly too much to take on and learn right now as a marketing/admin team of 1.

I'm pretty novice at coding so if I can have a more clear direction on what I all need to do to get an account field be updated when information is updated on a contact record.

Custom field on contact: Warranty_Registration_Products__c (A pick list multi select)

Custom field on account: Warranty_Registration_Products__c (A pick list multi select)

thanks much in advance!!

Stephanie

0

There should be a field on Contact called accountId. Contact is considered a Child of Account. However, your Org may not be associating new contacts with Accounts, especially if new contacts are being created from web forms. Unless the Account Name is on that form or the form contains a link to the accountId that populates that field, you'd need some way of querying for the Account to associate the contact with.

Without knowing more about your organization's Schema, particularly the fields you mention on the multi-select picklists and what they mean (e.g. do they associate the contact directly with an account of some kind?), it's nearly impossible for any of us to guide you.

0

After reading your requirement, I am not very much clear about your requirement. But I can suggest you trigger, It will work for your requirement. I had once similar requirements like your's and same code I am posting here worked for me. It's simple parent(Account) and child(contact) trigger. You can use according to your requirement like which trigger context you want.

Trigger Helper class:

public class UpdatetAcocuntField {

public static void updatePicklistOnAccount(List<Contact> listContacts){
    List <Account> upAccList = new List <Account> (); 

    //initializes sets
    set<Id> setOfAccountIds = new set<Id>();
    map<Id, Contact> mapAccountIdContact = new map<Id, Contact>();

    for(Contact objcon :listContacts){
        if(objcon.AccountId!= null){
            setOfAccountIds.add(objcon.AccountId);
        }
    }

    List<Contact> listOfContact = [SELECT Id, LastName,AccountId, Active__c  FROM Contact WHERE AccountId =: setOfAccountIds ];

    for(contact con: listContacts){
        UpAccList.add(new Account(Id= con.AccountId ,Active__c = con.Active__c ));
    }

    if (upAccList.size () > 0) 
        update upAccList; 
}

}

Trigger on contact:

trigger ContactTrigger on Contact (after insert, after update) {   

if(Trigger.isAfter && Trigger.isInsert) {

    UpdateContactAcocuntOnlyDefaultField.updatePicklistOnAccount(Trigger.new);
} 
if(Trigger.isAfter && Trigger.isUpdate){
    UpdateContactAcocuntOnlyDefaultField.updatePicklistOnAccount(Trigger.new);
}

}

I am assuming this will help in solving your problem. Please try this one and let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.