Salesforce

An effort to bring a revolution in Salesforce.

Showing posts with label batch. Show all posts
Showing posts with label batch. Show all posts

Thursday, 26 October 2017

Future method cannot be called from a future or batch method: Error

11:40

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

System.AsyncException: Future method cannot be called from a future.

System.AsyncException: Future method cannot be called from a future or batch method


You need to check if the trigger is being fired from the future method, add the below line as your first line of trigger.

    if(system.isFuture() || System.isBatch()) return;

Saturday, 18 June 2016

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

09:27



 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.

Get Gmail, Docs, Drive, and Calendar for business