Salesforce – Quickbooks Online Integration – oAuth 2.O

Hi All, Hope you all enjoyed my previous Integration related posts. I have come up with another integration. In this post we will make connection between Salesforce and Quickbook System using Apex, VF page.

Earlier Quickbooks uses oAuth 1.0 for the authentication but now it has updated it’s API and using oAuth 2.0 so in this Integration we are going to use oAuth 2.0

Step1 – Create a Custom Object OR Custom Metadata to store the information about Access and Refresh Token. If you are thinking about to use Custom Setting the answer is No because Access Token length is more than 255 Character and in Custom Setting we can store data upto 255 Character.

Setup -> Create -> Objects -> New -> Your Object will look like below image

QuickBooks Infos Object

Step2 – Create a Trail Account of QuickBooks From Here.

Step3 – Create a connected App into QuickBooks Developer account, Follow the steps given into this Link. Please enter a redirect URI. for example if you want to redirect into “QuickbookConnection” VF page and your org base URL is “” then your Redirect URI will be as given below


Step4 – Now, in this Step get the Consumer Secret and Consumer Key and to get the key follow the steps given in This Link.

Connected App

Step5 – Now, Create a Apex Class. File -> New -> Apex Class -> Name it “QuickbookConnection” -> OK. Use below code the class

Step5 – Create a VF page. File -> New -> Visualforce Page -> Name “QuickbookConnection” -> OK. and use below code for this page

<apex:page controller="QuickbookConnection">
<apex:slds />
<apex:form id="theForm" >
<apex:pageblock >
<apex:pageMessages ></apex:pageMessages>
<apex:actionstatus id="statusAuthQuickBooks">
<apex:facet name="start">
<div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb; height:100%;opacity:0.65;width:100%;">
<div class="waitingHolder" style="top: 100px; width: 91px;">
<img class="waitingImage" src="/img/loading.gif" title="Please Wait..." />
<span class="waitingDescription">Loading...</span></div>
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!doAuthorizationQuickBooks}" value="Authorize with Quickbooks" />
<apex:commandButton action="{!doFetchAccessToken}" value="Complete Authorzation" status="statusAuthQuickBooks"
reRender="theForm" />

tada we have done with the coding and configuration part, now time to test the functionality. Click preview on the VF page. Click on Authorize with QuickBooks it will take you to login page of QuickBooks login with your username and password.

If you have more than 1 Sandbox it will list all the sandbox over there select one which you want to integrate.

Authorize the Application and you will be redirected to the same page now click on Complete Authorization it will create a record for the custom Object that you have created with success message

See the working in below gif Image

Salesforce - Quickbooks Working.gif

Now, We have access token we can make the callout to get the data from QuickBooks into Salesforce. You can find the complete code form Here.

If you have any problem then please come up into comment section.

Happy Learning 🙂 😉

Resources –

9 thoughts on “Salesforce – Quickbooks Online Integration – oAuth 2.O

  1. dre1979 January 5, 2019 / 7:18 pm

    Are you able to provide a test apex class as well.


    • Amit Singh January 7, 2019 / 12:37 pm

      I have not developed the test class for the same. But to write the test class you need to create a Mock class and then use that Mock class inside the test class.


  2. Sam January 2, 2019 / 10:17 pm

    Hello, thanks for the code snipped. I have a question: Where exactly you are calling the method doRefreshAccessToken( ). I didn’t find any references of that method in either of your Apex class or Visualforce page.


    • Amit Singh January 3, 2019 / 3:16 am

      Hi Sam,

      I am not using that method in any other methods the method only contains the logic to refresh the token. You need to call that method from the method which is responsible for making the API call before you make API call it’s best practice to check if token is valid or NOT.


      • Sam January 3, 2019 / 3:47 am

        Awesome. I get it now. Your article is really helpful. If you could also provide a way to actually performing call outs to get/put the data from/to Quickbooks, like an interface on the Salesforce, that would be really appreciated. Thank you for your hard work.


  3. Brent December 10, 2018 / 8:18 pm

    Just to mention, your step 5 content for the VFP page seems to be HTML encoded, so formatting looks wacky.


  4. Brent November 12, 2018 / 10:30 pm

    Hi and thanks for sharing… I am getting an error in Salesforce — “Invalid type: QuickBookIntegrationInfo__c” which is referenced in the doRefreshAccessToken function.

    This also brings up the question of how are you handling the token refresh since it does expire and requires a refresh frequently?


    • Amit Singh November 13, 2018 / 7:14 am

      Well QuickBookIntegrationInfo__c was the custom setting that we user previously but now we are using a new custom object and I have replaced the code with the new version of the code.

      As per refreshing the Access Token you need to create a new DateTime Field and Name it “Expires In (Time)” API name Expires_In_Time__c and then use the code provided in the blog. Now, Before making the API call check if the time that is in Expires_In_Time__c field is less than or equals to now then get the new token with the help of Refresh Token and use this new token to make the Call.

      After making the API call update the Token Information if you will try before the call out you will get the Error.

      Hope I am clear to you.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s