Skip to content

The agent engineering platform.

docs: add notebook for langchain-salesforce package (#29800)

Cole McIntosh6874c9c1d08c
diff --git a/docs/docs/integrations/providers/salesforce.mdx b/docs/docs/integrations/providers/salesforce.mdx
new file mode 100644
index 0000000000..ea27f204f7
--- /dev/null
+++ b/docs/docs/integrations/providers/salesforce.mdx
@@ -0,0 +1,19 @@
+# Salesforce
+
+[Salesforce](https://www.salesforce.com/) is a cloud-based software company that
+provides customer relationship management (CRM) solutions and a suite of enterprise
+applications focused on sales, customer service, marketing automation, and analytics.
+
+[langchain-salesforce](https://pypi.org/project/langchain-salesforce/) implements
+tools enabling LLMs to interact with Salesforce data.
+
+
+## Installation and Setup
+
+```bash
+pip install langchain-salesforce
+```
+
+## Tools
+
+See detail on available tools [here](/docs/integrations/tools/salesforce/).
diff --git a/docs/docs/integrations/tools/salesforce.ipynb b/docs/docs/integrations/tools/salesforce.ipynb
new file mode 100644
index 0000000000..52a4b5deea
--- /dev/null
+++ b/docs/docs/integrations/tools/salesforce.ipynb
@@ -0,0 +1,300 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "563f3174",
+ "metadata": {},
+ "source": [
+ "# Salesforce\n",
+ "\n",
+ "Tools for interacting with Salesforce.\n",
+ "\n",
+ "## Overview\n",
+ "\n",
+ "This notebook provides examples of interacting with Salesforce using LangChain.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Setup\n",
+ "\n",
+ "1. Install the required dependencies:\n",
+ "```bash\n",
+ " pip install langchain-salesforce\n",
+ "```\n",
+ "\n",
+ "2. Set up your Salesforce credentials as environment variables:\n",
+ "\n",
+ "```bash\n",
+ " export SALESFORCE_USERNAME=\"your-username\"\n",
+ " export SALESFORCE_PASSWORD=\"your-password\" \n",
+ " export SALESFORCE_SECURITY_TOKEN=\"your-security-token\"\n",
+ " export SALESFORCE_DOMAIN=\"test\" # Use 'test' for sandbox, remove for production\n",
+ "```\n",
+ "\n",
+ "These environment variables will be automatically picked up by the integration.\n",
+ "\n",
+ "## Getting Your Security Token\n",
+ "If you need a security token:\n",
+ "1. Log into Salesforce\n",
+ "2. Go to Settings\n",
+ "3. Click on \"Reset My Security Token\" under \"My Personal Information\"\n",
+ "4. Check your email for the new token"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "dd32d0d8",
+ "metadata": {},
+ "source": [
+ "## Instantiation"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "117ecaf8",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "\n",
+ "from langchain_salesforce import SalesforceTool\n",
+ "\n",
+ "username = os.getenv(\"SALESFORCE_USERNAME\", \"your-username\")\n",
+ "password = os.getenv(\"SALESFORCE_PASSWORD\", \"your-password\")\n",
+ "security_token = os.getenv(\"SALESFORCE_SECURITY_TOKEN\", \"your-security-token\")\n",
+ "domain = os.getenv(\"SALESFORCE_DOMAIN\", \"login\")\n",
+ "\n",
+ "tool = SalesforceTool(\n",
+ " username=username, password=password, security_token=security_token, domain=domain\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "28c1a13e",
+ "metadata": {},
+ "source": [
+ "## Invocation"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e75623af",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def execute_salesforce_operation(\n",
+ " operation, object_name=None, query=None, record_data=None, record_id=None\n",
+ "):\n",
+ " \"\"\"Executes a given Salesforce operation.\"\"\"\n",
+ " request = {\"operation\": operation}\n",
+ " if object_name:\n",
+ " request[\"object_name\"] = object_name\n",
+ " if query:\n",
+ " request[\"query\"] = query\n",
+ " if record_data:\n",
+ " request[\"record_data\"] = record_data\n",
+ " if record_id:\n",
+ " request[\"record_id\"] = record_id\n",
+ " result = tool.run(request)\n",
+ " return result"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d761883a",
+ "metadata": {},
+ "source": [
+ "## Query\n",
+ "This example queries Salesforce for 5 contacts."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "5fb2e42b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "query_result = execute_salesforce_operation(\n",
+ " \"query\", query=\"SELECT Id, Name, Email FROM Contact LIMIT 5\"\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b917c89e",
+ "metadata": {},
+ "source": [
+ "## Describe an Object\n",
+ "Fetches metadata for a specific Salesforce object."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ef6ca50c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "describe_result = execute_salesforce_operation(\"describe\", object_name=\"Account\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "40ed4656",
+ "metadata": {},
+ "source": [
+ "## List Available Objects\n",
+ "Retrieves all objects available in the Salesforce instance."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a7114bbc",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "list_objects_result = execute_salesforce_operation(\"list_objects\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "6619fe12",
+ "metadata": {},
+ "source": [
+ "## Create a New Contact\n",
+ "Creates a new contact record in Salesforce."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1e15980d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "create_result = execute_salesforce_operation(\n",
+ " \"create\",\n",
+ " object_name=\"Contact\",\n",
+ " record_data={\"LastName\": \"Doe\", \"Email\": \"[email protected]\"},\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f8801882",
+ "metadata": {},
+ "source": [
+ "## Update a Contact\n",
+ "Updates an existing contact record."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2f4bd54c",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "update_result = execute_salesforce_operation(\n",
+ " \"update\",\n",
+ " object_name=\"Contact\",\n",
+ " record_id=\"003XXXXXXXXXXXXXXX\",\n",
+ " record_data={\"Email\": \"[email protected]\"},\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "46dd7178",
+ "metadata": {},
+ "source": [
+ "## Delete a Contact\n",
+ "Deletes a contact record from Salesforce."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "31830f80",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "delete_result = execute_salesforce_operation(\n",
+ " \"delete\", object_name=\"Contact\", record_id=\"003XXXXXXXXXXXXXXX\"\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "7f094544",
+ "metadata": {},
+ "source": [
+ "## Chaining"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0e997f71",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from langchain.prompts import PromptTemplate\n",
+ "from langchain_openai import ChatOpenAI\n",
+ "from langchain_salesforce import SalesforceTool\n",
+ "\n",
+ "tool = SalesforceTool(\n",
+ " username=username, password=password, security_token=security_token, domain=domain\n",
+ ")\n",
+ "\n",
+ "llm = ChatOpenAI(model=\"gpt-4o-mini\")\n",
+ "\n",
+ "prompt = PromptTemplate.from_template(\n",
+ " \"What is the name of the contact with the id {contact_id}?\"\n",
+ ")\n",
+ "\n",
+ "chain = prompt | tool.invoke | llm\n",
+ "\n",
+ "result = chain.invoke({\"contact_id\": \"003XXXXXXXXXXXXXXX\"})"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b8467ae7",
+ "metadata": {},
+ "source": [
+ "## API reference\n",
+ "[langchain-salesforce README](https://github.com/colesmcintosh/langchain-salesforce/blob/main/README.md)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": ".venv",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.13.2"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/libs/packages.yml b/libs/packages.yml
index 469eea889e..b0d7d00391 100644
--- a/libs/packages.yml
+++ b/libs/packages.yml
@@ -429,6 +429,11 @@ packages:
repo: langchain-ai/langchain
downloads: 9521
downloads_updated_at: '2025-02-13T23:35:48.490391+00:00'
+- name: langchain-salesforce
+ path: .
+ repo: colesmcintosh/langchain-salesforce
+ downloads: 0
+ downloads_updated_at: '2025-02-13T23:35:48.490391+00:00'
- name: langchain-discord-shikenso
path: .
repo: Shikenso-Analytics/langchain-discord