Friday, April 17, 2020

Get the Content (Blob) of File from Box and Store/Manipulate it in Salesforce

Through this blog, I am going to share sample apex script through which you can get content of file from box as blob and then store or manipulate it within salesforce.

I have already written a blog to explain how to get box access token (needed for handshake with Box) and to display file content in salesforce in VF page without storing it in salesforce. You can cosider it as Mashup inSalesforce. Please refer below URL to that:

Box and Salesforce Integration

In order to get box file content, we need to have box file Id and box access token.

Box does not provide direct API to get file content. First you need to do callout to get download URL and then you perform another API callout to get file content. Also you perform another API call to get file details like filename in order to store it in salesforce.

I am going to store box file in salesforce library for demo purpose. You can store it as attachments or read the content on the fly to perform some logic instead of saving it.

Add below URLs in remote site settings before performing the callouts:
  • https://api.box.com
  • https://dl.boxcloud.com 

Below is required code and it is self explainatory as comments are mentioned for each methods:

Now run below script in developer console:

string boxFileId='6542xxx28604';
string access_token='0xxxxxxxxxxxxxxxxxxxxxxxxxxxredx0P';
string sfdcLibraryName='Box_File_Library';
string boxFilename= SK_BoxAPIUtilityClass.findFileNameFromBox(boxFileId,access_token);
system.debug('****boxFilename:'+boxFilename);
SK_BoxAPIUtilityClass.readFileContentFromBox(boxFileId,boxFilename,sfdcLibraryName,access_token);



Use Case

During sandbox refresh, all custom settings data gets refreshed from production values. So before refresh, you have to take back up each custom settings data and after refresh, you need to update the custom setting records. In order to automate this, you can write script through which you can push all custom setting data to box folder. Code to upload the files from Salesforce to box is already shared in blog  Box and Salesforce Integration.

Now we need to get the content of all csv files stored in box and update the custom setting in salesforce. Once you get the content of file, you can parse csv file and update custom settings.

Hope this helps!!!


15 comments:

  1. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!

    360DigiTMG

    ReplyDelete
  2. Market your store. Whenever you have the store ready for action you need to out some work into it; this is where most stores begin to fall flat.besimple.com/

    ReplyDelete
  3. What job doesn’t require attention to detail? But recently, I witnessed first hand, a group of professionals whose entire workload is attention to detail. get detail

    ReplyDelete
  4. Interchange fees published by the card brands such as Visa and MasterCard dictate the underlying costs of all credit card processing charges.Gun Credit Card Processing

    ReplyDelete
  5. Interesting topic for a blog. I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I'll be sure to check back again real soon. email marketing costs

    ReplyDelete
  6. Likewise, get data about the installment mode.transfer large files

    ReplyDelete
  7. Over time, it became common to get good grades as soon as this site https://bestessaytyper.com/write-my-essay asked me to do so, where they do any writing work in no time, with high quality and low prices, convenient for everyone.

    ReplyDelete
  8. I am now not certain the place you’re getting your information, but good topic... Content Management Systems

    ReplyDelete
  9. Such a wonder is currently underestimated by numerous individuals of us. Furthermore, it is the sheer volume of the store that permits it to stock all and anything one may require including administrations, for example, a hair style, a nail salon, and even cafés and banks. Why go elsewhere in the event that you can get everything in just one stop? https://open4u.co.uk/branches/farmfoods.html

    ReplyDelete
  10. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. 성인

    ReplyDelete
  11. A squashed box won't be solid. You need to be certain that the crates are dry, since moving boxes that were wet will handily self-destruct. I realize that this will sound somewhat interesting, yet ensure the cases don't have an awful stench! Mylabs

    ReplyDelete
  12. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. content marketing for small businesses

    ReplyDelete
  13. In the event that 'giving your retail outlet a new look' is the thing that you are searching for, here is the thing that we are taking a gander at. selective pallet racking system

    ReplyDelete