新しいBoxサポートサイトへようこそ。 変更点の詳細はこちらをご確認ください .

Box for Salesforce Auto-Add attachments

新規投稿

コメント

2件のコメント

  • spharrin

    Did you ever have any luck in auto creating the Box case folders?  I'm looking into the same functionality right now.

    0
    コメントアクション Permalink
  • bbfaef

    Yes, I created a trigger on Case that calls a Queueable Class. This is good for Classic, but Lightning uses "Files", which I haven't figured out yet.

     

    trigger CaseBoxFolderTrigger on Case (after update) {
    	
        List myId = new List();
        
        for( Case ca : trigger.new ) {
           //Check if Case has attachments and they are not too large to send to Box upload Queue
            List atts = new List([Select ID, BodyLength from Attachment where ParentID =: ca.id]);
            if (!atts.isEmpty() && Limits.getHeapSize() < 3000000 ){
                for (Attachment att: atts ){
                    myId.add(att.id);
                }
            }        
        }
        System.enqueueJob(new AttachmentBoxFolderHandlerQueueableJob(myId));

    I included a limit on heap size to try and limit large file uploads as SF has a gov limit.

     

    global class AttachmentBoxFolderHandlerQueueableJob implements System.Queueable, Database.AllowsCallouts {
    	//get list of attachments and then queue them to load into the Box folder of the Parent Object
        List attachments {get; set;}
        
        global AttachmentBoxFolderHandlerQueueableJob (List attachments) {
            this.attachments = attachments;
    	}
        global void execute (QueueableContext context) {
         		List attachments = new List([Select Id, Name, Body, ParentId from Attachment where Id IN: attachments]);        
                box.Toolkit boxToolkit = new box.Toolkit();
                
            // Add the Attachment to Box
                for (Attachment att : attachments){
                    String fileId = boxToolkit.createFileFromAttachment( att, null, null, null);
                    system.debug('new item id: ' + fileId);
                  /* createFileFromAttachment params:
        			Attachment att - required - This is the file to add in Box
        			String fileNameOverride - optional/null - If a non-null value is sent, that will be the name of the file in Box (be sure to include the extension)
        			String folderIdOverride - optional/null - If a value is sent, the attachment will be uploaded to this folder id.  Otherwise, it is uploaded to the folder associated with this salesforce record.  If no folder exists, one will be created
        			String accessToken - optional/null - If a value is sent, this will be used as the accessToken to connect to box.  Otherwise, the service user credentials are used.  Generally this is sent as null.
    			  */
                }
              boxToolkit.commitChanges();
    	}
    }

    Our Cases are assigned to a Queue, so once an individual takes ownership the trigger fires and the folder is created and the files uploaded. This has saved us $$$ by limiting our SF File space, and we can then send links to the files in case responses or to other departments. 

    0
    コメントアクション Permalink

サインインしてコメントを残してください。