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
Forrest MulduneForrest Muldune 

Apex Trigger - Update Date field with value in other Date field on same custom object

All ,

This is my first attempt in creating a trigger.

I have 2 date fields (below) in a custom object name Judgment_Event__c

Expiration_Date__c
Recording_Date__c

When I attempted to write my trigger below, I received the error.

User-added image
I want a trigger to initiate when a user enters or edits the Recording_Date__c the same date value will automatically populate into the Expiration_Date__c . This could be easily done with a formula field, however I am trying to learn how to code using triggers.

Regards,
Best Answer chosen by Forrest Muldune
sharathchandra thukkanisharathchandra thukkani

obj.Expiration_Date__c = obj.Recording_Date__c; 

reverse it.

All Answers

sharathchandra thukkanisharathchandra thukkani
you need to take the reference of the Judgment_Event__c object when you are assignin the value.

i.e obj.Recording_Date__c = obj.Expiration_Date__c
 
Forrest MulduneForrest Muldune

sharathchandra,

For some reason whey I enter a date in  Recording_Date__c the date value does not populate into the 
Expiration_Date__c field. 

My update trigger is below

User-added image
 
sharathchandra thukkanisharathchandra thukkani

obj.Expiration_Date__c = obj.Recording_Date__c; 

reverse it.
This was selected as the best answer
Forrest MulduneForrest Muldune

sharathchandra,

Thank you sir, I appreciate your time. if you know of any websites that could help me with the similar issues I had, I would appreciate it if you could send it to me.