You need to sign in to do that
Don't have an account?
Hermann Ouré
Trigger To uncheck a checkbox
Hello,
I am trying to create a trigger to uncheck a checkbox field on Account called "Active Order".
Basically when an Order has benn deleted from an account and there is no Order remaining for the Account, the trigger should uncheck Active Order.
No Order:
Uncheck Active Order on Account
Can't get my trigger working properly
Thank you
I am trying to create a trigger to uncheck a checkbox field on Account called "Active Order".
Basically when an Order has benn deleted from an account and there is no Order remaining for the Account, the trigger should uncheck Active Order.
No Order:
Uncheck Active Order on Account
Can't get my trigger working properly
trigger AccountActiveOrderTrigger on Account (after delete) { List<Order> lstOrder = new List<Order>(); //Get Accounts with orders Map<Id, Account> accWithOrders = new Map<Id, Account>([SELECT Id, Name, Active_Order__c, (SELECT Id FROM Orders) FROM Account WHERE Id IN: Trigger.old]); //Iterate through each Accounts for(account a : Trigger.old) { System.debug('Accounts with orders' +accWithOrders.get(a.Id).Orders.size()); //Check if an Account has an order if(accWithOrders.get(a.Id).Orders.size() == 0) { a.Active_Order__c = False; } update a; } }
Thank you
Actually decided to call an apex class from a trigger which gives that:
Apex class
Apex trigger:
That is working accordingly and unchecking the box when all orders have been delated from an Account
All Answers
You need to write a trigger on Order instead of Account. because you are deleting order not Account.
If this solution is usefull for you, Please mark as a Best Answer to help others.
Regards
Mukesh
Actually decided to call an apex class from a trigger which gives that:
Apex class
Apex trigger:
That is working accordingly and unchecking the box when all orders have been delated from an Account