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
Manuel DangondManuel Dangond 

Trigger to check if encripted field changed

Hello,

I've never written a trigger before and was wondering if someone can help. All I need is a trigger on the Account object, on update, that will check to see if Tax ID changed. If this is true, then update the Comments field with something like "Tax ID was last updated on" & Today(). The pseudocode would be something like this:

Trigger TaxIdChanged on Account (On Update)
If ISCHANGED(Tax_id__c) = True
    Comments = "Tax ID was last updated on" & Today()
End

It is important to know that Tax_Id__c is an encrypted field and this is why I'm having to try to create a trigger to do this since I believe is the only way to look at the contents of an ecrypted field. I've tried doing this via a workflow rule or process builder, and unfortunately was not able to do it becuase I'm dealing with an encrupted field.

Thank you so much!!
RKSalesforceRKSalesforce
Hi Manuel,

You can achieve this by using multiple ways:
1) Workflow / Process Builder
2) Apex trigger
3) By using Standard Enable Account History feature

Lets do it using Workflow Field Update:
Create Workflow on Your Account Object similar to Below Image. I am using Sum_Of_Salary__c(You can use your Field ) field which available in my system :
User-added image
Also add Workflow Field Update as below: 

User-added image
Please let me know if helped. Mark as best answer for others help.

Regards,
Ramakant
Surya Prakash TomarSurya Prakash Tomar
Hi Manuel,
 
Ischanged() is not work on the apex classes or triggers. Better you can used trigger.oldmap and trigger.new to check.
Yuvaraj mayilsamy 9Yuvaraj mayilsamy 9
trigger taxidchanged on account(before update) {
for(account a : trigger.new){
if(trigger.oldmap.get(a.id).tax_id__c != a.tax_id__C){
a.comments__c = 'Tax ID was last updated on' +system.today();
}
}
}

Mark as best answer if it helps you.
Manuel DangondManuel Dangond
Thank you so much Yuvaraj! This works perfectly!!
Manuel DangondManuel Dangond
Thank you so much Yuvaraj! This works perfectly!! Manuel Dangond Business Systems Analyst III Opus Bank 19900 MacArthur Blvd., Irvine, CA 92612 P. 949.251.8173 opusbank.com | Twitter | LinkedIn