You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mule Salesforce连接器查询操作:List of Maps输入响应异常问题

How to Query Multiple Contacts in Salesforce Connector Using a List of Maps

Got it, let's work through this. The Salesforce connector's query operation doesn't natively accept a list of maps like insert/update does, but we can build a dynamic SOQL query using your contact IDs to fetch all records in one go. Here's how to make it happen:

Step 1: Generate a Dynamic SOQL Query with DataWeave

First, we need to turn your list of contact maps into a formatted SOQL IN clause. Use this DataWeave script to create the query:

%dw 2.0
output application/json
// Format IDs for the SOQL IN clause (wrap each in single quotes, join with commas)
var formattedContactIds = payload map "'" ++ $.id ++ "'" joinBy ","
// Build the complete SOQL query
---
{
    soql: "SELECT Id, Name FROM Contact WHERE Id IN (" ++ formattedContactIds ++ ")"
}

For your sample input [ {id:'169057',Name:'John'}, {id:'169099',Name:'Mark'} ], this will output:

{
    "soql": "SELECT Id, Name FROM Contact WHERE Id IN ('169057','169099')"
}

Step 2: Configure the Salesforce Connector's Query Operation

In your Salesforce connector, select the Query operation. Instead of entering a static SOQL string, reference the dynamic query from the previous step. For example, if the DataWeave output is in the payload, set the SOQL field to payload.soql.

Step 3: Convert the ConsumerIterator to a Usable List

The Salesforce connector returns a ConsumerIterator as the result—this is a lazy-loaded collection designed for large datasets. To turn it into a list of maps (matching your input structure), use this DataWeave script:

%dw 2.0
output application/json
---
payload as Array {
    id: $.Id,
    Name: $.Name
}

This transforms the iterator into an array of maps with the exact keys (id and Name) from your original input. If you just need a string for debugging, you can use payload as String, but converting to an array is more useful for downstream processing.

Quick Tips

  • Salesforce allows up to 1000 values in an IN clause, so this approach scales perfectly for your use case (and up to 1000 records).
  • If some IDs in your list don't exist in Salesforce, the query will only return the records that do exist—no errors for missing IDs.
  • Make sure your Salesforce connected app has read permissions for Contact records.

内容的提问来源于stack exchange,提问作者Marcos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:49:13