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
sessusessu 

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; } }
SRKSRK

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;
  }
  }

asish1989asish1989

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

SRKSRK

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

asish1989asish1989

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

SRKSRK

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.....

SRKSRK

& 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.

asish1989asish1989

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

SRKSRK

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"

asish1989asish1989

ok

sessusessu
Hi Ashish Thanks My Code worked, Now, I need to display details of lead to contact after conversion(need to display in related list of account), for that I need to match account id to contact so that we will come to know which account belongs to which contact ......... My code is getting saved but while converting lead I am getting error. I need to display account name and in its related list contact all the data Visualforce Error :Help for this Page System:.StringException: Invalid id: XYZ Error is in expression '{!doCreateAccount}' in component in page leadconvert Class.CMyLeadControllerExtension.doCreateAccount: line 15, column 1 and my code is..... public class CMyLeadControllerExtension { public ApexPages.StandardController LEAD; public CMyLeadControllerExtension(ApexPages.StandardController stdController) { this.LEAD = stdController; } Lead abc = [select Id,Name, Email, Company,MobilePhone 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.LastName = abc.Name; newcon.Accountid = abc.Company; -------------------------------------------------------------------------------------error newcon.MobilePhone = abc.MobilePhone; newcon.Email = abc.Email; newcon.FirstName = abc.Name; insert newcon; pageReference p = new pageReference('/' + newacc.id); p.setRedirect(true); return p; } } Please help me.
asish1989asish1989

Hi sesu

  Please write your problem in a proper maner so that It will be easy to understands what excatly you want....

 

 

  thanks

  asish