For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • SDKs
    • SDK concepts
    • SDK features
    • Client-side SDKs
    • Server-side SDKs
      • .NET SDK reference
      • Apex SDK reference
      • C++ SDK reference
      • Erlang SDK reference
      • Go SDK reference
      • Haskell SDK reference
      • Java SDK reference
      • Lua SDK reference
      • Node.js SDK reference
      • PHP SDK reference
      • Python SDK reference
      • Ruby SDK reference
      • Rust SDK reference
    • AI SDKs
    • Edge SDKs
    • OpenFeature providers
    • Observability SDKs
    • Relay Proxy
Sign inTry it free
LogoLogo
On this page
  • Overview
  • Get started
  • Deploy the SDK to Salesforce
  • Initialize the client
  • Evaluate a user
  • Use the LaunchDarkly Salesforce bridge
  • Install the bridge
  • Supported features
SDKsServer-side SDKs

Apex SDK reference

Was this page helpful?
Previous

C++ SDK reference (server-side)

Next
Built with

Overview

This topic documents how to get started with the Apex SDK, and links to reference information on all of the supported features.

SDK quick links

LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and a sample application:

ResourceLocation
SDK API documentationSDK API docs
Supported SDK VersionsApex server SDK
GitHub repositoryapex-server-sdk
Sample applicationApex
Published moduleNone

Get started

After you complete the Get started process, follow these instructions to start using the LaunchDarkly SDK in your Salesforce Apex application.

Deploy the SDK to Salesforce

The first step is deploying the SDK to Salesforce:

Console
$git clone https://github.com/launchdarkly/apex-server-sdk.git
$cd apex-server-sdk
$sfdx force:source:deploy --targetusername='YOUR TARGET ORG' --sourcepath='force-app'

Initialize the client

Initialize the client as follows:

1LDClient client = new LDClient();

To learn more about the specific configuration options available for this SDK, read LDConfig.Builder.

Evaluate a user

You can use the Variation methods available from the client to check which variation a particular user will receive for a given feature flag.

Here’s how:

Apex
1LDUser user = new LDUser.Builder('example-user-key')
2 .setName('Sandy')
3 .build();
4
5Boolean value = client.boolVariation(user, flagKey, false);
6if (value) {
7 // Application code to show the feature
8} else {
9 // The code to run if the feature is off
10}

After the SDK is deployed to Salesforce, start the bridge to begin evaluating flags. The bridge must be running in order to receive flag updates and publish events to LaunchDarkly.

Use the LaunchDarkly Salesforce bridge

The Apex server-side SDK is architected differently than our other SDKs. In most of our SDKs, the SDK downloads feature configurations and sends events by itself. The Apex SDK instead uses an external bridging application to connect LaunchDarkly and Salesforce.

Because the SDK uses a bridge to handle state management, there is no initialization delay required to download flags. Additionally, the lack of state inside the SDK means that initializing multiple instances of the SDK is not problematic.

The Apex SDK exposes two HTTP endpoints that the bridge uses: /store and /event. The bridge pushes flag updates to Salesforce through one endpoint, and pulls events from Salesforce with the other.

Install the bridge

The bridge is designed to be run as a daemon on your server infrastructure, either with a cloud provider or your own on-premise infrastructure.

The bridge is a Go application configured with environment variables. To build the bridge from source install Go 1.14 or higher. To install Go, read Go’s documentation.

The bridge needs authorization for both LaunchDarkly and Salesforce.

The Apex SDK uses an SDK key

The Apex SDK uses an SDK key. Keys are specific to each project and environment. They are available on the SDK keys page under Settings. To learn more about key types, read Keys.

Build and run the bridge like this:

Console
$cd bridge && go build .
$
$export LD_SDK_KEY='an active LaunchDarkly SDK key'
$export SALESFORCE_URL='Your Salesforce Apex REST URL'
$export OAUTH_ID='Your Salesforce OAuth Id'
$export OAUTH_SECRET='Your Salesforce OAuth secret'
$export OAUTH_USERNAME='Your Salesforce username'
$export OAUTH_PASSWORD='Your Salesforce password + security token'
$
$./bridge

The logs indicate if the bridge is running. If it fails, the logs show the errors that occurred.

To learn more about possible bridge errors and how to remediate them, read the following troubleshooting articles:

  • Error “invalid_client_id” Apex SDK
  • Error “invalid_client” Apex SDK
  • Error “invalid_grant” Apex SDK

You must deploy the SDK to Salesforce before you run the bridge. After the SDK is deployed to Salesforce, start the bridge to begin evaluating flags. The bridge must be running in order to receive flag updates and publish events to LaunchDarkly.

Supported features

This SDK supports the following features:

  • Aliasing users
  • Anonymous contexts and users
  • Configuration, including
    • Service endpoint configuration
  • Context configuration
  • Evaluating flags
  • Flag evaluation reasons
  • Getting all flags
  • Identifying and changing contexts
  • Private attributes
  • Sending custom events
  • Web proxy configuration