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
masthan khanmasthan khan 

Line: 1, Column: 8 Invalid constructor syntax, name=value pairs can only be used for SObjects: Lead

Hai, 
Iam Getting following error:
Line: 1, Column: 8
Invalid constructor syntax, name=value pairs can only be used for SObjects: Lead

Lead l=new Lead(lastname='Ch',FirstName='Satish',Company='Capital',leadSource='Web');
            insert l;
            Database.LeadConvert  lc =new Database.LeadConvert();
            lc.setLeadId(l.id);
            LeadStatus stat= [select id,MasterLabel  from LeadStatus where isConverted=true];
            lc.setConvertedStatus(stat.MasterLabel);
            Database.convertLead(lc);
With Regards
Masthan
Prady01Prady01
The below piece of the code seems to be working fine!! the error seems to be some place else. I was able to run your code in developer console with no errors.
 
Lead l=new Lead(lastname='Ch',FirstName='Satish',Company='Capital',leadSource='Web');
            insert l;
            Database.LeadConvert  lc =new Database.LeadConvert();
            lc.setLeadId(l.id);
            LeadStatus stat= [select id,MasterLabel  from LeadStatus where isConverted=true];
            lc.setConvertedStatus(stat.MasterLabel);
            Database.convertLead(lc);

Thanks,
Prady01​
Akshay_DhimanAkshay_Dhiman
Hi Masthan,

so try this code,
 
Lead myLead = new Lead(LastName = 'Fry', Company='Fry And Sons');
insert myLead;

Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(myLead.id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());


Hope it might help you.

 Thanks 
 Akshay