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
Jha dilipJha dilip 

Regarding generic method

hi all i want to create a method with following requirements and it should be generic. The number of fields is not constant i.e. in some instances there might be 3 fields to be updated in some cases there could be 10 on account object.

The methods should either return the AccountID created or a list of AccountIDs created
  The method should always create the object with all required fields with default values

any sugesion
Vivek DVivek D
Use JSON,
Assuming you can populate the fields dynamically in your VF and from JavaScript remoting pass string of object.
// This JSON can be dynamic based on the requirement add as many fields you want
 [
                     { "Name" : 'Acme',
                       "Phone":"232131"
                     },
                    { "Name" : 'Acme2',
                       "Phone":"232131"
                     }
   ]

// Apex Class method

String jsonString = yourStringFromPage;

List<Account> accounts = (List<Account>)JSON.desearialize(jsonString,List<Account>.class);

Database.SaveResult[] saveRes = Database.insert(accounts);

List<String> accountIds = new List<String>();
for (Database.SaveResult sr : saveRes ) {
    if (sr.isSuccess()) {
        accountIds.add(sr.getId());        
    }
}

return accountIds;