We've built a simple application that demonstrates how LaunchDarkly's SDK works.
Below, you'll find the basic build procedure, but for more comprehensive instructions, you can visit the Apex SDK reference guide.
This guide requires you to install the Salesforce CLI and the Go compiler, version 1.26 or newer, which the bridge requires to build.
- Clone the Apex SDK.
git clone https://github.com/launchdarkly/apex-server-sdk.git- Deploy the SDK to Salesforce.
cd apex-server-sdk
sf project deploy start --target-org 'YOUR TARGET ORG' --source-dir 'force-app'- Build the Salesforce LaunchDarkly bridge.
cd apex-server-sdk/bridge
go build .- Set the environment variable
LD_SDK_KEYto your LaunchDarkly SDK key. Set environment variables for your Salesforce account. This example uses the client credentials flow, which needs no user credential; enable Enable Client Credentials Flow on the connected app or External Client App in Salesforce first. See the bridge configuration reference for all supported options, including JWT authentication.
SALESFORCE_URLmust name the org's My Domain host (https://MyDomainName.my.salesforce.com/services/apexrest/), not the Lightning host from your browser's address bar. The bridge derives the OAuth token endpoint from it whenOAUTH_URIis unset.- The client credentials flow is not accepted on
login.salesforce.comortest.salesforce.com, so leaveOAUTH_URIunset for both production and sandbox orgs.
- Start the Salesforce bridge.
cd apex-server-sdk/bridge
export LD_SDK_KEY='Your LaunchDarkly SDK key'
export SALESFORCE_URL='Your Salesforce Apex REST URL'
export OAUTH_GRANT_TYPE='client-credentials'
export OAUTH_ID='Your Salesforce OAuth Id'
export OAUTH_SECRET='Your Salesforce OAuth secret'
./bridge- If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, edit
hello.apexand set the value offlagKeyto the flag key.
String flagKey = 'my-boolean-flag';- Use the SDK with
hello.apex
sf apex run --target-org 'YOUR TARGET ORG' --file 'hello.apex'