You need to sign in to do that
Don't have an account?
Asel Vazir 1
Create record on related object and update fields on it if Opportunity custom checkbox field is true
Need help to resolve the issue. The trigger doesn't create a new record with updated fields when checkbox on Opp object is true. Also, the new record on custom object should show the Amount resulted due to subtraction on Opp fields.
public static void createGLTransaction(List<Opportunity> oppList2) { List<Id> GLIds = new List<Id>(); for (Opportunity opp : oppList2) { if (opp.Fee_Applied__c == true) { GLIds.add(opp.Id); } Map<Id, GL_Transaction__c> mapGl = new Map<Id, GL_Transaction__c> ([SELECT Id, Transaction__c, Amount__c FROM GL_Transaction__c WHERE Id IN : GLIds]); List<GL_Transaction__c> glTransactions = new List<GL_Transaction__c>(); for (Opportunity oppt : oppList2){ if(oppt.Fee_Applied__c == true && mapGl.containsKey(oppt.Id)){ GL_Transaction__c gl = mapGl.get(oppt.Id); gl.Amount__c = oppt.Amount_Received__c -= oppt.Exchange_Fee__c; gl.Transaction__c = 'Phase One Exchange Fee'; glTransactions.add(gl); } insert glTransactions; update glTransactions; } } } trigger ExchangeTriggers on Opportunity (before insert, before update, after update) { if (Trigger.isInsert || Trigger.isUpdate){ PrimaryEmailOnExchange.createGLTransaction(Trigger.new); }
You can certainly use the approach of code but have you considered the OOB solutions for your implementation??
Regards,
Anutej