You need to sign in to do that
Don't have an account?

trigger to insert data into custom object from another object thru apex class
Hi,
I am trying to insert data into obj2 based on some condition in obj1 through handler /apex class but it is not working.
Please find the code
I am trying to insert data into obj2 based on some condition in obj1 through handler /apex class but it is not working.
Please find the code
trigger orderAccountTransactionUpdate on Account (before update) { Order__c orderAccount = new Order__c(); system.debug('inside trigger'); orderAccount.lstNewAccounts = Trigger.new; orderAccount.lstOldAccounts = Trigger.old; // Trigger Logic – Before Update if((Trigger.isAfter && Trigger.isUpdate) ) { orderAccount.check(Trigger.new, Trigger.oldMap); } } public class OrderAccountTransaction { public List<Account> lstNewAccounts = new List<Account>(); public List<Account> lstOldAccounts = new List<Account>(); public void check(List<Account> Accounts, Map<Id, Account> oldAccount) { Map<Id, Account> mapVerifyOldAccounts = new Map<Id, Account>(); List<Order__c> createOrder = new List <Order__c> (); for(Account acc : Accounts){ system.debug('Accounts' + Accounts); system.debug('oldAccount' + oldAccount); Account beforeUpdate = oldAccount.get(acc.Id); if(acc.Email!=beforeUpdate.Email) { NOT GOING INSIDE THIS system.debug('inside if'); createOrder.add(new Order__c (Action__c = 'insert',Status__c = 'success')); } } try { insert createOrder; } catch (Exception Ex){ system.debug(Ex); } } }
Try with belwo code let me know if it helps !!
Thanks
Manoj
All Answers
Try below code.
Thanks,
Gaurav
Try with belwo code let me know if it helps !!
Thanks
Manoj