Generic Code to Insert Record in Object Salesforce

// Get object type by passing object name
Schema.SObjectType objType = Schema.getGlobalDescribe().get(objectName);

// Create instance of sObject
sObject genericObj = objType.newSObject();

//Set fieldValue for each fields, you want to set
//@param:fieldApiName must be of String type
//@param:fieldValue of any data type value

//Insert record by Insert statement
Database.insert(genericObj, true);

Leave a Reply

Your email address will not be published. Required fields are marked *