There could be several ways to automate sobject creation, if we need to create multiple custom objects.
If you use SFDX, it is possible to use shane
plugin to create custom object metadata file and then deploy those files or create a package from them and install the package.
upperlim=2000
for ((i=0; i<=upperlim; i++)); do
echo "$i"
sfdx shane:object:create -t custom -l "CustomObject$i" -p "CustomObjects$i" -a "CustomObject${i}__c"
done
Another option is to use Metadata API and create them in Apex
for (Integer i = 0; i < 100; i++) {
HttpResponse res = MetadataApiCustomObjectCreate.add('CustomObject' + i);
System.debug(res.getBody());
}
with use of the following class
public without sharing class MetadataApiCustomObjectCreate {
private static String getSoapBodyXml(String name) {
return ''
+ '<?xml version="1.0" encoding="utf-8"?>'
+ '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
+ '<env:Header>'
+ '<urn:SessionHeader xmlns:urn="http://soap.sforce.com/2006/04/metadata">'
+ '<urn:sessionId>' + UserInfo.getSessionId() + '</urn:sessionId>'
+ '</urn:SessionHeader>'
+ '</env:Header>'
+ '<env:Body>'
+ '<createMetadata xmlns="http://soap.sforce.com/2006/04/metadata">'
+ '<metadata xsi:type="CustomObject">'
+ '<label>' + name + '</label>'
+ '<pluralLabel>' + name +'s' + '</pluralLabel>'
+ '<fullName>' + name + '__c' + '</fullName>'
+ '<nameField><label>Name</label><type>Text</type></nameField>'
+ '<deploymentStatus>Deployed</deploymentStatus>'
+ '<sharingModel>ReadWrite</sharingModel>'
+ '</metadata>'
+ '</createMetadata>'
+ '</env:Body>'
+ '</env:Envelope>'
;
}
public static HttpResponse add(String name) {
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getOrgDomainUrl().toExternalForm() + '/services/Soap/m/50.0');
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', '""');
req.setBody(getSoapBodyXml(name));
return new Http().send(req);
}
}