You need to sign in to do that
Don't have an account?
Gopal Das 13
Instantiate custom object by name and insert record into it
How to create custom object dynamically?
I have one method in Apex controller which takes two arguement like below -
insertIntoCustomObjectDynamic(customObjectName, Map<String, String> fieldvalues){
//customObjectName can be any customobject name inside the org, its not static or predefined value
//if customObjectName is like MyObject__c then it will insert all the field values into MyObject__c customobject.
}
I have one method in Apex controller which takes two arguement like below -
insertIntoCustomObjectDynamic(customObjectName, Map<String, String> fieldvalues){
//customObjectName can be any customobject name inside the org, its not static or predefined value
//if customObjectName is like MyObject__c then it will insert all the field values into MyObject__c customobject.
}
Try the below code which will dynamically inserts data into Objects based on customObjectName parameter. Let me know if you get any issues.
You need to extend this to support more DATA Types.
All Answers
This should be straight forward.
1) Write a nested if according to customObjectName, basically to get the insert into text.
2) And inside the nested if, iterate the map values and form the query.
The points one and two working together are forming a dynamic query.
And finally outside the nested if block call the Salesforce update query which updates the custom object.
I have to say this is pretty neat
Hope it helps
RD
Try the below code which will dynamically inserts data into Objects based on customObjectName parameter. Let me know if you get any issues.
You need to extend this to support more DATA Types.