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

Trigger was fired after update, when the trigger has to be fired before update
Hi,
The below trigger was fired after updating the field twice, but it was not fired before update.
The below trigger was fired after updating the field twice, but it was not fired before update.
trigger age on Account (before update) { Map<Id,Account> ageMap = new Map<Id,Account>(); Account[] acct = [SELECT Id,Age__c FROM Account WHERE Id IN : Trigger.newMap.keySet()]; for(Account a : trigger.new){ if(a.age__c != null){ ageMap.get(a.Id); a.Is_Age_Updated__c = true; } else{ ageMap.get(a.Id); a.Is_Age_Updated__c = false; } } }
If you need to update the same Account in Trigger.New, then no need to fire an query.
Keep the code as simple as possible.
Thanks,
Gaurav
Skype: gaurav62990
All Answers
Check once below sample code :
Hope this helps you!
Thanks
Varaprasad
For Support: varaprasad4sfdc@gmail.com
Both the codes were fired after update not before update.
According to my code, if you change the Age__c field on any account record then Is_Age_Updated__c field will marked as true. If you blank update or update any other field then Is_Age_Updated__c will marked as false.
Can you please tell me what is your exact requirement.
If you need to update the same Account in Trigger.New, then no need to fire an query.
Keep the code as simple as possible.
Thanks,
Gaurav
Skype: gaurav62990
@gaurav....thanks for the help. I have written this code before. But tried another way using new map. Thanks for the suggestion, i'll try to code as simple as possible