返回空白记录,而不是从Salesforce中找不到记录

时间:2018-11-20 17:08:35

标签: salesforce soql salesforce-communities

我正在使用SalesForce Mobile SDK开发移动应用程序,并且为了使功能正常工作,我正在建立customer_id与相应地址之间的映射。因此,要进行映射,我已经修改了SOQL查询以在执行查询后取回customer_id值。

找到地址后,此映射工作正常。但是,当没有地址关联时,我没有任何响应。因此,映射一个customer_id并在其中放置一个空地址,即使没有找到地址,我也需要将customer_id退回。

为了更好地说明:由于没有找到地址,以下查询不会返回任何结果:

SELECT Account_vod__c,Address_line_2_vod__c, City_vod__c, Name FROM Address_vod__c WHERE Account_vod__c = '001e000000qVp8WAAS'

但是我想创建一个查询,以便如果没有找到记录,它将返回类似:

enter image description here

3 个答案:

答案 0 :(得分:0)

您可以尝试使用合并

SELECT coalesce(Account_vod__c,001e000000qVp8WAAS),
Address_line_2_vod__c, City_vod__c, Name 
FROM Address_vod__c WHERE Account_vod__c = '001e000000qVp8WAAS'

答案 1 :(得分:0)

此问题基于初始DBMS标记回答:

SELECT a.Account_vod__c, a1.Address_line_2_vod__c, a1.City_vod__c, a1.Name
FROM (SELECT '001e000000qVp8WAAS' AS Account_vod__c) a LEFT OUTER JOIN
     Address_vod__c a1
     ON a1.Account_vod__c = a.Account_vod__c;

如果您有多个Account_vod__c,请使用UNION ALL并执行LEFT JOIN

SELECT a.Account_vod__c, a1.Address_line_2_vod__c, a1.City_vod__c, a1.Name
FROM (SELECT '001e000000qVp8WAAS' AS Account_vod__c
      UNION ALL
      . . .
     ) a LEFT OUTER JOIN
     Address_vod__c a1
     ON a1.Account_vod__c = a.Account_vod__c;

答案 2 :(得分:0)

嵌套的SOQL查询可以达到目的:

SELECT Id, Name,(SELECT Id, Account_vod__c, Name, Address_line_2_vod__c, City_vod__c FROM Address_vod__r)FROM Account WHERE Id = '001e0000008Ch5nAAC' LIMIT 1