You need to sign in to do that
Don't have an account?
Rob Koch 1
Apex Trigger to Update Account on Asset Delete
Hello, I am looking to create a trigger that will update an account field to "Null" or "0" when a child asset is deleted. The two account fields are Max Advisor Count, and Max Mortgage Advisor Count. When adding an asset, depending on the type, it will add a quantity of "1" to either the Max Advisor Count or the Max Mortgage Advisor Count.
I set up Process Builder to update those counts when an asset record is created or changed. But it looks like I will need a trigger to set either of those counts to 0 when an asset record is deleted.
All I need is for the trigger to fire after an asset is deleted. Any suggestions are welcome, thank you!!!
I set up Process Builder to update those counts when an asset record is created or changed. But it looks like I will need a trigger to set either of those counts to 0 when an asset record is deleted.
All I need is for the trigger to fire after an asset is deleted. Any suggestions are welcome, thank you!!!
Your trigger will look something like below:
However the code needs to be modify based on your requirement. Please let me know if you need any further help on this.
Thanks,
Abhishek Bansal
All Answers
Your trigger will look something like below:
However the code needs to be modify based on your requirement. Please let me know if you need any further help on this.
Thanks,
Abhishek Bansal
So when there is only one related Asset that contains the name "Figlo Advisor", quantity of 1 and it is deleted, set Max Advisor Count to 0. Otherwise, reduce the Max Advisor Count by 1.
When there is only one related Asset that contains the name "Figlo Hypotheken," quantity of 1 and it is deleted, set Max Mortgage Advisor Count to 0. Otherwise reduce the Max Mortgage Advisor Count by 1.
So this is an excellent start. All I need now is help with the logic to update the counts according to the above conditions.
The fields involved are:
Asset Fields:
Asset Name
Asset Quantity
Account Fields:
Max_Advisor_Count__c
Max_Mortgage_Advisor_Count__c
Thank you again! I was happy to see that the underlying trigger is working.
Please find below your required trigger code:
Let me know if you face any issues with this.
Thanks,
Abhishek Bansal.