0

Salesforce中有 5 个对象:contact, account, account_contact__c, user, recordtype。下面是需要转换为 Salesforce SOQL 查询的 SQL 查询

SELECT c.id,c.fname,c.lname,u.name, ac.desc, r.date 
FROM contact c 
LEFT JOIN user u on c.oid =u.sfid 
LEFT JOIN account_contact__c ac on c.sfid=ac.contact_id__c  
LEFT JOIN account a on a.sfid=ac.account_id__c 
LEFT JOIN recordtype r on a.recordtypeid =r.sfid and r.type=‘test’

我设法加入了 2 个对象,但在第二个表中,我无法添加多个字段。

Select id,fname,lname 
from contact 
where id in (
   select contact_id__c from account_contact__c
)

如果我尝试在其中添加另一个SELECT语句account_contact__c,则会出现错误。

4

1 回答 1

0

We don't know all your relations, for example Contact-User. What do you need? Contact's Owner? Customer/Partner Community user created out of that contact? Created By/Last Modified by User?

And the Account_Contact__c table looks weird, why didn't you use standard AccountContactRelation. Or even normally go "up" from Contact to Account.

Something like this could work but it really depends on what you need. And wit your custom table - no promise this compiles, you might have different field names.

"related list style" - you start from contact, go "down" to your weird custom relationship, then "up" from that relationship to account.

SELECT Id, FirstName, LastName, Owner.Name,
   (SELECT Id, Account__r.Id, Account__r.Name, Account__r.RecordType.Name)
FROM Contact

"normal style" - you start from your custom relationship table then go "up" to acc and con

SELECT Id,
    Contact__r.FirstName, Contact__r.LastName, Contact__r.Owner.Name,
    Account__r.Name, Account__r.RecordType.Name
FROM Account_Contact__c
于 2021-08-28T11:00:54.307 回答