1
public class UpdateGraduated {
    public static void WhenGraduatedUpdate(List<hed__Program_Enrollment__c> enrollmentListUpdate){
        try{
            List<hed__Program_Enrollment__c> enrollmentList = new List<hed__Program_Enrollment__c>();
            List<contact> contactList = new List<contact>();
            List<contact> contactListUpdated = new List<contact>();
            set<id> IdList = new set<Id>();
            enrollmentList = [select id, hed__Contact__c , hed__Enrollment_Status__c, hed__End_Date__c
                             from hed__Program_Enrollment__c
                             where id in:enrollmentListUpdate
                             and hed__Enrollment_Status__c = 'Graduated'];

            for(hed__Program_Enrollment__c en: enrollmentList) {
                IdList.add(en.hed__Contact__c);
            }

            contactList = [select id, Graduation_Date__c from contact where id in : IdList];

            for(hed__Program_Enrollment__c enn: enrollmentList) {
                for(contact en :contactList){
                    if(enn.hed__Contact__c == en.id && enn.hed__Enrollment_Status__c == 'Graduated'){
                        en.hed__End_Date__c = enn.Graduation_Date__c;
                        contactListUpdated.add(en);
                    }
                }
            }
            update contactListUpdated;
        } catch(Exception e) {
            system.debug('Error is -> '+ e.getMessage() + 'at Line -> '+ e.getLineNumber());
        }
    }
}

I am getting an error on Line 22 of my Apex class that a variable hed_End_Date__c does not exist but the field does exist in my production and sandbox. So I am not 100% sure where I am going wrong. Any ideas?

1

Realised my problem! The assignment needs to be the other way around.

Instead of :

en.hed__End_Date__c = enn.Graduation_Date__c;

It should be:

en.Graduation_Date__c = enn.hed__End_Date__c;

Thanks!

3
  • don't forget to accept your answer. This way the question will be marked as solved and it will not be randomly bumped to homepage in a few months/years – Novarg Nov 21 '19 at 8:52
  • @Novarg Thanks, how do I 'accept' my answer? – Chloe Brown Nov 21 '19 at 13:22
  • 1
    you have a tick/check mark on the left side(under the score). Click it and it will turn green, meaning that this is an accepted answer – Novarg Nov 21 '19 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.