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.

// settings.gradle.kts
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://jitpack.io") }
        maven { url = uri("https://opensource.salesforce.com/AgentforceMobileSDK-Android/agentforce-sdk-repository") }
        maven { url = uri("https://s3.amazonaws.com/inapp.salesforce.com/public/android") }
        maven { url = uri("https://s3.amazonaws.com/salesforce-async-messaging-experimental/public/android") }
    }
}

// build.gradle.kts
plugins {
   id("com.android.application")
   id("kotlin-android")
   id("kotlin-kapt")
   id("kotlinx-serialization")
   id("org.jetbrains.kotlin.plugin.compose")
}

// app/build.gradle.kts
android {
    compileOptions {
        isCoreLibraryDesugaringEnabled = true
    }
}

dependencies {
    // Agentforce SDK Dependencies
    api("com.salesforce.android.agentforcesdk:agentforce-sdk:14.97.1")

    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
}

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.

import com.salesforce.android.agentforceservice.*

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

class MyAppCredentialProvider : AgentforceAuthCredentialProvider {
   override fun getAuthCredentials(): AgentforceAuthCredentials {
       return AgentforceAuthCredentials.OAuth(
           authToken = "YOUR_AUTH_TOKEN",
           orgId = "YOUR_ORG_ID",
           userId = "YOUR_USER_ID"
       )
   }
}
class MyAppCredentialProvider : AgentforceAuthCredentialProvider {
   override fun getAuthCredentials(): AgentforceAuthCredentials {
       return AgentforceAuthCredentials.OrgJWT(orgJWT = "YOUR_ORG_JWT")
   }
}
class MyAppCredentialProvider : AgentforceAuthCredentialProvider {
   override fun getAuthCredentials(): AgentforceAuthCredentials {
       return AgentforceAuthCredentials.Guest(url = "YOUR_GUEST_URL")
   }
}

To learn more, see Integrate Agentforce SDK.

4. Configure Chat

Configure your chat object for Employee agent or Service agent.

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

// Configure an Employee agent
val configuration = AgentforceConfiguration.builder(
    authCredentialProvider = myAuthCredentialProvider
)
    .setApplication(application)
    .setSalesforceDomain("https://your-domain.my.salesforce.com")
    .setAgentId("YOUR_AGENT_ID")
    .setThemeManager(createCustomAgentforceThemeManager(themeMode = AgentforceThemeMode.SYSTEM))
    .setNetwork(myNetworkProvider)
    .setLogger(myLogger)
    .setNavigation(myNavigation)
    .build()

// Set mode for Employee agent
val agentforceMode = AgentforceMode.FullConfig(configuration)

// Create client
agentforceClient?.init(
    authCredentialProvider = configuration.authCredentialProvider,
    agentforceMode = agentforceMode,
    application = application
)
// Configure a Service agent
val serviceAgentConfig = ServiceAgentConfiguration.builder(
    serviceApiURL = "https://your-service-api-url.com",
    organizationId = "YOUR_ORG_ID",
    esDeveloperName = "YOUR_CHAT_DEVELOPER_NAME",
    authorizationContext = AuthorizationContext(
        authorizationMethod = AuthorizationMethod.UNVERIFIED
    )
).build()

val agentforceMode = AgentforceMode.ServiceAgent(
    serviceAgentConfiguration = serviceAgentConfig,
    agentforceConfiguration = configuration
)

// Create client
agentforceClient?.init(
    authCredentialProvider = configuration.authCredentialProvider,
    agentforceMode = agentforceMode,
    application = application
)

To learn more, see Integrate Agentforce SDK.

5. Start and Present Chat

Start the chat conversation.

// Start conversation
val conversation = agentforceClient.startAgentforceConversation()

And add the UI component.

@Composable
fun MyChatScreen(
    agentforceClient: AgentforceClient,
    conversation: AgentforceConversation,
    onClose: () -> Unit
) {
    agentforceClient.AgentforceConversationContainer(
        conversation = conversation,
        onClose = onClose
    )
}

To learn more, see Integrate Agentforce SDK.

Next Steps