+ Start a Discussion
m 3m 3 

Error: Compile Error: Variable does not exist: Id at line 16 column 38

Hi Please help me above error is throwing when  i am trying to save class 

public class AddPrimaryContact implements Queueable {
    
    private Contact mainContact;
    private list<Schema.Account> accounts;
    
    public AddPrimaryContact (Contact c, String abbr) {
        this.mainContact = c;
        this.accounts = [Select Id, Name From Account Where BillingState = :abbr limit 200];
    }
    
    public void execute (QueueableContext context) {

        list<Contact> newContacts = new list<Contact>();                
        for (Account a :this.accounts) {
            Contact newContact = this.mainContact.Clone();
            newContact.AccountId = a.Id;
            newContacts.Add(newContact);
        }
        insert newContacts;
    }
}
Raj VakatiRaj Vakati
Use this code
 
public class AddPrimaryContact implements Queueable {
    
    private Contact mainContact;
    private list<Account> accounts;
    
    public AddPrimaryContact (Contact c, String abbr) {
        this.mainContact = c;
        this.accounts = [Select Id, Name From Account Where BillingState = :abbr limit 200];
    }
    
    public void execute (QueueableContext context) {
        
        list<Contact> newContacts = new list<Contact>();                
        for (Account a :this.accounts) {
            Contact newContact = this.mainContact.Clone();
            newContact.AccountId = a.Id;
            newContacts.Add(newContact);
        }
        insert newContacts;
    }
}

 
Sanjay Bhati 95Sanjay Bhati 95
Hi M3,

There is no issue in your code please try again with same code.It will work.

Thanks 
Sanjay Bhati