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
Bhupathi YadavBhupathi Yadav 

Compile Error: Variable does not exist: name

My scnario was when iam inserting account record automatically associated contact also should  insert:
But iam getting error like ;Variable does not exist: name' but i have field Name on account
trigger account_trigger on Account (after insert,after update)
{
  if(Trigger.isInsert)
  {

    List<Contact> ct = new List <Contact>();

    for(Account acc : trigger.new)
    {

        Contact c = new Contact(LastName=acc.name,AccountId=acc.id,MailingStreet=acc.BillingStree,
                    Phone=acc.Phone);

        ct.add(c);
    }
    insert ct;
  }
}
Best Answer chosen by Bhupathi Yadav
Amit Chaudhary 8Amit Chaudhary 8
Hi Bhupathi Yadav 

Can you please check you have any Apex class name with Account. If yes then please rename or delete the same apex class and retry.

Let us know if that will help you

All Answers

VineetKumarVineetKumar
I don't think this is for name, but for BillingStree. infact this should be MailingStreet=acc.BillingStreet.
Let me know if this helps.
Bhupathi YadavBhupathi Yadav
Still Its not working
It shows same thing
Pankaj_GanwaniPankaj_Ganwani
trigger account_trigger on Account (after insert,after update)
{
  if(Trigger.isInsert)
  {

    List<Contact> ct = new List <Contact>();

    for(Account acc : trigger.new)
    {
        ct.add(new Contact(LastName=acc.name,AccountId=acc.id,MailingStreet=acc.BillingStreet,Phone=acc.Phone));
    }
    insert ct;
  }
}

I have updated your code a little bit. Please refer the above.
VineetKumarVineetKumar
I was able to save the same code without any issues, are you getting this error while saving the code or running the code?
Bhupathi YadavBhupathi Yadav
Thanks
Pankaj, But it shows same thing
 
Pankaj_GanwaniPankaj_Ganwani
I am able to save the above code. Can you close your editor and then paste the code?
Amit Chaudhary 8Amit Chaudhary 8
Hi Bhupathi Yadav 

Can you please check you have any Apex class name with Account. If yes then please rename or delete the same apex class and retry.

Let us know if that will help you
This was selected as the best answer
Gary Holland 17Gary Holland 17
I'm getting the same thing. I rnamed the class to something else. Then back to the original name , the error went away. The question is why?
Shipra Verma 1Shipra Verma 1
Had the same problem . renamed a class named Account and then there was no error
omnamaomnama
Getting same error. Any help appreciated
code snipet


public class MyTest {
    
    public Account acc {set;get;}
    
    public MyTest(){
        
        acc = new Account();
         
        acc.Name='abc';
         
    }
}
 
omnamaomnama
issue is==> I had my own Account class; so for the above snippet; its not referring the Salesforce Account class.
Just deleted my own Account class; and NO compiler error for the above code snippet :)
 
prabhu teja 17prabhu teja 17
have same issue while creating accout name... can anyone help ?
my code is 

public class Account_create {
    public Account_create(){
        account acc=new account();
        acc.name='rover';
        acc.phone='9000452581'
        insert acc;
    }
}
清华 鲁清华 鲁
Unbelievable, this is so useful
Amit Awasthi 7Amit Awasthi 7
My scnario was when iam inserting Course Record So check Dupliacte Course_name__c and Branch__c if value is duplicate so get the error and if no then insert and update the record 
I m getting  error 
Variable does not exist: Course_Name__c
Variable does not exist: Branch__c please help me

trigger CourseTrigger on Course__c (before insert, before update) {
    list<Course__c> courselst = [Select Course_Name__c, Branch__c from Course__c];
    for(Course__c c1 : trigger.new ) {
        if(c1.Course_Name__c == courselst.Course_Name__c && c1.Branch__c == courselst.Branch__c ){
          c1.addError('Course Name is already exists');      
        } else {
            Insert c1;
        }
    }
}