You need to sign in to do that
Don't have an account?
Pedro Garcia G
sobject date type dynamic insert
hi...
I'm inserting Contact records from an array of object in JSON format.
The object property name does not match with the Contact field name. I've created a mapping for this purpose.
The issue is when the field format is the date such has Contact.birthdate.
How could I parse every field based on the field type?
Thanks
Here is my code:
this is the field mapping
I'm inserting Contact records from an array of object in JSON format.
The object property name does not match with the Contact field name. I've created a mapping for this purpose.
The issue is when the field format is the date such has Contact.birthdate.
How could I parse every field based on the field type?
Thanks
Here is my code:
public static boolean insertBunch(List<Object> selectedItems, boolean setFile, CAS_Export_File__c fileProperty){ List<Contact> contactList = new List<Contact>(); Map<Object, Object> fieldMap = (Map<Object, Object>) selectedItems[0]; Set<Object> fieldSet = new Set<Object>(); fieldSet = fieldMap.keySet(); Map<String,String> fieldsMapping = MyContact.fieldsMapping; for(Integer i=0; i< selectedItems.size(); i++){ Map<Object, Object> mObject = (Map<Object, Object>) selectedItems[i]; Contact newContact = new Contact(); for(Object fieldname : fieldSet){ if(fieldsMapping.get((String) fieldname) !=null) newContact.put(fieldsMapping.get((String) fieldname), mObject.get((String) fieldname).toString()); } contactList.add(newContact); } System.debug('cas7.13>>>'+contactList); insert contactList; return (contactList.size()>0); }
this is the field mapping
public static Map<String,String> fieldsMapping = new Map<String,String>{ 'last_name' =>'LastName', 'first_name' =>'FirstName', 'email' =>'Email' , 'date_of_birth' =>'Birthdate', 'permanent_street_address' =>'MailingStreet', 'permanent_street_address_2' =>'OtherStreet', 'permanent_city' =>'MailingCity', 'permanent_state' =>'MailingState', 'permanent_postal_code' =>'MailingPostalCode', 'permanent_country_name' =>'MailingCountry'};