GuideStar (Candid) Salesforce integration

Look up any US nonprofit by EIN and pull its data and charity status straight into the Account. Built and tested before a trial API key ran out.

Custom REST API integration for nonprofit data and charity verification · 2021

The challenge

Before money goes to a nonprofit, somebody has to confirm it is a real one. The official name, the IRS status, whether donations to it are actually tax-deductible. None of that was in Salesforce.

GuideStar, now part of Candid, holds it for almost every nonprofit in the US. My client wanted the check to happen on the Account, where the work already happens, instead of somewhere else.

The catch was time. I only had a trial API key, which meant I had to build and test the whole integration in a sandbox before the trial ran out. No second chances to just check one more response later.

What the user sees

The user opens an Account, enters the EIN and clicks one button in a custom component. A few seconds later the Account has the organization's official name, address and its charity and tax-exempt status, straight from GuideStar.

The EIN, the Employer Identification Number, is the ID every US nonprofit has, so it was the natural key for the search. It also comes in different formats, with or without the dash, so the input has to be cleaned before it goes anywhere.

How the connection works

GuideStar's API used a subscription key rather than OAuth. In 2021 Salesforce only had what we now call legacy Named Credentials. The key lived in the Named Credential and went out in a custom HTTP header with a merge field. That way it never sits in Apex code and nobody reads it off the org. The endpoint also needed a Remote Site Setting.

The Apex side

Salesforce sends the callout, gets JSON back and maps it to the Account fields. JSON from an external system is never as tidy as the documentation promises, so the mapping has to survive empty fields and missing values without breaking the record.

Charity status is a good example of why the details matter. Being tax-exempt with the IRS and being eligible for tax-deductible donations are not the same thing, and GuideStar's data separates the two. Mapping them to one checkbox would have looked fine and been wrong.

Some of the processing runs in asynchronous Apex, so the user isn't waiting on it and the org stays inside its callout limits. Salesforce allows 100 callouts per transaction.

How the GuideStar integration works, and how it was tested In the org, an agent enters an EIN on an Account, Apex makes a callout with the subscription key held in a Named Credential, GuideStar returns JSON, and the Account is updated with the official name, address and the charity and tax-exempt statuses. Separately, API responses captured in Postman were reused with HttpCalloutMock in the Apex tests, so the tests never needed the live API and kept running after the trial key expired. IN THE ORG Account agent enters the EIN Apex callout key in a Named Credential GuideStar (Candid) API outside Salesforce JSON back Account updated official name & address · charity status · tax-exempt status HOW IT WAS TESTED Postman real responses Saved JSON good and bad HttpCalloutMock in the Apex tests Tests pass The tests never touch the live API. They kept running after the trial key expired.
What happens at runtime, and the separate path that made the tests survive the trial key.

Working against a trial deadline

Before writing any Apex I tested the API in Postman. I wanted to see exactly what GuideStar sends back for different searches, the good ones and the bad ones. Then I used those real JSON responses with HttpCalloutMock in my Apex tests.

That part saved the project. The tests didn't need the live API, so they kept working after the trial key expired. The client had a tested integration without paying for the API just to build it. Mocks also make it easy to test the unhappy paths: an EIN that doesn't exist, an empty response, an expired key. Those you really don't want to meet for the first time in production.

Stack

Apex · REST API · JSON · legacy Named Credentials · Remote Site Settings · asynchronous Apex · Postman · HttpCalloutMock

Emina Koćić, Salesforce Consultant · Virago. I've worked in Salesforce since 2020 and hold Platform Developer I, Platform Developer II and JavaScript Developer I certifications. I help Ops and RevOps teams with no developer get their Salesforce working again. Based in Tuzla, working with teams in Europe and North America. More about me · LinkedIn · Book a call

Need something connected to Salesforce?

This is the kind of work I do most. If you have a system that should be talking to Salesforce and isn't, tell me what it is.