You need to sign in to do that
Don't have an account?
sessu
hi
Hi I need to convert Lead to contactand account at the time I am saving the code its dsiplaying an error Error: Compile Error: Field is not writeable: Contact.Name at line 14 column 6, please help me public class CMyLeadControllerExtension { public ApexPages.StandardController LEAD; public CMyLeadControllerExtension(ApexPages.StandardController stdController) { this.LEAD = stdController; } Lead abc = [select Id,Name, Email, Company from Lead where id = :apexpages.currentpage().getparameters().get('id')]; public pageReference doCreateAccount(){ Account newacc = new Account(); newacc.Name = abc.Company; insert newacc; Contact newcon = new Contact(); newcon.Name = abc.Name;---------------------------------- insert newcon; pageReference p = new pageReference('/' + newacc.id); p.setRedirect(true); return p; } }
In contact Name is not a writeable field it's just a combination of first & last name
Try this:--
public class CMyLeadControllerExtension
{
public ApexPages.StandardController LEAD; public CMyLeadControllerExtension(ApexPages.StandardController stdController)
{
this.LEAD = stdController;
}
public pageReference doCreateAccount()
{
Lead abc = [select Id,Name, Email, Company from Lead where id = :apexpages.currentpage().getparameters().get('id')];
Account newacc = new Account();
newacc.Name = abc.Company;
insert newacc;
Contact newcon = new Contact();
newcon.LastName = abc.Name;
insert newcon;
pageReference p = new pageReference('/' + newacc.id); p.setRedirect(true); return p;
}
}
Hi sesu
As we know Name Is standard field and Standard filed is not writable . That's why you are facing error . But your problem is solved by using FirstName and LastName field..
try this......
public class CMyLeadControllerExtension
{
public ApexPages.StandardController LEAD;
public CMyLeadControllerExtension(ApexPages.StandardController stdController)
{
this.LEAD = stdController;
}
Lead abc = [select Id,FirstName,LastName, Email, Company from Lead
where id = :apexpages.currentpage().getparameters().get('id')];
public pageReference doCreateAccount()
{
Account newacc = new Account();
newacc.Name = abc.Company;
insert newacc;
Contact newcon = new Contact();
newcon.FirstName = abc.FirstName ;
newcon.LastName = abc.LastName ;
---------------------------------- insert newcon;
pageReference p = new pageReference('/' + newacc.id);
p.setRedirect(true);
return p;
}
}
Did this post solve your problem if so please mark It solved so that other's get benifited...
Thanks
asish
Hi asish
Actully Name field is a not a Standard filed it's a "System Field"
also Standard fileds are writable......
Name is system field like "createdby" & that's why it's not writable
Hi SRK
I think Name is a Standard filed .We can not write in to standard field from apex class. yes we can enter value from visualforce page or manully in database. It is impossible to write Contact.Name = 'SRK' ;
Thanks
asish
As i said it's system fields so it's true that u cannot insert values init
but for example account also have the name fields & it's a standared field & it's writable
but earlyler u mention that standard fields are not writable.....
& Yes we can enter value in standard fieds from apex class
i can assign any text to account.name field from my apex class where name is a standard fields
we cannot assign any thing in system fields
like Name field in contact which is a system field
also like createdby & e.t.c.
hi
yes, you are right , but If Name is System field why it is displayed under Contact Standard field .
here is the link
https://ap1.salesforce.com/p/setup/layout/LayoutFieldList?type=Contact&setupid=ContactFields&retURL=%2Fui%2Fsetup%2FSetup%3Fsetupid%3DContact
Let me know the cause
Thanks
asish
All System field are Standard Fields but all Standard Fields are not System field
You said earlier that Standard Fields are not writable but that not correct
even CreatedBy show's under Standard Fields but it's a system fields
as i say All System field are Standard Fields but all Standard Fields are not System field
Example
Name in contact is come under Standard Fields section but it's a System field
But Name in account object is comes under Standard Fields section & it's a Standard Fields & it writable
so it is wrong to say that "Standard Fields are not writable"
ok
Hi sesu
Please write your problem in a proper maner so that It will be easy to understands what excatly you want....
thanks
asish