You need to sign in to do that
Don't have an account?
Dave The Rave
Apex Trigger: Variable does not exist
Hi All,
The code below from (Matheus Sales Ferreira) is for 2 Objects: Registration_Layer__c and Meeting__c. It is a master-detail relationship Meeting__c to Registration_Layer__c. The code below produces several errors which appear on different lines of code, but all start with "Variable Does Not Exist" - Registration_Layer__c and then for datemeeting__c, freepoints__c and points__c.
Errors as above on lines which contain the above fields, so lines 6,7,15,16,17.18.19.20.21.22.23.24.25.26.
I think it is eactly the same issue for each line.
The code below from (Matheus Sales Ferreira) is for 2 Objects: Registration_Layer__c and Meeting__c. It is a master-detail relationship Meeting__c to Registration_Layer__c. The code below produces several errors which appear on different lines of code, but all start with "Variable Does Not Exist" - Registration_Layer__c and then for datemeeting__c, freepoints__c and points__c.
Errors as above on lines which contain the above fields, so lines 6,7,15,16,17.18.19.20.21.22.23.24.25.26.
I think it is eactly the same issue for each line.
Trigger TrgOnMeeting on Meeting__c (before insert, before Update){ if(Trigger.isInsert || Trigger.isUpdate) { Set<Id> regIds = new Set<Id>(); for(Account meeting : Trigger.new) { if(meeting.Registration_Layer__c != null) regIds.add(meeting.Registration_Layer__c); } Map<Id, Registration_Layer__c> mapReg = new Map<Id, Registration_Layer__c>([SELECT Id, CertRegFrom__c, ObligatoryPointsObtainedYr1__c, ObligatoryPointsObtainedYr2__c, ObligatoryPointsObtainedYr3__c, ObligatoryPointsObtainedYr4__c, ObligatoryPointsObtainedYr5__c, ObligatoryPointsObtainedYr6__c FROM Registration_Layer__c WHERE Id IN: regIds]); for(Account meeting : Trigger.new) { if(meeting.datemeeting__c.Year() == (mapReg.get(meeting.Registration_Layer__c).CertRegFrom__c.Year()) && meeting.freepoints__c) { mapReg.get(meeting.Registration_Layer__c).ObligatoryPointsObtainedYr1__c += meeting.Points__c; } else if(meeting.datemeeting__c.Year() == (mapReg.get(meeting.Registration_Layer__c).CertRegFrom__c.Year() + 1) && meeting.freepoints__c) { mapReg.get(meeting.Registration_Layer__c).ObligatoryPointsObtainedYr2__c += meeting.Points__c; } else if(meeting.datemeeting__c.Year() == (mapReg.get(meeting.Registration_Layer__c).CertRegFrom__c.Year() + 2) && meeting.freepoints__c) { mapReg.get(meeting.Registration_Layer__c).ObligatoryPointsObtainedYr3__c += meeting.Points__c; } else if(meeting.datemeeting__c.Year() == (mapReg.get(meeting.Registration_Layer__c).CertRegFrom__c.Year() + 3) && meeting.freepoints__c) { mapReg.get(meeting.Registration_Layer__c).ObligatoryPointsObtainedYr4__c += meeting.Points__c; } else if(meeting.datemeeting__c.Year() == (mapReg.get(meeting.Registration_Layer__c).CertRegFrom__c.Year() + 4) && meeting.freepoints__c) { mapReg.get(meeting.Registration_Layer__c).ObligatoryPointsObtainedYr5__c += meeting.Points__c; } else if(meeting.datemeeting__c.Year() == (mapReg.get(meeting.Registration_Layer__c).CertRegFrom__c.Year() + 5) && meeting.freepoints__c) { mapReg.get(meeting.Registration_Layer__c).ObligatoryPointsObtainedYr6__c += meeting.Points__c; } } update mapReg.values(); } }
I trust you are doing very well.
Instead of Account in for loop, you need to use your custom object i.e; Meeting__c
So, in both for loop, change Account to Meeting__c
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.
Thanks and Regards,
Khan Anas
Please let me know your requirement So that we can help you accordingly.
Try this :
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
You need to change for loop on Line 13 also, from Account to Meeting__c