An effort to bring a revolution in Salesforce.

Saturday, 18 June 2016

Salesforce auto-create folders for all Account? Box.com




 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){
   }
}

 Box.com,Auto create folder for account.

, , ,

No comments:

Post a Comment

Get Gmail, Docs, Drive, and Calendar for business