+ Start a Discussion
Akash ShrirameAkash Shrirame 

how to insert or copy custom object record data to account object automatically after custom object record gets approved

How to insert or copy custom object record data to account object automatically after custom object record gets approved

I have custom object student account and i want the functionality to copy some student object field record data to account object after student record get approved. there are about 10 fields record to copy in 1 time.
 
Best Answer chosen by Akash Shrirame
mukesh guptamukesh gupta
Hi Akash,

If you create a custom field on your object, say, isApproved__c (checkbox, default to false), your approval process could update that field when the final approval comes.

From there, you can wrap your desired trigger code in an if(record.isApproved__c && !trigger.oldMap.get(record.Id).isApproved__c) block to prevent that specific code from being run until isApproved__c is flipped from false to true (and you want to do the comparison against the old value as well, lest your code execute on every single trigger firing after it is approved).

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

All Answers

mukesh guptamukesh gupta
Hi Akash,

If you create a custom field on your object, say, isApproved__c (checkbox, default to false), your approval process could update that field when the final approval comes.

From there, you can wrap your desired trigger code in an if(record.isApproved__c && !trigger.oldMap.get(record.Id).isApproved__c) block to prevent that specific code from being run until isApproved__c is flipped from false to true (and you want to do the comparison against the old value as well, lest your code execute on every single trigger firing after it is approved).

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
This was selected as the best answer
Akash ShrirameAkash Shrirame
Thanks For the Answer.

But in my scenario, my approval process should also be triggered automatically so i have used process builder to record get submitted automatically. if i do so as you suggested then the user who is going to fill the info of Custom object can check the checkbox and Save the record. then at the same time trigger (copy field record to account object) will fire. and this record is already copied to account before manager approve the record.
PriyaPriya (Salesforce Developers) 

You can hide the checkbox field so that user cannot enter the value into it and the trigger will not run before.

Regards,

Priya Ranjan