Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created September 27, 2018 15:37
Show Gist options
  • Save swapnilshrikhande/5896cce8a1fe0242f87fbecbac8d3e2b to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/5896cce8a1fe0242f87fbecbac8d3e2b to your computer and use it in GitHub Desktop.
Opportunity opp = [select Reason_for_No_Withdrawal_Symptom__c,Withdrawal_Symptoms__c from opportunity where id='006g000000GVeVq'];
Map<String,Object> deserializeMap = (Map<String,Object>)JSON.deserializeUntyped(JSON.serialize(opp));
Map<String,String> oppRecord = new Map<String,String>();
for(String key : deserializeMap.keySet()){
if( 'attributes'.equalsIgnoreCase(key) )
continue;
Object value = deserializeMap.get(key);
oppRecord.put(key,String.valueOf( value != null ? value : ''));
}
System.debug(oppRecord);
//--
Opportunity updateRecord = (Opportunity)JSON.deserialize(JSON.serialize(oppRecord),Opportunity.class);
updateRecord.Name = 'Test Record';
update updateRecord;
System.debug(updateRecord);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment