Android Quick Start Guide

Get up and running quickly with the Agentforce Mobile SDK for Android using these instructions.

Before You Begin 

Ensure you have:

  • A Salesforce org with Agentforce enabled
  • An agent configured in your org (Employee Agent or Service Agent)
  • The required values from your Salesforce org depending on agent type

For detailed setup instructions, see Before You Begin.

For Service Agent 

You need these values from your Salesforce org:

  • Service API URL: Setup > Embedded Service Deployments > your deployment > Settings
  • Organization ID: Setup > Company Information
  • ES Developer Name: Setup > Embedded Service Deployments > Developer Name

For Employee Agent 

You need these values from your Salesforce org:

  • Agent ID: From the Agent Details page URL (the 18-character ID at the end)
  • User ID: From the user profile. See Find the Salesforce ID for a User.
  • Salesforce Domain: Setup > My Domain > Current My Domain URL

1. Add Dependencies 

Add the Agentforce SDK to your project.

Add Dependencies
1// settings.gradle.kts
2dependencyResolutionManagement {
3    repositories {
4        google()
5        mavenCentral()
6        maven { url = uri("https://jitpack.io") }
7        maven { url = uri("https://opensource.salesforce.com/AgentforceMobileSDK-Android/agentforce-sdk-repository") }
8        maven { url = uri("https://s3.amazonaws.com/inapp.salesforce.com/public/android") }
9        maven { url = uri("https://s3.amazonaws.com/salesforce-async-messaging-experimental/public/android") }
10    }
11}
12
13// build.gradle.kts
14plugins {
15   id("com.android.application")
16   id("kotlin-android")
17   id("kotlin-kapt")
18   id("kotlinx-serialization")
19   id("org.jetbrains.kotlin.plugin.compose")
20}
21
22// app/build.gradle.kts
23android {
24    compileOptions {
25        isCoreLibraryDesugaringEnabled = true
26    }
27}
28
29dependencies {
30    // Agentforce SDK Dependencies
31    api("com.salesforce.android.agentforcesdk:agentforce-sdk:14.97.1")
32
33    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
34    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
35}

To learn more, see Install the Android SDK.

2. Add Required Permissions 

See Android Requirements.

3. Implement Credential Provider 

To use the SDK, be sure to import the Agentforce SDK packages.

Agentforce SDK Import
1import com.salesforce.android.agentforceservice.*

Create a credential provider using one of the supported authentication methods.

Sample OAuth Implementation
1class MyAppCredentialProvider : AgentforceAuthCredentialProvider {
2   override fun getAuthCredentials(): AgentforceAuthCredentials {
3       return AgentforceAuthCredentials.OAuth(
4           authToken = "YOUR_AUTH_TOKEN",
5           orgId = "YOUR_ORG_ID",
6           userId = "YOUR_USER_ID"
7       )
8   }
9}
Sample OrgJWT Implementation
1class MyAppCredentialProvider : AgentforceAuthCredentialProvider {
2   override fun getAuthCredentials(): AgentforceAuthCredentials {
3       return AgentforceAuthCredentials.OrgJWT(orgJWT = "YOUR_ORG_JWT")
4   }
5}
Sample Guest User Implementation
1class MyAppCredentialProvider : AgentforceAuthCredentialProvider {
2   override fun getAuthCredentials(): AgentforceAuthCredentials {
3       return AgentforceAuthCredentials.Guest(url = "YOUR_GUEST_URL")
4   }
5}

To learn more, see Integrate Agentforce SDK.

4. Configure Chat 

Configure your chat object for Employee agent or Service agent.

For guidance on gathering information for the agent configuration object, see Agent Type Setup in Before You Begin.

Tip

Employee Agent Configuration
1// Configure an Employee agent
2val configuration = AgentforceConfiguration.builder(
3    authCredentialProvider = myAuthCredentialProvider
4)
5    .setApplication(application)
6    .setSalesforceDomain("https://your-domain.my.salesforce.com")
7    .setAgentId("YOUR_AGENT_ID")
8    .setThemeManager(createCustomAgentforceThemeManager(themeMode = AgentforceThemeMode.SYSTEM))
9    .setNetwork(myNetworkProvider)
10    .setLogger(myLogger)
11    .setNavigation(myNavigation)
12    .build()
13
14// Set mode for Employee agent
15val agentforceMode = AgentforceMode.FullConfig(configuration)
16
17// Create client
18agentforceClient?.init(
19    authCredentialProvider = configuration.authCredentialProvider,
20    agentforceMode = agentforceMode,
21    application = application
22)
Service Agent Configuration
1// Configure a Service agent
2val serviceAgentConfig = ServiceAgentConfiguration.builder(
3    serviceApiURL = "https://your-service-api-url.com",
4    organizationId = "YOUR_ORG_ID",
5    esDeveloperName = "YOUR_CHAT_DEVELOPER_NAME",
6    authorizationContext = AuthorizationContext(
7        authorizationMethod = AuthorizationMethod.UNVERIFIED
8    )
9).build()
10
11val agentforceMode = AgentforceMode.ServiceAgent(
12    serviceAgentConfiguration = serviceAgentConfig,
13    agentforceConfiguration = configuration
14)
15
16// Create client
17agentforceClient?.init(
18    authCredentialProvider = configuration.authCredentialProvider,
19    agentforceMode = agentforceMode,
20    application = application
21)

To learn more, see Integrate Agentforce SDK.

5. Start and Present Chat 

Start the chat conversation.

Start Chat
1// Start conversation
2val conversation = agentforceClient.startAgentforceConversation()

And add the UI component.

Add UI Component
1@Composable
2fun MyChatScreen(
3    agentforceClient: AgentforceClient,
4    conversation: AgentforceConversation,
5    onClose: () -> Unit
6) {
7    agentforceClient.AgentforceConversationContainer(
8        conversation = conversation,
9        onClose = onClose
10    )
11}

To learn more, see Integrate Agentforce SDK.

Next Steps