function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hemanth BakthavatsaluHemanth Bakthavatsalu 

Need help in making external (CPQ) Web Services API Calls from Salesforce

We have are planning to keep the accounts in Salesforce and CPQ system in sync.

I am trying to make a CPQ OnDemand Web Services API Call (RESTful) from a trigger to create/update a Account on the CPQ system, whenever a Account is created or updated in Salesforce..

Below is the code that i have written so far:

public class WebServiceCallout {

public static void cpqCallOut() {
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http(); String strname = 'MYsfdcUsername@abc.com';
//String strsession = getsessionid();
req.setEndpoint('https://sbx.fpx.com/rs/8/cpq/login');
req.setMethod('POST');
req.setBody('username ='+EncodingUtil.urlEncode(strname, 'UTF-8') );
req.setCompressed(true);
try {
res = http.send(req);
} catch(System.CalloutException e)
{ System.debug('Callout error: '+ e);
System.debug(res.toString()); } }}

Can anyone please guide me on how to retrieve the API sfdc Sessionid and sfdc server url from the apex code and make the updates in the external system (CPQ)

Below are the steps that I am trying to follow..I am new to writing REST API webservice callouts from Salesforce..

CPQ API: http://docs.fpx.com/docs/api/restful/14/. Look under the CPQ OnDemand Web Services API Calls (RESTful) header

Going to need three calls in particular:
1. Login - The first step will be to log in to CPQ. You will want to use the sfdcsessionid and sfdcserverurl parameters
2. Query - When updating existing Accounts you will need their CPQ ID. You can query all of the existing accounts with something like SELECT Id, ExternalId FROM Account and then match the Id (CPQ ID) to ExternalID (SFDC ID)
3. Create/Update Object - The JSON object passed in the body of this call can contain multiple accounts to create/update at once. For new accounts be sure to specify the "type":"Account" field. For accounts being updated, you can pass only the fields that need to be modified.
Andy BoettcherAndy Boettcher
SessionId = Userinfo.getSessionId();
URL = System.URL.getSalesforceBaseURL();