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
Mario PaesMario Paes 

Trying to resolve error - Variable does not exist: Id

I have been trying to find out what's wrong with some apex code. I started seeing compile errors, so I reduced the code to the most basic code to try to find the issue, but I'm not sure what I'm doing wrong here.

Here's the stripped down version of my code:  
 public with sharing class ContactTriggerHandler {

     public static void UpdateOptLogs(List<Contact> newContacts) {

        //Read the new values of the Contact object 
        for (Contact contactObj: newContacts)
        {
            system.debug(' contactObj.Id : ' + contactObj.Id);
        }
    }
}

I get an error : Result: [OPERATION FAILED]: ContactTriggerHandler: Variable does not exist: Id (Line: 6, Column: -1)


Thanks for your help.
 
Best Answer chosen by Mario Paes
RAM AnisettiRAM Anisetti
Can you check if there is exist any class name as "Contact" in ur organization
if it is exist please rename the class.

All Answers

RAM AnisettiRAM Anisetti
Can tell me where u are execute this code ,i mean Standard SF UI or Eclipse
Mario PaesMario Paes
Get the error in both, the developer console as well as Mavensmate.
RAM AnisettiRAM Anisetti
Can you check if there is exist any class name as "Contact" in ur organization
if it is exist please rename the class.
This was selected as the best answer
Abu HashimAbu Hashim
Are u getting the same error with this code? (I mean after removing the other code as u've mentioned above.)
JeffreyStevensJeffreyStevens
I'm not sure that the handler methods can be static. You might try your method definition as just

public void UpdateOptLogs(List<Contact> newContacts) {

...
Mario PaesMario Paes
@ram, there's no other class called 'Contact in the org. This is the standard contact object. In any case, the Id field will be present on any object.
@Abu, I am getting the error on the code that I posted in the initial post. 
@JeffreyStevens, I have other existing handler classes in the same org that are static. These compiled successfully and are deployed to the production org. I will change this class to a non-static class and try it out to eliminate this possibility.
Mario PaesMario Paes
@JeffreyStevens, changing to a non-static method didn't make a difference.

public void UpdateOptLogs(List<Contact> newContacts) {
 
William TranWilliam Tran
Can you confirm that is Id (Eye D)  and not ld ( EL D).

Otherwise, try lastname and see if it works or not (if not then it's the object, if it works then it's the field)

As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.

Thanks
 
Mario PaesMario Paes
It is Id (Eye D) . I did try using a couple of other fields and got the same error.
William TranWilliam Tran
Can you post your code that is calling the  class ContactTriggerHandler ?
Thx
Mario PaesMario Paes
I didn't get around to closing this issue. I did find a class in my org called contact. This was conflicting with the definition of the standard contact object. I deleted this class and the issue was resolved.