I have a Sobject Record which is already instantiated and fields are added along with values.

                 sObject  sObj = Schema.getGlobalDescribe().get(Name of Object).newSObject() ;
sobj.put(fieldname,fieldvalue); sobjectMap.put('id1',sobj);

Now after some logic processing , i loop through the sobject map and would like to few more fields or update the existing fields and then insert the sobject.So i did something as below , but dont seem to be successfully add new fields or update existing one, any help ?

   Sobject sobj = (SObjectMap.get(id1).clone();

   sobj.put(new field,new value);//printing sobj after adding new fields , doesnt really add field value

               SObjectMap.get(sobjUUID).put(reference,CloneSObjectMap.get(parentUUID).id);//neither do this  

1 Answer 1

There are two ways to set fields values:

SObject acc = new Account();

// Schema.FieldType, Object
acc.put(Schema.Account.Description, 'Description of Account');

// Field API name, Object
acc.put('Description', 'Description of Account');

//To update the Value
Map <String, Schema.SObjectField> fieldMap = o1.getSobjectType().getDescribe().fields.getMap();
    o1.put('Name', 'Test');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .