Integrating QuickBooks With Salesforce Via The REST API

Hey there, today’s topic revolves around integrating QuickBooks with Salesforce via the REST API using Named Credentials in Flow. Our process involves creating an Apex class to utilize the REST API for QuickBooks integration. Integrating QuickBooks with Salesforce via Apex is straightforward. We’ll be calling the Apex class from the Lightning flow.

What does QuickBooks entail

QuickBooks serves as accounting software designed for small businesses, enabling tasks like invoice creation, sales tracking, and providing real-time insights into business performance by accessing accounting data stored in the cloud.

Why is Integrating Salesforce with QuickBooks Essential

  1. Increase productivity by sharing the data between these.Achieve better forecasting.Give better approch for how we complete our goal.

Before delving into QuickBooks integration with Salesforce, let’s outline some key details first

  • Requirement: To automate the creation of an Account in QuickBooks when it’s created in Salesforce.
  • QuickBooks Procedure: Begin by signing up for a developer account with QuickBooks, then create an App within the account. Following this, establish an authentication provider and named credentials for QuickBooks within Salesforce.
  • Salesforce Procedure: Upon configuring the Auth provider and named credentials, create a flow that will trigger an Apex class. This class will execute a callout to the QuickBooks API using a POST request to generate a new account in QuickBooks, utilizing details sent from Salesforce.

Once the named credential is configured in Salesforce, we’ll craft an Apex class containing an Invokable method. This method will be called through the flow.

Code :


public class QuickbooksIntegration{
    public static void CreateAccount(List<Id> accountIds){
       //get account        
       List<Account> accountList = [SELECT id, name from account where id =:accountIds[0]];
      //Data map Preparation
       map<String,Object> mainMap = new map<String,Object>();
       mainMap.put('Name', accountList[0].name);
       mainMap.put('AccountType', 'Accounts Receivable');
       if(mainMap!= null && !mainMap.isEmpty()){
           //Calling Async method for callout 
    @future(callout =true)
    public static void insertOnQuickBook(String jsonData){
        //new request
        HttpRequest req = new HttpRequest();
        string  endPointURL = 'callout:quickbook_named_credentials/v3/company/4620816365165921730/account?minorversion=59';
        req.setHeader('Content-Length', '512');
        Http http = new Http();
        HTTPResponse response = http.send(req);
        //Response Handle
        if(response.getStatusCode() == 200 ){
            Map<String, Object> serializeResponseBody = new Map<String, Object>();
            serializeResponseBody = (Map<String, Object>)JSON.deserializeUntyped(response.getBody());

Generate Flow:

After creating the class we are going to create a flow that will run on the creation of Accounts in salesforce. That flow will have an Action type element which will refer to the QuickbooksIntegration class and we also will set the input parameter for the invokable method which will be the current record Id.

QuickBooks Integration With Salesforce Rest API Flow Techdicer

QuickBooks Integration With Salesforce Rest API Flow

QuickBooks Integration With Salesforce Rest API Flow