So we are used to develop apex code with static reference. What it means is the code is referencing the object directly and when this code is moved in a package then the referenced object will automatically be included in it. But it might happen that you only need the code to be included in the package as the object is already present in the install org.
Static reference code:
Dynamic reference code:
Static reference code:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Account acc = new Account(); | |
acc.Name = 'Account Name'; | |
acc.Phone = 9999999999; | |
insert acc; |
Dynamic reference code:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sobject acc; | |
String sObjectNamet = 'Account'; | |
Schema.SObjectType temp = Schema.getGlobalDescribe().get(sObjectNamet); | |
acc = temp.newSObject(); | |
acc.put('Name','Account Name'); | |
acc.put('Phone',9999999999); | |
insert acc; |
No comments:
Post a Comment