I am very new to Salesforce and I need to write a trigger which should fire on few formula field updates and should update the other fields in contacts and accounts. So something like this:

Trigger should fire when updates are done to these fields:

From Contact object fields - ED_180_Prior__c (formula date field), Prof_Status__c (text)

From Account object fields - M_Status__c (formula text field), Days_of_MT__c (formula number field).

Trigger should update these fields:

From Contact object - Pardot_ED_180_Prior__c (date field), Pardot_Prof_Status__c (text).

From Accounts object - Pardot_M_status__c (text field), Pardot_Days_of_MT__c (number field)

I have tried this so far:

trigger updatePardot on Contact (after insert){
    List<contact> conUpdate = new List<Contact>();
    set<Id> sAccId = new set<Id>();
    for(Contact con: trigger.new){
    List<Account> lstAccount = [select id from account where id IN: sAccId];
    for(Account acc: lstAccount){
        for(Contact con: acc.contacts){
            //con.Address_1__c = acc.Address_1__c;
            con.Pardot_ED_180_Prior__c                = con.ED_180_Prior__c;
            con.Pardot_Prof_Status__c                 = con.Prof_Status__c;

            acc.Pardot_M_status__c                    = acc.M_status__c;
            acc.Pardot_Days_of_MT__c                  = acc.Days_of_MT__c;
    if(conUpdate.size() > 0){
        update conUpdate;
    if(lstAccount.size() > 0) {
        update lstAccount;

Can someone please help me if I am not doing it correct, or if I should change the approach as soon as possible? Also, should I setup workflow rules for every different field when this trigger should fire? Much thanks in advance.

closed as unclear what you're asking by battery.cord, glls, Basti, Patlatus, Boris Bachovski Dec 13 '17 at 5:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • can you post what you have tried so far – Santanu Boral Dec 11 '17 at 20:24
  • 2
    If you want to learn how to do this yourself, you should definitely complete the appropriate Salesforce Trailheads. If you want someone else to do this work for you "as soon as possible", then you should definitely hire a developer. You can start on the Appexchange directory – David Cheng Dec 11 '17 at 20:39
  • Updated my post above. Have posted the code which I have written so far - however not sure if this is even correct. – abc Dec 11 '17 at 22:16
  • At a glance it looks fine, but we really won't know for sure- you need to run this yourself. If you encounter an error, add it to the post. – battery.cord Dec 12 '17 at 14:34