I need to create box.com folder for 500 Account records. Inside that Account box folder will be 12 other folders. I am using box.com's toolkit for Salesforce.
I am using a batch apex class and invoking it from the dev console. Here is the code.
global class AccountBoxFolderCreationBatch implements Database.Batchable<Sobject>, Database.AllowsCallouts, Database.Stateful {
global Database.querylocator start(Database.BatchableContext BC) {
Id householdAccountRTId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Household').getRecordTypeId();
return Database.getQueryLocator([
select
Id,
Box_Folder_Id__c,
Financial_Accounts_Parent_Box_Folder_Id__c,
CLG_Opportunities_Parent_Box_Folder_Id__c,
Real_Estate_Assets_Parent_Box_Folder_Id__c,
Tax_Documents_Parent_Box_Folder_Id__c,
Medical_Records_Parent_Box_Folder_Id__c,
Funding_Parent_Box_Folder_Id__c,
Underwriting_Parent_Box_Folder_Id__c,
Registration_Parent_Box_Folder_Id__c,
Compliance_Parent_Box_Folder_Id__c,
Contact_Parent_Box_Folder_Id__c,
Performance_Reports_Parent_Box_Folder_Id__c,
Opportunity_Parent_Box_Folder_Id__c
from Account
where RecordTypeId = :householdAccountRTId
and Box_Folder_Id__c = null
]);
}
global void execute(Database.BatchableContext BC, List<Account> scope) {
box.Toolkit boxToolkit = new box.Toolkit();
for(Account account : scope) {
account.Box_Folder_Id__c = boxToolkit.createFolderForRecordId(account.Id, null, false);
account.Financial_Accounts_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Financial Accounts', account.Box_Folder_Id__c, null);
account.CLG_Opportunities_Parent_Box_Folder_Id__c = boxToolkit.createFolder('CLG Opportunities', account.Box_Folder_Id__c, null);
account.Real_Estate_Assets_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Real Estate Assets', account.Box_Folder_Id__c, null);
account.Tax_Documents_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Tax Documents', account.Box_Folder_Id__c, null);
account.Medical_Records_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Medical Records', account.Box_Folder_Id__c, null);
account.Funding_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Funding', account.Box_Folder_Id__c, null);
account.Underwriting_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Underwriting', account.Box_Folder_Id__c, null);
account.Registration_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Registration', account.Box_Folder_Id__c, null);
account.Compliance_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Compliance', account.Box_Folder_Id__c, null);
account.Contact_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Contact', account.Box_Folder_Id__c, null);
account.Performance_Reports_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Performance Reports', account.Box_Folder_Id__c, null);
account.Opportunity_Parent_Box_Folder_Id__c = boxToolkit.createFolder('Opportunities', account.Box_Folder_Id__c, null);
}
boxToolkit.commitChanges();
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
However it keeps giving me the following error.
First error: box:Too many callouts: 101
I even tried reducing the number of batches by doing
AccountBoxFolderCreationBatch objTest = new AccountBoxFolderCreationBatch();
Database.executebatch(objTest, 50);
But it still fails.
Where am I going wrong?