Skip to content

Example repo to show how to implement Salesforce composite graph API in node.js

License

Notifications You must be signed in to change notification settings

msrivastav13/sf-compositegraphapi-herokuapp

Repository files navigation

SF-COMPOSITEGRAPHAPI-HEROKUAPP

This is a Node.js implementation for Salesforce Graph API.

The compositeGraphBuilder.js shows how to use fluent interface to build request for Salesforce Composite Graph API.

Connection between Salesforce and Heroku is implemented using ConnectedApps and uses OAuth 2.0 JWT Bearer Flow for Server-to-Server Integration

Example Implementation

const request = require('./compositeGraphBuilder');

const lead = {LastName : "Trailhead", Company: "Salesforce"};
const leadCompositeRequest = new request.CompositeSubRequestBuilder()
    .withBody(lead)
    .withMethod("POST")
    .withReferenceId("Lead1")
    .withUrl("/services/data/v50.0/sobjects/Lead")
    .build();

const campaign = {Name : "Campaign1"};
const campaignCompositeRequest = new request.CompositeSubRequestBuilder()
    .withBody(campaign)
    .withMethod("POST")
    .withReferenceId("Campaign1")
    .withUrl("/services/data/v50.0/sobjects/Campaign")
    .build();

const campaignMember = {leadId: '@{Lead1.id}', campaignId: '@{Campaign1.id}'};
const campaignMemberCompositeRequest = new request.CompositeSubRequestBuilder()
    .withBody(campaignMember)
    .withMethod("POST")
    .withReferenceId("campaignMember1")
    .withUrl("/services/data/v50.0/sobjects/CampaignMember")
    .build();

const graph1 = new request.GraphBuilder()
    .withGraphId("graph1")
    .addCompositeSubRequest(leadCompositeRequest)
    .addCompositeSubRequest(campaignCompositeRequest)
    .addCompositeSubRequest(campaignMemberCompositeRequest)
    .build();

const graphApiInput = new request.CompositeGraphBuilder()
    .addGraph(graph1)
    .build();

console.log(JSON.stringify(graphApiInput));

Learn More

check the code in the index.js file to learn how to use jsforce to make a call to invoke Salesforce Composite Graph API

To learn more on how about the authentication and implementation, watch the below videos

About

Example repo to show how to implement Salesforce composite graph API in node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages