=============== LIBRARY RULES =============== From library maintainers: - Do not infer product behavior beyond what is stated in the markdown. - Preserve product terminology as written in the source markdown. # Salesforce Documentation Context Salesforce Documentation Context is a comprehensive documentation repository that converts official Salesforce PDF documentation into LLM-friendly Markdown format. The project provides Context7 MCP integration, enabling AI assistants to query up-to-date Salesforce documentation including Apex development, SOQL/SOSL queries, CLI commands, Metadata API, Salesforce DX, and Lightning components. All documentation is sourced directly from Salesforce's official resources and converted for optimal context retrieval. The repository serves as a documentation bridge between Salesforce's official PDFs and modern AI-powered development workflows. By maintaining converted Markdown versions of key Salesforce developer guides, it allows developers to leverage LLM assistants that can accurately reference current Salesforce platform capabilities, syntax, limits, and best practices without relying on potentially outdated training data. ## Context7 MCP Integration - Query Salesforce Documentation The primary interface for accessing this documentation is through Context7's MCP (Model Context Protocol) server. This allows AI assistants to query the documentation library directly using a fixed library ID. ```json // Query Salesforce documentation via Context7 MCP // Tool: mcp__context7__query-docs { "libraryId": "/damecek/salesforce-documentation-context", "query": "How do I write a trigger in Apex? Provide steps and a minimal code example." } // Example queries for different documentation areas: // Apex Development { "libraryId": "/damecek/salesforce-documentation-context", "query": "What are the governor limits for SOQL queries in Apex?" } // SOQL Syntax { "libraryId": "/damecek/salesforce-documentation-context", "query": "Show syntax for SOQL relationship queries with parent-child records." } // Salesforce CLI Commands { "libraryId": "/damecek/salesforce-documentation-context", "query": "How do I create and authorize a scratch org using sf CLI?" } // Metadata API { "libraryId": "/damecek/salesforce-documentation-context", "query": "How do I deploy metadata using REST API? Show package.xml example." } ``` ## Apex Development Guide - Writing Server-Side Logic The Apex Developer Guide provides comprehensive coverage of Salesforce's strongly typed, object-oriented programming language for server-side business logic, triggers, and custom controllers. ```apex // Basic Apex Class with DML Operations public class AccountManager { // Insert new accounts with error handling public static List createAccounts(List accountNames) { List newAccounts = new List(); for (String name : accountNames) { newAccounts.add(new Account(Name = name)); } try { insert newAccounts; } catch (DmlException e) { System.debug('Error inserting accounts: ' + e.getMessage()); throw e; } return newAccounts; } // Query accounts with SOQL public static List getAccountsWithContacts(String industry) { return [ SELECT Id, Name, Industry, (SELECT Id, FirstName, LastName, Email FROM Contacts) FROM Account WHERE Industry = :industry LIMIT 100 ]; } } // Apex Trigger Example trigger AccountTrigger on Account (before insert, before update, after insert) { if (Trigger.isBefore) { if (Trigger.isInsert || Trigger.isUpdate) { for (Account acc : Trigger.new) { // Auto-populate field before save if (String.isBlank(acc.Description)) { acc.Description = 'Created via trigger on ' + System.now(); } } } } if (Trigger.isAfter && Trigger.isInsert) { // Call async process after insert AccountManager.processNewAccounts(Trigger.newMap.keySet()); } } ``` ## SOQL and SOSL Reference - Querying Salesforce Data SOQL (Salesforce Object Query Language) retrieves records from single or related objects, while SOSL (Salesforce Object Search Language) performs text-based searches across multiple objects. ```apex // Basic SOQL Query with filtering and ordering List contacts = [ SELECT Id, FirstName, LastName, Email, Account.Name FROM Contact WHERE Email != null AND CreatedDate = LAST_N_DAYS:30 ORDER BY LastName ASC LIMIT 50 ]; // Aggregate Functions AggregateResult[] results = [ SELECT Industry, COUNT(Id) cnt, SUM(AnnualRevenue) totalRevenue FROM Account WHERE Industry != null GROUP BY Industry HAVING COUNT(Id) > 5 ORDER BY COUNT(Id) DESC ]; for (AggregateResult ar : results) { System.debug('Industry: ' + ar.get('Industry') + ', Count: ' + ar.get('cnt') + ', Revenue: ' + ar.get('totalRevenue')); } // Parent-to-Child Relationship Query (nested) List accountsWithContacts = [ SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts WHERE IsActive__c = true) FROM Account WHERE Industry = 'Technology' ]; // Child-to-Parent Relationship Query (dot notation) List contactsWithAccount = [ SELECT Id, FirstName, LastName, Account.Name, Account.Industry, Account.Owner.Name FROM Contact WHERE Account.Industry = 'Healthcare' ]; // SOSL Search across multiple objects List> searchResults = [ FIND 'Acme*' IN ALL FIELDS RETURNING Account(Id, Name, Industry), Contact(Id, FirstName, LastName, Email), Lead(Id, Name, Company) LIMIT 20 ]; List accounts = (List)searchResults[0]; List foundContacts = (List)searchResults[1]; List leads = (List)searchResults[2]; ``` ## Salesforce CLI Command Reference - sf Commands The Salesforce CLI (`sf`) provides commands for managing DX projects, scratch orgs, sandboxes, deployments, and package development. ```bash # Authenticate and authorize orgs sf org login web --alias myDevHub --set-default-dev-hub sf org login web --alias mySandbox --instance-url https://test.salesforce.com # Create a scratch org from definition file sf org create scratch \ --definition-file config/project-scratch-def.json \ --alias MyScratchOrg \ --duration-days 7 \ --set-default # Deploy source to an org sf project deploy start \ --source-dir force-app \ --target-org MyScratchOrg \ --wait 10 # Deploy with specific metadata sf project deploy start \ --metadata ApexClass:AccountManager \ --metadata ApexTrigger:AccountTrigger \ --target-org MyScratchOrg # Retrieve source from org sf project retrieve start \ --target-org MyScratchOrg \ --metadata CustomObject:Account # Run Apex tests sf apex run test \ --target-org MyScratchOrg \ --code-coverage \ --result-format human \ --wait 10 # Execute anonymous Apex sf apex run \ --target-org MyScratchOrg \ --file scripts/anonymous.apex # Query data with SOQL sf data query \ --query "SELECT Id, Name FROM Account LIMIT 10" \ --target-org MyScratchOrg \ --result-format table # Create and install packages sf package create \ --name "MyPackage" \ --package-type Unlocked \ --path force-app sf package version create \ --package MyPackage \ --installation-key-bypass \ --wait 10 sf package install \ --package 04t... \ --target-org TargetOrg \ --wait 10 ``` ## Metadata API - Deploy and Retrieve Configurations The Metadata API enables programmatic deployment and retrieval of Salesforce metadata components using file-based or CRUD-based operations. ```xml AccountManager ContactService ApexClass AccountTrigger ApexTrigger Account Contact CustomObject * CustomField 66.0 ``` ```bash # Deploy metadata using REST API with curl # Step 1: Create deployment zip file containing package.xml and components # Step 2: Deploy using REST endpoint curl -X POST \ "https://yourinstance.salesforce.com/services/data/v66.0/metadata/deployRequest" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -H "Content-Type: application/zip" \ --data-binary @deploy.zip # Step 3: Check deployment status curl -X GET \ "https://yourinstance.salesforce.com/services/data/v66.0/metadata/deployRequest/0Af..." \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" ``` ```apex // CRUD-based metadata operations in Apex // Create custom metadata record Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata(); customMetadata.fullName = 'MyConfig__mdt.DefaultSettings'; customMetadata.label = 'Default Settings'; Metadata.CustomMetadataValue configValue = new Metadata.CustomMetadataValue(); configValue.field = 'API_Endpoint__c'; configValue.value = 'https://api.example.com'; customMetadata.values.add(configValue); Metadata.DeployContainer container = new Metadata.DeployContainer(); container.addMetadata(customMetadata); // Deploy asynchronously Id deployJobId = Metadata.Operations.enqueueDeployment(container, null); ``` ## Salesforce DX Developer Guide - Modern Development Workflow Salesforce DX provides source-driven development with scratch orgs, version control integration, and continuous integration/deployment capabilities. ```json // sfdx-project.json - Project configuration { "packageDirectories": [ { "path": "force-app", "default": true, "package": "MyPackage", "versionName": "ver 1.0", "versionNumber": "1.0.0.NEXT" }, { "path": "unpackaged" } ], "namespace": "", "sfdcLoginUrl": "https://login.salesforce.com", "sourceApiVersion": "66.0" } ``` ```json // config/project-scratch-def.json - Scratch org definition { "orgName": "My Scratch Org", "edition": "Developer", "features": [ "EnableSetPasswordInApi", "Communities", "ServiceCloud" ], "settings": { "lightningExperienceSettings": { "enableS1DesktopEnabled": true }, "securitySettings": { "passwordPolicies": { "enableSetPasswordInApi": true } }, "omniChannelSettings": { "enableOmniChannel": true } } } ``` ```bash # Complete DX workflow example # 1. Create new project sf project generate --name my-sfdx-project # 2. Authorize Dev Hub sf org login web --set-default-dev-hub --alias DevHub # 3. Create scratch org sf org create scratch \ --definition-file config/project-scratch-def.json \ --alias scratch1 \ --set-default \ --duration-days 30 # 4. Push source to scratch org sf project deploy start --source-dir force-app # 5. Open scratch org sf org open --target-org scratch1 # 6. Pull changes from org sf project retrieve start # 7. Run tests sf apex run test --code-coverage --result-format human # 8. Create package version sf package version create \ --package MyPackage \ --installation-key test1234 \ --wait 20 \ --code-coverage # 9. Deploy to sandbox/production sf project deploy start \ --source-dir force-app \ --target-org ProductionOrg \ --test-level RunLocalTests ``` ## Lightning Aura Components Developer Guide Lightning Aura Components provide a component-based framework for building dynamic web apps on Salesforce. ```html
{!v.errorMessage}
Industry:
{!acc.Industry}
``` ```javascript // myComponentController.js - Client-side controller ({ doInit: function(component, event, helper) { component.set("v.isLoading", true); var action = component.get("c.getAccounts"); action.setParams({ "industry": "Technology" }); action.setCallback(this, function(response) { component.set("v.isLoading", false); var state = response.getState(); if (state === "SUCCESS") { component.set("v.accounts", response.getReturnValue()); } else if (state === "ERROR") { var errors = response.getError(); var message = errors[0] ? errors[0].message : "Unknown error"; component.set("v.errorMessage", message); } }); $A.enqueueAction(action); }, handleRefresh: function(component, event, helper) { helper.refreshData(component); } }) ``` ## Querying Documentation with Context7 The recommended workflow pattern for using this documentation library involves querying Context7 MCP to verify uncertain details, fetch current syntax, or get accurate code examples. ```json // Verification query pattern { "libraryId": "/damecek/salesforce-documentation-context", "query": "Verify whether SOQL supports OFFSET clause. If true, show syntax and limitations." } // Example-focused query pattern { "libraryId": "/damecek/salesforce-documentation-context", "query": "Show a minimal, correct example for bulk DML operations in Apex. Include error handling." } // Best practices query pattern { "libraryId": "/damecek/salesforce-documentation-context", "query": "What are the best practices for avoiding governor limits in Apex triggers?" } // Troubleshooting query pattern { "libraryId": "/damecek/salesforce-documentation-context", "query": "What causes MIXED_DML_OPERATION error and how do I resolve it?" } ``` ## Summary This documentation repository serves Salesforce developers who need accurate, current reference material for Apex development, SOQL/SOSL queries, CLI operations, metadata management, and component development. The Context7 MCP integration enables AI assistants to provide precise answers about Salesforce platform capabilities without relying on potentially outdated information, making it ideal for development workflows, code reviews, and learning scenarios. The primary use cases include verifying Apex syntax and patterns, looking up CLI command flags and options, understanding API limits and best practices, and generating correct code examples. Integration is straightforward through the Context7 MCP tool with the fixed library ID `/damecek/salesforce-documentation-context`, allowing developers to query any aspect of Salesforce development covered by the official documentation guides.