怎么取得一个Object的所有自定义字段(使用SOQL实现)
2023年09月13日
文章浏览:376
需求: 当我们想把一个Object里面的,所有的自定义字段都给取出来

我们可以用下面的SOQL语句来取得(需要勾选上Use Tooling API?选项

TableEnumOrId 的值就是这个Object的Id

在Classic界面下面,Object的自定义页面的地址如下。标粗体的就是Object的ID

 https://dreamitschool-dev-ed.my.salesforce.com/01I5h0000006Q5e?setupid=CustomObjects#01I5h0000006Q5e_CustomFieldRelatedList_target 


在Lightning界面下面的地址如下,标粗体的就是Object的ID

 https://dreamitschool-dev-ed.lightning.force.com/lightning/setup/ObjectManager/01I5h0000006Q5e/Details/view?0.source=alohaHeader 

SELECT DeveloperName, TableEnumOrId FROM CustomField WHERE  TableEnumOrId = '01I5h0000006Q5e'


取得的结果如下

"_","DeveloperName","TableEnumOrId"
"[CustomField]","Memo","01I5h0000006Q5eEAE"
"[CustomField]","Certification","01I5h0000006Q5eEAE"
"[CustomField]","CloseDate","01I5h0000006Q5eEAE"
"[CustomField]","Year","01I5h0000006Q5eEAE"
"[CustomField]","Month","01I5h0000006Q5eEAE"
"[CustomField]","SalesTargetAmount_Direct","01I5h0000006Q5eEAE"
"[CustomField]","SalesByYear_BD_parent","01I5h0000006Q5eEAE"
"[CustomField]","MyEmail","01I5h0000006Q5eEAE"



关于CustomField Object,详细可以参考下面的链接

 https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_customfield.htm 

关注 收藏