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
Praz01Praz01 

Invalid constructor syntax, name=value pairs can only be used for SObjects

I am using the following code for past 1 year but suddenly today this error cropped up which was not there earlier

 

Account[] accts = new Account[]{};
        accts.add(new Account(name = 'ApexTestPOSController1', Local_Id__c = 'SimId2009083001'));
        accts.add(new Account(name = 'ApexTestPOSController2', Local_Id__c = 'SimId2009083002'));
        accts.add(new Account(name = 'ApexTestPOSController3', Local_Id__c = 'SimId2009083003'));
        insert accts;

 

 

How to get rid of it?

Praz01Praz01

This error is quite erratic too..sometimes coming and sometime going

paul-lmipaul-lmi

try changing it to

 

List<Account> accts = new List<Account>();

Pradeep_NavatarPradeep_Navatar

I have tried your code,  it works fine except local_id. It may be due to account object local_id field .

Praz01Praz01

Actually now it's not  giving any problem ...I think this is quite erratic..

PatelPatel

Hi Guys,

 

I am new to salesforce.

 

When i am trying to insert data into an object ,I am receiving the error "Invalid constructor syntax, name=value pairs can only be used for SObjects".

 

Apex

---------

public with sharing class Account {

public Integer total { get; set; }

 public integer Number2 {get; set; }

public integer Number1 { get; set; }

public pagereference Add()
{
/*Number2=Number2;
Number1 =Number1;*/
total=Number1 + Number2;


Account a=new Account(Number1=Number1,Number2=Number2,total=total);
insert a;
// Database.SaveResult[] results = Database.insert(a);

return null;
}

}

 

Thanks in advance,

Patel.