Skip to content

heroku/heroku-applink-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Node.js SDK for Heroku AppLink

Use the Node.js SDK for Heroku AppLink to develop Heroku AppLink managed apps that interact with Salesforce and Data Cloud orgs.

Node.js SDK for Heroku AppLink provides:

  • Utilities to parse requests from Salesforce Heroku-type External Services and Data Cloud Data Action Targets hydrating SDK objects that response the request: InvocationEvent and Context.
  • Objects that encapsulate the requesting Salesforce or Data Cloud Org and User.
  • Utility objects that wrap Salesforce and Data Cloud APIs to perform simple CRUD operations and complex record manipulations.

And much more!

Documentation

For more information, see API docs.

Example

Example use of the Node.js SDK for Heroku AppLink provided as part of the Heroku AppLink CLI Plugin's applink:project template:

fastify.get('/accounts', async function (request, reply) {
    const {event, context, logger} = request.sdk;

    logger.info(`GET /accounts: ${JSON.stringify(event.data || {})}`);

    const query = 'SELECT Id, Name FROM Account';

    if (process.env.SALESFORCE_ORG_NAME) {
        // If an org reference is set, query Accounts in that org
        const orgName = process.env.SALESFORCE_ORG_NAME;
        const applinkAddon = request.sdk.addons.applink;

        logger.info(`Getting org '${orgName}' connection from Heroku Applink add-on...`);
        const anotherOrg = await applinkAddon.getAuthorization(orgName);

        logger.info(`Querying org '${orgName}' (${anotherOrg.id}) Accounts...`);
        try {
            const result = await anotherOrg.dataApi.query(query);
            const accounts = result.records.map(rec => rec.fields);
            logger.info(`For org '${orgName}' (${anotherOrg.id}), found ${accounts.length} Accounts`);
        } catch (err) {
            logger.error(err.message);
        }
    }

    // Query invoking org's Accounts
    const org = context.org;
    logger.info(`Querying invoking org (${org.id}) Accounts...`);
    const result = await org.dataApi.query(query);
    const accounts = result.records.map(rec => rec.fields);
    logger.info(`For invoking org (${org.id}), found the following Accounts: ${JSON.stringify(accounts || {})}`);
    return accounts;
});

Configuration

  • HEROKU_APPLINK_ADDON_NAME - For development, configures the SDK to use a different addon name in place of "HEROKU_APPLINK". Used when fetching config vars.

Testing

Dependency

You will need java installed to run wiremock.

Running tests

To test with coverage run yarn test:coverage

About

Use the Salesforce SDK for Node.js to develop Heroku Applink managed apps that interact with Salesforce and Data Cloud orgs.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7