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
Sourav PSourav P 

Trigger showing invalid field name

Hi,
The below trigger showing the field name " ModifiedAddress__c" doesnt exist. whereas the field API name is correct. Any idea plz why its giving such error.? Thanks
User-added image

Here, the full code below,
trigger trgContactChanges on Account (before update) {
   
    //This trigger perform when there is a change in Contact
   
    //To compare old and new value of Account
    if(Trigger.IsBefore && Trigger.IsUpdate) {
       
        for(Account NewAccount : Trigger.New) {
           
            for(Account OldAccount : Trigger.Old) {
               
                NewAccount.ModifiedAddress__c = false;
               
                //Compare Old Contact Phone Number with New Contact Phone Number
                if(NewAccount.Contact_Phone_Number_Mobile__c != oldAccount.Contact_Phone_Number_Mobile__c) {
                    NewAccount.ModifiedPhone1__c = true;
                } else {
                    NewAccount.ModifiedPhone1__c = false;
                }
               
                if(NewAccount.Contact_Phone_Number_Mobile2__c != oldAccount.Contact_Phone_Number_Mobile2__c) {
                    NewAccount.ModifiedPhone2__c = true;
                } else {
                    NewAccount.ModifiedPhone2__c = false;
                }
               
                if(NewAccount.Contact_Phone_Number_Mobile3__c != oldAccount.Contact_Phone_Number_Mobile3__c) {
                    NewAccount.ModifiedPhone3__c = true;
                } else {
                    NewAccount.ModifiedPhone3__c = false;
                }
               
                //Compare Old Contact Email Address with New Contact Email Address
                if(NewAccount.Contact_Email_Address__c != oldAccount.Contact_Email_Address__c) {
                    NewAccount.ModifiedEmail1__c = true;
                } else {
                    NewAccount.ModifiedEmail1__c = false;
                }
               
                if(NewAccount.Contact_Email2_Address__c != oldAccount.Contact_Email2_Address__c) {
                    NewAccount.ModifiedEmail2__c = true;
                } else {
                    NewAccount.ModifiedEmail2__c = false;
                } 
               
                if(NewAccount.Contact_Email3_Address__c != oldAccount.Contact_Email3_Address__c) {
                    NewAccount.ModifiedEmail3__c = true;
                } else {
                    NewAccount.ModifiedEmail3__c = false;
                }
               
                //Compare Old Contact LastName with New Contact LastName
                if(NewAccount.LastName != oldAccount.LastName) {
                    NewAccount.ModifiedLastName__c = true;
                } else {
                    NewAccount.ModifiedLastName__c = false;
                }
               
            }
        }
       
    }
   
}
 
sancasanca
Is this field part of Account object ? can you post the screenshot of this Api name
Sourav PSourav P
Hi Sanju,
Sobject Type : Account
Its written for personal account actually, but as personal account too taking the same "Account" name API. Thnx
Sourav PSourav P
User-added image
sancasanca
Hi Sourav ,

It looks perfect , but still dont know why issue persists.
Can you please do couple of things
1) check field permission for profile (not requied but still check)
2) Instead of Trigger.New , replace Trigger.new . ( I know apex is not case sensitive , but still try) 
Mahesh K 22Mahesh K 22
HI Sorav
I have obeserved 2 thingg above code 
1. While creating checkbox(ModifiedAddress__c) is false(unchecked) 
no need to mention these field in code .i.e it has unchecked
2.if u want this filed as usaully compare new value to old value
like
   if(NewAccount.ModifiedAddress__c != oldAccount.ModifiedAddress__c) {
                    NewAccount.ModifiedAddress__c = true;
                } else {
                    NewAccount.ModifiedAddress__c= false;
                }