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

Update a field with today's date based on a certain value being selected in another field by using trigger
I have object Account two custom fields one is Amount it requared field anather one is Date field. if we can update the Amount and check the Date field is todate or it can through error messege how is it passible?
Is your requirement to update the date field to today's date when amount is entered or updated?
If yes then you can accomplish this by making the date field a formula field. Select advance formula and say
IF( Amount__c <> 0, TODAY() ,NULL)
This should do the job:) Let me know if this is what you're looking for!!
Try the below trigger:
The below trigger checks the two field and throws an error:
trigger TestTrigger on Account (before update)
{
for(Account a : Trigger.new)
{
if(a.Amount__c != Trigger.oldMap.get(a.id).Amount__c && a.Date__c != TODAY())
a.Date__c.addError('Date is need to be in UptoDate');
}
}
Can you please Let me know if it works or not!!!
If it works don't forget to mark this as a best answer!!!
Thanks,
Raj