+ 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
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',
                    { "Name" : 'Acme2',

// 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()) {

return accountIds;