Salesforce documentation has Dynamic Sobject Creation Example The test class gives an example of how to check if object exists and the create the object. Unfortunately they use Account which every org has. How do you do the same thing with CustomObject__c c? Not Sobject s which I know we can use but requires get and put which is bit more cumbersome vs c.Name.
If I use CustomObject__c = (CustomObject__c)DynamicSobjectCreation.createObject(typeName)
and it doesn't exist in the org, get a deployment error in SFDX.
Invalid type: CustomObject__c
The point of the exercise is to see if the object exists in the first place and instantiate it.
// Create a new sObject by passing the sObject type as an argument.
**Account a = (Account)DynamicSObjectCreation.createObject(typeName);**
System.assertEquals(typeName, String.valueOf(a.getSobjectType()));
// Set the account name and insert the account.
a.Name = acctName;
insert a;
}
}