You need to sign in to do that
Don't have an account?
Dave The Rave
Apex Trigger compare two date fields and change field value
After a record is created, I would like to update several number fields based the the date value on fields from 2 different objects. I tried this in the process builder but it did not work.
Attached is an image with object & field names, the list is also at the end of this message. In the Schema Builder the Master-Detail relationship is Meeting__c to RegistrationLayer__c and a Lookup Relationship Meeting__c to RegistrationLayer__c.
After a record on the Meeting__c object is created a process needs to be initiated to update the value of PointsYR1__c, PointsYR2 etc.. (on the RegistrationLayer__c object) with Points__c (on the Meeting__c object). The YEAR on the two date fields of the two objects much match in order for PointsYR1__c etc.. to be updated.
The logic should be:
IF YEAR(datemeeting__c) = YEAR(certregfrom__c) AND freepoints__c =TRUE THEN PointsYR1__c = (PointsYR1__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +1 ) AND freepoints__c =TRUE THEN PointsYR2__c = (PointsYR2__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +2 ) AND freepoints__c =TRUETHEN PointsYR3__c = (PointsYR3__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +3) AND freepoints__c =TRUETHEN PointsYR4__c = (PointsYR4__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +4) AND freepoints__c =TRUE THEN PointsYR5__c = (PointsYR5__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +5) AND freepoints__c =TRUE THEN PointsYR6__c = (PointsYR6__c + Points__c)
Fieldname Field Type
Meeting__c (Object)
Points__c
datemeeting__c
freepoints__c
Registration__c (object)
CertRegFrom__c
PointsYR1__c
PointsYR2__c
PointsYR3__c
PointsYR4__c
PointsYR5__c
PointsYR6__c
Attached is an image with object & field names, the list is also at the end of this message. In the Schema Builder the Master-Detail relationship is Meeting__c to RegistrationLayer__c and a Lookup Relationship Meeting__c to RegistrationLayer__c.
After a record on the Meeting__c object is created a process needs to be initiated to update the value of PointsYR1__c, PointsYR2 etc.. (on the RegistrationLayer__c object) with Points__c (on the Meeting__c object). The YEAR on the two date fields of the two objects much match in order for PointsYR1__c etc.. to be updated.
The logic should be:
IF YEAR(datemeeting__c) = YEAR(certregfrom__c) AND freepoints__c =TRUE THEN PointsYR1__c = (PointsYR1__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +1 ) AND freepoints__c =TRUE THEN PointsYR2__c = (PointsYR2__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +2 ) AND freepoints__c =TRUETHEN PointsYR3__c = (PointsYR3__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +3) AND freepoints__c =TRUETHEN PointsYR4__c = (PointsYR4__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +4) AND freepoints__c =TRUE THEN PointsYR5__c = (PointsYR5__c + Points__c)
IF YEAR(datemeeting__c) = YEAR(certregfrom__c +5) AND freepoints__c =TRUE THEN PointsYR6__c = (PointsYR6__c + Points__c)
Fieldname Field Type
Meeting__c (Object)
Points__c
datemeeting__c
freepoints__c
Registration__c (object)
CertRegFrom__c
PointsYR1__c
PointsYR2__c
PointsYR3__c
PointsYR4__c
PointsYR5__c
PointsYR6__c
Try this:
All Answers
Try this:
Finally, I get around to implementing your code in our Sandbox Org.
Unfortunately, I am getting 85 errors before I run this code.
This is what did exactly, I cut and paste you code into Excel and then changed the field and object names. I made no other changes.
Then I copied the code and pasted it back into the developer console.
I receive the error below for every line of the code.
"Invalid identifier ''. Apex identifiers must start with an ASCII letter (a-z or A-Z) followed by any number of ASCII letters (a-z or A-Z), digits (0 - 9), '$', '_'."
Do you have any idea what the error is?
However, I have 38 errors still in the above code. I am going top create a new question for this.