Trigger for Creating Folder On Account Insert.
trigger BoxFolderCreationTrigger on Account (after insert) { public Set<ID> accids = new Set<ID>(); for(Account acc : Trigger.New) { accIds.add(acc.Id); } if(accIds.size() > 0) { BoxFutureClass.createFolder(accIds); } }
As Call-out is not allowed in Trigger.Here i have call Future class method for call-out.
Snippet OF Future Class.
global class BoxFutureClass
{
@future(callout=true)
public static void createFolder(set<ID> AccIds) {
Map<String,String> boxFRUPMap = new Map<String,String>();
for(box__FRUP__c bF : [SELECT box__Folder_ID__c,box__Record_ID__c FROM box__FRUP__c where box__Object_Name__c = 'Account' limit 9999]) {
boxFRUPMap.put(bF.box__Record_ID__c,bF.box__Folder_ID__c);
}
for(Account acc : [Select id,name from account where id IN :AccIds])
{
box.Toolkit boxToolkit ;
if(!boxFRUPMap.containsKey(acc.Id))
{
boxToolkit = new box.Toolkit();
String accountFolderId = boxToolkit.createFolderForRecordId(acc.Id,null, true);
boxToolkit.commitChanges();
}
}
}
}
box__FRUP__c is custom object for box folder to keep track of folder created by recordId.
No comments:
Post a Comment