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
mohsin ahmad 11mohsin ahmad 11 

have an error when executing a code in anonymous window in debug section under the developer console

When I tried to insert a record through the apex coding, I found an error :

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


The code that I used was:

Account acct = new Account(
    Name='SFDC Computing',
    Phone='(415)555-1212',
    NumberOfEmployees=50,
    BillingCity='San Francisco');
insert acct;

Please tell me , why this type of error am facing??

Regards,
Mohsin Ahmad

Best Answer chosen by mohsin ahmad 11
Neetu_BansalNeetu_Bansal
Hi Mohsin,

This issue might be because of the overriding of standard controller with custom, just check in your org for any custom controller with name Account. If you find any just try renaming them to something else or delete the controller if you dont need it.

You can check by looking under Setup -> Develop -> Apex Classes, if you find any class with name Account.

Let me know if this helps.

Thanks,
Neetu
 

All Answers

Neetu_BansalNeetu_Bansal
Hi Mohsin,

This issue might be because of the overriding of standard controller with custom, just check in your org for any custom controller with name Account. If you find any just try renaming them to something else or delete the controller if you dont need it.

You can check by looking under Setup -> Develop -> Apex Classes, if you find any class with name Account.

Let me know if this helps.

Thanks,
Neetu
 
This was selected as the best answer
mohsin ahmad 11mohsin ahmad 11
Thanks Neetu for the answer, I followed all the thing that you tell me. Now its success and am not finding any error now..
 
Darshana Nigade 6Darshana Nigade 6
I am getting error   Type requires name=value pair construction: Account

 MY Code is this : 
public static void updateEndDateOnAssetLineItem(List<Apttus_Config2__AssetLineItem__c> newList, Map<Id,Apttus_Config2__AssetLineItem__c> oldMap){
      Set<Id> accId = new Set<Id>();
        for (Apttus_Config2__AssetLineItem__c assetList : newList)
            {
              if((assetList .Apttus_Config2__AssetStatus__c=='Activated') &&  oldMap.get(assetList .Id).Apttus_Config2__AssetStatus__c!='Activated')
               { 
                 accId.add(assetList .Apttus_Config2__AccountId__c);
               }   
       }
      Map<ID, Account> accMap = new Map<ID, Account>([SELECT Id,Latest_Asset_line_item_End_date__c  FROM Account where Id IN: accId]);
      List<Account> accList= new List<Account>();
        for (Apttus_Config2__AssetLineItem__c assetList : newList)
          {
            // getting error on this line.
             Account acc =new Account([Select Id, Latest_Asset_line_item_End_date__c  from Account where Id=: assetList.Apttus_Config2__AccountId__c]);    //Type requires name=value pair construction: Account  
            

             //Account acc= new Account();
               //acc.ID=[Select Id  from Account where Id=: assetList.Apttus_Config2__AccountId__c]; 
              //acc.Latest_Asset_line_item_End_date__c=[Select Latest_Asset_line_item_End_date__c  from Account where Id=: assetList.Apttus_Config2__AccountId__c];
              //List<Account> accList= [Select Id, Latest_Asset_line_item_End_date__c  from Account where Id=: assetList.Apttus_Config2__AccountId__c];
              
              if((assetList .Apttus_Config2__EndDate__c > accMap.get(assetList .Apttus_Config2__AccountId__c).Latest_Asset_line_item_End_date__c  ||
                accMap.get(assetList.Apttus_Config2__AccountId__c).Latest_Asset_line_item_End_date__c == Null) && assetList.Product_Family__c!='Trial' && assetList.Product_Family__c!='Professional Service')
              {
                  acc.Latest_Asset_line_item_End_date__c = assetList .Apttus_Config2__EndDate__c ;
              }
            accList.add(acc);
          }
    if(accList.size()>0){
        Set<Account> accset = new Set<Account>();
        List<Account> resultAccList = new List<Account>();
        accSet.addAll(accList);//deletes duplicates
        resultAccList.addAll(accSet);//populates new list without duplicates           
        update resultAccList; }
    }