You need to sign in to do that
Don't have an account?

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;
}
}
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;
}
}
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
Let me know if this helps.
It shows same thing
I have updated your code a little bit. Please refer the above.
Pankaj, But it shows same thing
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
code snipet
public class MyTest {
public Account acc {set;get;}
public MyTest(){
acc = new Account();
acc.Name='abc';
}
}
Just deleted my own Account class; and NO compiler error for the above code snippet :)
my code is
public class Account_create {
public Account_create(){
account acc=new account();
acc.name='rover';
acc.phone='9000452581'
insert acc;
}
}
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;
}
}
}