Connect Salesforce with

Hi All, We all know that’s how costly it is to store data in So we always want to store data in third party so that we can reduce the cost. Thats why today I am sharing the authorization process between Salesforce and in my Integration series.

For this first you need to go to for a Developer account which you can create here.

After successful account creation you need to create an App to get the key and token. You can create an app here.

After creation your app will look like this.




Give your Visualforce page url as redirect URL. Now use the below code to perform the authorization process.


[code language="java"]
public with sharing class BoxComIntegration {
    //Fetched from URL
    private String code ;
    private string key = 'llpm**************2ks8';
    private string secret = 'LMh**************jCmK2fDHK' ;
    private string redirect_uri = '';
    public BoxComIntegration()
        code = ApexPages.currentPage().getParameters().get('code') ;  
        //Get the access token once we have code
        if(code != '' && code != null)
            AccessToken() ;
    public PageReference BoxAuth()
        PageReference pg = new PageReference(BoxAuthUri (key , redirect_uri)) ;
        return pg ;
    public String BoxAuthUri(String Clientkey,String redirect_uri)
        String key = EncodingUtil.urlEncode(Clientkey,'UTF-8');
        String uri = EncodingUtil.urlEncode(redirect_uri,'UTF-8');
        String authuri = '';
        authuri = ''+
        return authuri;
    public void AccessToken()
        //Getting access token from google
        HttpRequest req = new HttpRequest();
        String messageBody = 'code='+code+'&client_id='+key+'&client_secret='+secret+'&redirect_uri='+redirect_uri+'&grant_type=authorization_code';
        req.setHeader('Content-length', String.valueOf(messageBody.length()));

        Http h = new Http();
        String resp;
        HttpResponse res = h.send(req);
        resp = res.getBody();
         Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res.getBody()) ;  
          String token =  String.valueOf(responseMap.get('access_token'));


VF Page:

[code language=”html”]

<apex:page controller="BoxComIntegration">
<apex:form >
    <apex:pageblock > 
        <apex:commandbutton action="{!BoxAuth}" value="Authentication">



Also add two Base URLs in remote site setting. And now you are all set when you run this code you will get access token and using that token you can easily upload, download the files.


Let me know if you like this post. Do you have anything to add in the post. let me know in comments section.

Also check second post of Integration series connect salesforce with box com part 2



4 thoughts on “Connect Salesforce with

    1. When we make a request to server User first need to allow our app to access his data. When user allow our app then we get a long string of code. Thats code value we are using here.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.