LangChain을 사용하여 Salesforce CRM과 상호작용하기 위한 도구입니다.

Overview

langchain-salesforce 패키지는 LangChain을 Salesforce CRM과 통합하여, LangChain 애플리케이션에서 데이터를 쿼리하고, 레코드를 관리하며, 객체 스키마를 탐색할 수 있게 해줍니다.

Key Features

  • SOQL Queries: Salesforce Object Query Language (SOQL) 쿼리 실행
  • Object Management: Salesforce 객체에 대한 생성, 읽기, 업데이트, 삭제(CRUD) 작업
  • Schema Exploration: 객체 스키마 설명 및 사용 가능한 객체 목록 조회
  • Async Support: 비동기 작업 지원
  • Error Handling: 상세한 오류 메시지
  • Environment Variable Support: 환경 변수에서 자격 증명 로드

Setup

필요한 종속성을 설치합니다:
 pip install langchain-salesforce

Authentication Setup

이러한 환경 변수는 통합에 의해 자동으로 인식됩니다.

Getting Your Security Token

보안 토큰이 필요한 경우:
  1. Salesforce에 로그인
  2. Settings로 이동
  3. “My Personal Information” 아래의 “Reset My Security Token” 클릭
  4. 새 토큰이 포함된 이메일 확인

Environment Variables (권장)

Salesforce 자격 증명을 환경 변수로 설정합니다:
export SALESFORCE_USERNAME="[email protected]"
export SALESFORCE_PASSWORD="your-password"
export SALESFORCE_SECURITY_TOKEN="your-security-token"
export SALESFORCE_DOMAIN="login"  # Use "test" for sandbox environments

Instantiation

import os

from langchain_salesforce import SalesforceTool

username = os.getenv("SALESFORCE_USERNAME", "your-username")
password = os.getenv("SALESFORCE_PASSWORD", "your-password")
security_token = os.getenv("SALESFORCE_SECURITY_TOKEN", "your-security-token")
domain = os.getenv("SALESFORCE_DOMAIN", "login")

tool = SalesforceTool(
    username=username, password=password, security_token=security_token, domain=domain
)

Invocation

def execute_salesforce_operation(
    operation, object_name=None, query=None, record_data=None, record_id=None
):
    """Executes a given Salesforce operation."""
    request = {"operation": operation}
    if object_name:
        request["object_name"] = object_name
    if query:
        request["query"] = query
    if record_data:
        request["record_data"] = record_data
    if record_id:
        request["record_id"] = record_id
    result = tool.invoke(request)
    return result

Query

이 예제는 Salesforce에서 5개의 연락처를 쿼리합니다.
query_result = execute_salesforce_operation(
    operation="query", query="SELECT Id, Name, Email FROM Contact LIMIT 5"
)

Describe an Object

특정 Salesforce 객체에 대한 메타데이터를 가져옵니다.
describe_result = execute_salesforce_operation(
    operation="describe", object_name="Account"
)

List Available Objects

Salesforce 인스턴스에서 사용 가능한 모든 객체를 검색합니다.
list_objects_result = execute_salesforce_operation(operation="list_objects")

Create a New Contact

Salesforce에 새 연락처 레코드를 생성합니다.
create_result = execute_salesforce_operation(
    operation="create",
    object_name="Contact",
    record_data={"LastName": "Doe", "Email": "[email protected]"},
)

Update a Contact

기존 연락처 레코드를 업데이트합니다.
update_result = execute_salesforce_operation(
    operation="update",
    object_name="Contact",
    record_id="003XXXXXXXXXXXXXXX",
    record_data={"Email": "[email protected]"},
)

Delete a Contact

Salesforce에서 연락처 레코드를 삭제합니다.
delete_result = execute_salesforce_operation(
    operation="delete", object_name="Contact", record_id="003XXXXXXXXXXXXXXX"
)

Chaining

from langchain_anthropic import ChatAnthropic
from langchain.messages import HumanMessage
from langchain_salesforce import SalesforceTool

# Initialize the Salesforce tool
tool = SalesforceTool(
    username=username, password=password, security_token=security_token, domain=domain
)

# Initialize Anthropic LLM
llm = ChatAnthropic(model="claude-sonnet-4-20250514")

# First, let's query some contacts to get real data
contacts_query = {
    "operation": "query",
    "query": "SELECT Id, Name, Email, Phone FROM Contact LIMIT 3",
}

contacts_result = tool.invoke(contacts_query)

# Now let's use the LLM to analyze and summarize the contact data
if contacts_result and "records" in contacts_result:
    contact_data = contacts_result["records"]

    # Create a message asking the LLM to analyze the contact data
    analysis_prompt = f"""
    Please analyze the following Salesforce contact data and provide insights:

    Contact Data: {contact_data}

    Please provide:
    1. A summary of the contacts
    2. Any patterns you notice
    3. Suggestions for data quality improvements
    """

    message = HumanMessage(content=analysis_prompt)
    analysis_result = llm.invoke([message])

    print("\nLLM Analysis:")
    print(analysis_result.content)

API reference

포괄적인 문서 및 API 참조는 다음을 참조하세요:

Additional Resources


Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I