This is batch class use to auto-create folder for account .
global class autofolderCreator implements Database.Batchable<sObject>,Database.Stateful,Database.AllowsCallouts{
global
Map<String,String> boxFmap = new Map<String,String>();
global autofolderCreator(){
}
global Database.QueryLocator start(Database.BatchableContext BC){
// this loop use to map existing folder with account so prevent for duplication.
for(box__Folder_Meta__c mp :[select id,name,box__Folder_Id__c ,box__Folder_Name__c,box__Folder_Share_Link__c from box__Folder_Meta__c limit 9999]){
boxFmap.put(mp.box__Folder_Name__c,mp.id);
}
String query = 'Select id,name from account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> scope){
box.Toolkit boxToolkit ;
for(Account a : scope){
if(!boxFmap.containsKey(a.name)){
boxToolkit = new box.Toolkit();
String accountFolderId = boxToolkit.createFolderForRecordId(a.id, null, true);
boxToolkit.commitChanges();
}
}
}
global void finish(Database.BatchableContext BC){
}
}
No comments:
Post a Comment