Platform Salesforce Connect Adapter Generate 标志

Platform Salesforce Connect Adapter Generate

组织热门
forcedotcom
platform-salesforce-connect-adapter-generate

Custom Apex adapter generation for Salesforce Connect — connects any external REST API to Salesforce as live, queryable External Objects without ETL or copying. TRIGGER when: connecting a non-standard external API, writing a DataSource.Provider/Connection or a `.cls`/`.cls-meta.xml` custom adapter class, adding a `.namedCredential-meta.xml` for the adapter's callout, surfacing external data as records, "custom adapter", "ExternalId field", "DataSource namespace", or whether custom Apex fits. DO NOT TRIGGER when: a standard adapter is already configured (OData, Snowflake), for copy/bulk-sync (use platform-data-manage), or for Apex callouts outside Connect (use platform-apex-generate or integration-connectivity-generate).

概览

发布者forcedotcom
代码仓库sf-skills
技能名称platform-salesforce-connect-adapter-generate
星标数
1.1K
复刻数
351
附带文件
2
许可协议Apache-2.0
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 2 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 forcedotcom 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Platform Salesforce Connect Adapter Generate AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/forcedotcom/sf-skills/tree/main/plugins/builder/integration/skills/platform-salesforce-connect-adapter-generate
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/forcedotcom/sf-skills.git /tmp/sf-skills
mkdir -p .claude/skills
cp -r /tmp/sf-skills/plugins/builder/integration/skills/platform-salesforce-connect-adapter-generate .claude/skills/platform-salesforce-connect-adapter-generate
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Platform Salesforce Connect Adapter Generate,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Platform Salesforce Connect Adapter Generate。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Platform Salesforce Connect Adapter Generate 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Salesforce Connect — Custom Apex Adapter

Route the user through building a complete custom Salesforce Connect Apex adapter: two Apex classes, metadata deployment, and registration. Do not guess at the user's API shape — ask before generating.

Scope

In scope: Generating DataSource.Connection and DataSource.Provider Apex classes, Named Credential metadata, deployment via sf CLI, and step-by-step Setup registration guidance for any REST API.

Out of scope: Configuring standard adapters (OData, Snowflake, GraphQL — those have their own flows). Generating the External Data Source metadata file (not deployable via sf CLI — must be registered manually in Setup). Writing Apex that calls external APIs outside the Salesforce Connect framework (use the platform-apex-generate or integration-connectivity-generate skills).

Before starting

Confirm two things. If either is missing, ask before proceeding.

1. Is this actually a Salesforce Connect use case?

The user wants to…Right tool
Query external data live without copying it — read-only or read-write, appears as Salesforce recordsThis skill
Copy or sync data into Salesforce on a schedulethe platform-data-manage skill
Connect to OData, GraphQL, DynamoDB, Athena, or Cross-OrgStandard adapter setup — no Apex needed, different flow
Connect to Snowflake via Salesforce's native Snowflake adapter (direct Snowflake protocol)Built-in Snowflake adapter — no Apex needed
Access Snowflake (or any database) data via a REST or HTTP APIThis skill — Snowflake REST endpoint → custom Apex adapter
Call an external API from Apex or Flow logicthe platform-apex-generate skill or integration-connectivity-generate
Expose Salesforce data to an external systemintegration-connectivity-generate
Receive real-time pushed data or subscribe to external eventsNot Salesforce Connect — Connect is pull-only. Use Platform Events or Change Data Capture instead
Sync or copy data for analytics or bulk processingData Cloud or ETL — Connect is zero-copy virtualization only

If the user has a standard adapter available, tell them — writing a custom adapter when a standard one fits is unnecessary work.

2. Do they have a Salesforce Connect license?

A custom adapter requires a Salesforce Connect license (one license per External Data Source). Without it, the External Data Source menu won't show the Apex option. If the user doesn't have one, tell them before going further.


Default org context (when running locally)

If the user does not specify an org alias, use demo-org. If the user does not specify an SFDX project path, use ~/salesforce-connect-apex-skill/sfconnect-demo/. These are the defaults for local testing — always override if the user specifies their own.


Collect inputs before generating

Never generate code without these. If any are missing, ask:

InputWhy it matters
API name and what it doesNames the classes and sets context for field mapping
Base URLBecomes the Named Credential endpoint
Auth typeDetermines Named Credential setup and getAuthenticationMode()
Key GET endpoint(s) + sample responseDefines the External Object schema — field names, types, nesting
Write support needed?Determines whether to implement upsertRows() and deleteRows()
Org type (DE, scratch, sandbox)Sets apiVersion in .cls-meta.xml

If the user provides an OpenAPI spec, extract:

  • All GET endpoints returning arrays → each becomes a DataSource.Table
  • Response object properties → DataSource.Column entries
  • id / uuid / primary key → map to ExternalId
  • Property types → use the field type mapping table below

What to build

Every custom Salesforce Connect adapter is exactly two Apex classes.

DataSource.Connection

Handles communication with the external API. Exact signatures:

apex
override global DataSource.TableResult query(DataSource.QueryContext context)
override global List<DataSource.TableResult> search(DataSource.SearchContext context)

// Write support — only if API supports it:
global override List<DataSource.UpsertResult> upsertRows(DataSource.UpsertContext context)
global override List<DataSource.DeleteResult> deleteRows(DataSource.DeleteContext context)

Key distinction: query() always operates on one table (QueryContext has a single TableSelection). search() can operate on multiple tables simultaneously (SearchContext has multiple TableSelection instances) — handle each in a loop and return a result per table.

DataSource.Provider

Declares the adapter's capabilities and schema to Salesforce. Required methods:

  • getAuthenticationMode() — return ANONYMOUS for public APIs; NAMED_PRINCIPAL or PER_USER for authenticated APIs
  • getCapabilities() — declare QUERY, SEARCH; add ROW_CREATE, ROW_UPDATE, ROW_DELETE only if implementing writes
  • getConnection(ConnectionParams params) — return new YourConnection(params)
  • sync() — called when the user clicks "Validate and Sync" in Setup; returns List<DataSource.Table> defining the External Object schema and columns

The Provider class appears in Salesforce Setup as Custom-[ClassName] under the External Data Source type dropdown.

Critical: whenever you edit the Connection class, you must resave the Provider class too — even with no changes. Otherwise the adapter disappears from the Type picklist and existing External Object tabs break.


Field type mapping

External API typeUse this
string / textDataSource.DataType.TEXT_TYPE
number / integer / decimalDataSource.DataType.NUMBER_TYPE
booleanDataSource.DataType.BOOLEAN_TYPE
date (ISO 8601)DataSource.DataType.DATE_TYPE
datetime / timestampDataSource.DataType.DATETIME_TYPE
URLDataSource.DataType.URL_TYPE
emailDataSource.DataType.EMAIL_TYPE
phoneDataSource.DataType.PHONE_TYPE
enum / picklistTEXT_TYPE — map enum values as strings
nested object / JSON blobFlatten to scalar fields, or TEXT_TYPE and parse in query()
arrayDerive a count field (NUMBER_TYPE), or flatten first-element fields
string > 255 charsLong text area — do not truncate; Salesforce maps it automatically

Every DataSource.Table must include these columns:

apex
DataSource.Column.text('ExternalId', 255)  // unique key from external system — REQUIRED
DataSource.Column.text('Name', 255)        // display label shown in Salesforce UI — REQUIRED
DataSource.Column.url('DisplayUrl')        // link to the record in the external system — recommended

Missing ExternalId is the most common reason an adapter deploys but records don't appear. DisplayUrl enables the clickable link icon in list views — populate it with the external record's URL.


Scenarios

Four scenarios: (1) public read-only, (2) authenticated API key/OAuth, (3) read-write with upsert/delete, (4) paginated API. Full code patterns for each are in references/scenarios.md.

Key differences by scenario:

ScenarioAuth modeExtra capabilitiesNamed Credential
Public read-onlyANONYMOUSQUERY, SEARCHDeploy as metadata
AuthenticatedNAMED_PRINCIPAL or PER_USERQUERY, SEARCHCreate manually in Setup — never deploy credentials as metadata
Read-writeANONYMOUS or authAdd ROW_CREATE, ROW_UPDATE, ROW_DELETEPer above
PaginatedAnyAnyUse context.tableSelection.numberOfRows (default 500 if null); no automatic queryMore

How to verify the adapter is working

Option 1 — SOQL via sf CLI (fastest, no UI needed)

bash
sf data query \
  --query "SELECT ExternalId, Name__c FROM [YourObject]__x LIMIT 5" \
  --target-org [org-alias]

If rows come back, the adapter is working. If 0 rows, check the troubleshooting steps below.

Option 2 — Visualforce page (best for demos, works on any org)

Deploy a Visualforce page + Apex controller that queries [Object]__x and renders rows in an apex:pageBlockTable. Open at [orgUrl]/apex/[PageName]. More reliable than list views for testing — bypasses tab requirements, deployment status, and filter issues. See references/scenarios.md for the standard template.

Option 3 — List view (standard UI, but requires extra steps)

For the list view to show records, all four of these must be true:

  1. External Object Deployment Status = Deployed (Object Manager → Edit)
  2. A tab exists for the External Object (Setup → Tabs → Custom Object Tabs → New)
  3. List view filter is set to All (not "Recently Viewed")
  4. Remote Site Setting exists for the external API URL

Troubleshooting: 0 records with no error

SymptomCauseFix
SOQL returns 0Remote Site Setting missingSetup → Remote Site Settings → New
SOQL returns 0Named Credential not foundSetup → Named Credentials → confirm callout: name matches exactly
SOQL returns 0Org proxy blocks external URLsUse loopback pattern or switch to an external DE org
List view shows 0Deployment Status = In DevelopmentObject Manager → [Object]__x → Edit → Deployed
List view shows 0Filter is "Recently Viewed"Change filter to "All"
App Launcher shows nothingNo tab createdSetup → Tabs → Custom Object Tabs → New

What the agent deploys vs. what the developer does manually

Agent deploys (one sf project deploy start command)

FileNotes
classes/[API]DataSourceConnection.cls + metaAlways
classes/[API]DataSourceProvider.cls + metaAlways
namedCredentials/[API].namedCredential-meta.xmlPublic APIs only — skip for any API requiring credentials

Do NOT generate externalDataSources/[API].externalDataSource-meta.xml. The External Data Source must be registered manually in Setup after deploying the Apex classes. The sf project deploy start command cannot deploy custom Apex External Data Sources — the sf CLI will error with "Could not infer a metadata type." Tell the user to go to Setup → External Data Sources → New after deployment.

Correct NamedCredential XML format (no <name> element — the API name comes from the filename):

xml
<?xml version="1.0" encoding="UTF-8"?>
<NamedCredential xmlns="http://soap.sforce.com/2006/04/metadata">
    <label>My API</label>
    <endpoint>https://api.example.com</endpoint>
    <allowMergeFieldsInBody>false</allowMergeFieldsInBody>
    <allowMergeFieldsInHeader>false</allowMergeFieldsInHeader>
    <generateAuthorizationHeader>false</generateAuthorizationHeader>
    <principalType>Anonymous</principalType>
    <protocol>NoAuthentication</protocol>
</NamedCredential>

Deploy command:

bash
sf project deploy start \
  --source-dir force-app/main/default/ \
  --target-org [org-alias]

Developer does manually (always — no metadata equivalent exists)

Validate and Sync triggers a live call to the external API to discover its schema and create External Object definitions. This cannot be scripted.

text
Setup → External Data Sources → [your data source] → Validate and Sync
Check the box next to each External Object → Sync
App Launcher → search [External Object name] → confirm records appear

Always end with: "Deployment complete. One step left: open the External Data Source in Salesforce Setup and click Validate and Sync."


Error handling rules

Never let an exception propagate uncaught out of query() — Salesforce shows a generic error to the user with no context.

SituationHandle it by
HTTP 401throw new DataSource.OAuthTokenExpiredException()
HTTP 429 / rate limitReturn empty rows; log via System.debug()
HTTP 500 or network errorReturn empty rows; do not rethrow
Null field in responserecord.get('field') != null ? (String) record.get('field') : ''
Nested JSON that won't flattenReturn raw JSON string as a TEXT_TYPE field rather than failing the whole query

Governor limits

  • Max 100 HTTP callouts per transaction — each query() call is one transaction
  • Heap limit 6 MB (synchronous) — don't deserialize massive payloads; use server-side pagination
  • CPU limit 10 seconds — avoid nested loops over large response arrays

Setup prerequisites — in this exact order

1. Deploy Apex classes first

The Salesforce Connect: Custom (Developed with Apex) type only appears in the External Data Source type dropdown after at least one DataSource.Provider subclass is deployed in the org.

This is not a permissions issue. It is a dependency — Salesforce discovers available Provider classes at runtime. No deployed Provider = no option in the dropdown.

Correct sequence — always:

  1. Deploy Apex classes first (sf project deploy start)
  2. Then go to Setup → External Data Sources → New → the Custom Apex type will appear

If the user says "I don't see the Custom Apex option in the dropdown", the answer is: deploy the classes first, then come back to Setup.

2. Add Remote Site Setting before testing

The external API's base URL must be whitelisted or callouts fail silently — query() returns empty rows with no exception, no error message. Deploy as metadata or add at Setup → Remote Site Settings → New.

3. After Validate and Sync — set Deployment Status to Deployed

After Validate and Sync, Salesforce creates the External Object with status "In Development". Records return 0 results in list views and SOQL until this is changed. No error is shown — another silent failure.

text
Setup → Object Manager → [YourObject]__x → Edit
  Deployment Status → Deployed → Save

Always tell the user this step after Validate and Sync completes.

4. Create a tab to surface the External Object in App Launcher

External Objects are invisible in the UI without a tab. Create one at:

text
Setup → Tabs → Custom Object Tabs → New → select [YourObject]__x → Save

Also required

  • Salesforce Connect license — without it, all Connect adapter types including OData are hidden. If the user sees OData and Cross-Org in the dropdown, the license is already active.

Anti-patterns

Don'tWhyDo
Generate code without knowing the API shapeWrong field types, wrong ExternalId mapping, broken adapterAsk for API name, base URL, auth type, sample response first
Deploy ExternalDataSource as metadataNot a deployable metadata type — sf CLI will errorRegister the External Data Source manually in Setup after deploying the Apex classes
Use upsertRow() or deleteRow() (singular)These methods don't exist — compile errorUse upsertRows() and deleteRows() (plural)
Put sync() only on ProviderOn some API versions sync() must be on Connection — compiler will tell youImplement sync() on Connection; remove from Provider if it errors
Hardcode the API URL in ApexCredentials exposed in source, callout blockedAlways use callout:NamedCredentialName
Return a single DataSource.TableResult from search()search() returns List<DataSource.TableResult> — compile errorLoop over context.tableSelections and return one result per table
Skip COUNT handling in query()List views fire COUNT queries; without detection they return wrong resultsCheck columnsSelected[0].aggregation == DataSource.QueryAggregation.COUNT
Leave External Object in "In Development"Records return 0 with no error — invisible to the userAfter Validate and Sync: Object Manager → [Object]__x → Edit → Deployed
Skip the Remote Site SettingCallout fires silently, returns empty rows, no exceptionDeploy remoteSiteSettings/[API].remoteSite-meta.xml or add manually in Setup

Before shipping

Confirm: inputs collected (API name, URL, auth, sample response, write support) → code has sync() + query() + search() on Connection, getCapabilities() + getConnection() on Provider, ExternalId and nameColumn on every table, COUNT handling in query(), mock data for tests, callout: prefix on all endpoints → both .cls-meta.xml files generated → deploy command given → post-deploy steps communicated (Named Credential setup, Remote Site Setting, External Data Source registered, Validate and Sync, Deployment Status → Deployed, tab created).


Reference examples

See references/official-examples.md for annotated study of the official Salesforce Connect adapter examples — GitHub Issues (full DML, picklist, cross-table relationships), Google Drive (OAuth + test mock), Google Books (pagination), StackOverflow (multiple tables), and Loopback (filter translation). Read before generating for a new user.


Project setup — if the developer has no SFDX project yet

Before deploying, they need a project structure. If one doesn't exist, generate it first:

bash
sf project generate --name my-adapter --output-dir .
cd my-adapter

This creates force-app/main/default/classes/ and the required sfdx-project.json. All generated files go into this structure. The developer does not need VS Code, Agentforce Vibes, or any Salesforce IDE — just sf CLI installed and an org authenticated via sf org login web --alias my-org.

This skill works with any coding agent that can read a context file — Claude Code, Cursor, Windsurf, GitHub Copilot, or any agent with the SKILL.md loaded. No Salesforce MCP server, no Agentforce Vibes, no internal Salesforce tooling required.


Output format

Generate files in this order, then give the deploy command:

  1. force-app/main/default/classes/[API]DataSourceConnection.cls
  2. force-app/main/default/classes/[API]DataSourceProvider.cls
  3. force-app/main/default/classes/[API]DataSourceConnection.cls-meta.xml
  4. force-app/main/default/classes/[API]DataSourceProvider.cls-meta.xml
  5. force-app/main/default/namedCredentials/[API].namedCredential-meta.xml — public APIs only

One-line comment at top of each Apex class: // Salesforce Connect custom adapter for [API name] No other inline comments unless a logic choice is non-obvious.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Platform Salesforce Connect Adapter Generate AI 技能有什么作用?

Custom Apex adapter generation for Salesforce Connect — connects any external REST API to Salesforce as live, queryable External Objects without ETL or copying. TRIGGER when: connecting a non-standard external API, writing a DataSource.Provider/Connection or a `.cls`/`.cls-meta.xml` custom adapter class, adding a `.namedCredential-meta.xml` for the adapter's callout, surfacing external data as records, "custom adapter", "ExternalId field", "DataSource namespace", or whether custom Apex fits. DO NOT TRIGGER when: a standard adapter is already configured (OData, Snowflake), for copy/bulk-sync...

为什么在 TypingMind 中使用 Platform Salesforce Connect Adapter Generate?

因为您只需安装一次,就能搭配任何模型使用。Platform Salesforce Connect Adapter Generate 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Platform Salesforce Connect Adapter Generate?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/forcedotcom/sf-skills/tree/main/plugins/builder/integration/skills/platform-salesforce-connect-adapter-generate。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Platform Salesforce Connect Adapter Generate?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Platform Salesforce Connect Adapter Generate 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Platform Salesforce Connect Adapter Generate 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Platform Salesforce Connect Adapter Generate AI 技能免费吗?

是的。forcedotcom 已在 GitHub 上根据 Apache-2.0 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇