3) 通过SOQL语句进行查询:标准 rest接口同样支持使用SOQL去返回指定的list信息。格式为:services/data/v51.0/query/?q=SOQL query, 其中 SOQL使用 + 分隔 。下面demo中在Account表中查询了 Id以及Name。response中包含了记录数以及细节信息,可以通过层级结构进行数据的获取。
2. 新建场景
1) 单表常规操作新建:针对表的创建,因为我们需要request body指定哪些字段创建成哪些值,所以我们的method肯定不可能是 GET了,针对标准的单表创建,类型选择Post,将报文内容放在{}(花括号)中间,然后使用键值对方式,左面是字段的API Name,右面对应相关的值,按照以下的方式即可。点击Execute,我们可以看到 response的结构体返回了新建的Id,结果状态等信息。
每个层级结构中都有一个 referenceId:这个是必须要有的,并且是唯一的,当成功以后referenceId用来对应着成功插入数据的record id,这个可以随便赋值,只要保证唯一即可。
我们看到针对子表插入的时候,使用的是 Contacts / Cases等。这个是子表和父表关联时的 Child Relationship Name,因为这两个都是标准表,所以没有__r,如果是自定义表的关系,这个 Child Relationship Name后面需要添加 __r用来代表子表名称。
request body 内容如下所示:
{"records" :[
{
"attributes" : {"type" : "Account", "referenceId" : "ref1"},
"name" : "SampleAccount1",
"industry" : "Banking",
"Contacts" : {
"records" : [
{
"attributes" : {"type" : "Contact", "referenceId" : "ref2"},
"lastname" : "Smith",
"Title" : "President",
"email" : "sample@salesforce.com"
},{
"attributes" : {"type" : "Contact", "referenceId" : "ref3"},
"lastname" : "Evans",
"title" : "Vice President",
"email" : "sample@salesforce.com"
}
]
}
},
{
"attributes" : {"type" : "Account", "referenceId" : "ref4"},
"name" : "SampleAccount2",
"industry" : "Banking",
"Cases" : {
"records" : [
{
"attributes" : {"type" : "Case", "referenceId" : "ref5"},
"Status": "New",
"Priority": "Meduim",
"Origin" : "Phone"
}
]
},
"Contacts" : {
"records" : [
{
"attributes" : {"type" : "Contact", "referenceId" : "ref6"},
"lastname" : "Jones",
"title" : "President",
"email" : "sample@salesforce.com"
}
]
}
}
]
}