function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
uday kumar yuday kumar y 

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?
manasa udupimanasa udupi
Hi Uday,

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!!
Maharajan CMaharajan C
Hi Uday,

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