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
siva sai 22siva sai 22 

Variable does not exist: LastName

hi ,
while is inserting the code,i am getting error i.c "Variable does not exist: LastName" .why it is comming like this and my naming convensions is also correct.cany any one help me?
here i am aposting my code error  is in line no 11 to 15(in line no 15 i am getting error like DML requires SObject or SObject list type: lead) can you resolve it ??

public class MyLe {
    public string lastName{set;get;}
    public string com{set;get;}
    public string leadSource{set;get;}
    public string phoe{set;get;}
    
    
    public void create()
    {
              lead le =new lead();
11)                le.LastName=lastName;
12)                le.Company=com;
13)                le.LeadSource=leadSource;
 14)               le.Phone=phoe;
 15)               insert le;        
    }
}
devedeve
hello,

You are getting this error because there is no standard field 'LastName' on standard Lead object which you have defined on 11th line 'le.LastName'.
Pasan   EeriyagamaPasan Eeriyagama
Field names and code is alright. I tested below in anonymous and works fine.
 
MyLe l = new MyLe();

l.lastName = 'test1';
l.com = 'company';
l.leadSource = '';
l.phoe = '4324234324';

l.create();

Are you getting the error in runtime? can you please check if it's because your profile does not have access to Lead object?  
siva sai 22siva sai 22
Hi Pasan,
           it's already have full access to lead object.yeah while i am developing code only it is commimg like that(run time error )
Pasan   EeriyagamaPasan Eeriyagama
I believe it's a compile time error then as below. Can you please add a screenshot of it to be clear anyway.

Runtime: code execution time
Compile time: errors when written code is compiled (when saving the written code to Salesforce in code editor)