The langchain-salesforce package integrates LangChain with Salesforce CRM,
allowing you to query data, manage records, and explore object schemas
from LangChain applications.
from langchain_anthropic import ChatAnthropicfrom langchain_core.messages import HumanMessagefrom langchain_salesforce import SalesforceTool# Initialize the Salesforce tooltool = SalesforceTool( username=username, password=password, security_token=security_token, domain=domain)# Initialize Anthropic LLMllm = ChatAnthropic(model="claude-sonnet-4-20250514")# First, let's query some contacts to get real datacontacts_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 dataif 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)