简体   繁体   English

SalesForce SOQL 与查找以创建层次结构字符串

[英]SalesForce SOQL with lookup to create hierarchy string

I am trying to create an SOQL query that looks to an employees report to position id and create a string that will concat the employees position id and the position id of his manager and concat the managers manager and continue this up the organization chart.我正在尝试创建一个 SOQL 查询,该查询查看员工报告以查找职位 id,并创建一个字符串,该字符串将连接员工职位 id 和他的经理的职位 id,并连接经理经理并在组织结构图中继续此操作。

Example Data in Position__c: Position__c 中的示例数据:

Employee_Name     Position_ID      Reports_to_Position_ID
John Doe             123                    456
Billy Bob            456                    789
Jane Doe             789                    321
Harvey Sample        321                    654

John Doe's position id is 123, he reports to position 456. position 456 reports to 789 and so on. John Doe 的职位 id 是 123,他向职位 456 报告。职位 456 向 789 报告,依此类推。

Expected Result for John Doe reports_to_Hierarchy --> 123,456,789,321,654 John Doe 的预期结果reports_to_Hierarchy --> 123,456,789,321,654

SOQL looks bit object-oriented, you use dots to go "up" the relationship. SOQL 看起来有点面向对象,你使用点来“向上”关系。 https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships.htm

The basic idea is基本思想是

SELECT Name, Manager.Name, Manager.Manager.Name, Manager.Manager.Manager.Name
FROM User

Actual result depends if you have standard or custom object and what are the field names.实际结果取决于您是否有标准或自定义对象以及字段名称是什么。 You can go up to 5 levels (dots) away from your starting point.您最多可以从起点上升 5 个级别(点)。

Is the list flat just like that?名单就这样平吗? You might need a helper lookup to "self" field on Position__c, call it "Parent__c", "Manager__c" or something.您可能需要对 Position__c 上的“self”字段进行辅助查找,将其称为“Parent__c”、“Manager__c”或其他名称。 And you'd need to populate it during load (read about upsert and external ids?)并且您需要在加载期间填充它(阅读有关 upsert 和外部 ID 的内容?)

And then it'd be something like然后它会是这样的

SELECT PositionId__c, 
    Parent__r.PositionId__c, 
    Parent__r.Parent__r.PositionId__c, 
    Parent__r.Parent__r.Parent__r.PositionId__c
FROM Position__c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM