You need to sign in to do that
Don't have an account?
Su King
Trigger, update decimal field in Account when number field in Case is changed
Hi everyone, I am tring to write a trigger to update decimal field in Account when number field in Case is changed, any idea ?
I think this code will give you the batter idea for your requirement.
Here I am updating the Account field(Auto_Number_Of_Case__c) from the case field(Auto_Number__c).
We can update this field when we create a new Case or updating existing Case.
trigger UpdateNoField on Case (after insert, after update) {
List<Account> acList = new List<Account>();
Set<Id> idSet = new Set<Id>();
if(Trigger.isAfter){
for(Case c: Trigger.New){
if(c.AccountId != null){
idSet.add(c.AccountId);
}
}
acList = [SELECT Id, Auto_Number_Of_Case__c FROM Account WHERE Id IN: idSet LIMIT 1];
for(Case c: Trigger.New){
if(c.AccountId != null && acList.size() >0){
acList[0].Auto_Number_Of_Case__c = c.Auto_Number__c;
}
}
}
update acList;
}
Please mark this as Best Answer if this helps you.
Thanks & Regards.
Akash Pandey