I want to make a tool which will create custom objects & fields by uploading data through a CSV file. I have created the same using MetaDataService API. I'm able to create object, but can create only 5 fields at a time. If i try to upload more than 5 fields, then i'm getting the following error:- Too many callouts:11 Any suggestions?
3 Answers
You'll have to make a "batch apex" function if you want to call out many times. You can use Database.Stateful to store the results of the transaction, which you can stream back to the client after completion.
If you use the Apex Metadata API, you can leverage the BatchCreate class to create metadata items (including dependencies). Here is an example...
// Pass the Metadata items to the job for processing, indicating any dependencies
MetadataCreateJob.run(
new List<MetadataCreateJob.Item> {
new MetadataCreateJob.Item(customObject),
new MetadataCreateJob.Item(customField1, null, true), // Set wait to true, to process after object creation
new MetadataCreateJob.Item(customField2),
new MetadataCreateJob.Item(apexPage, null, true) // Set wait to true, to process after field creation
},
new MetadataCreateJob.EmailNotificationMetadataAsyncCallback());
Try to change the api version of your class/page to 28.0. I think salesforce had improved the governor limit recently in their latest versions.
-
Governor limits haven't really changed (and the new limits aren't going to help, either).sfdcfox– sfdcfox2013-09-03 03:15:51 +00:00Commented Sep 3, 2013 at 3:15