使用机会选择器检索机会contactrole

发布于 2025-02-03 08:11:43 字数 1494 浏览 4 评论 0原文

我是Apex的新手,我正在尝试了解别人写的Apex代码。它检索机会数据。除了机会联系角色外,它都会获得所有领域。即使其中有数据,它总是空的。

它从服务类中调用机会选择者

机会opp = cq.opportunities.getbyidwithocr(new Set {opunterId})[0];

在opployselector.apxc

public List<Opportunity> GetByIdWithOCR(Set<Id> idSet) {
        return (List<Opportunity>) GetQueryFactory()
                .WithCriteria(cq_Criteria.ValueIn(Opportunity.Id, idSet))
                .WithRelatedField(Opportunity.AccountId, Account.Name)
                .WithRelatedField(Opportunity.AccountId, Account.BillingStreet)
                .WithRelatedField(Opportunity.AccountId, Account.BillingCity)
                .WithRelatedField(Opportunity.AccountId, Account.BillingState)
                .WithRelatedField(Opportunity.AccountId, Account.BillingPostalCode)
                .WithRelatedField(Opportunity.AccountId, Account.BillingCountry)
                .WithChildQuery(
                        cq.OpportunityContactRoles.GetQueryFactory()
                            .WithCriteria(cq_Criteria.Equals(OpportunityContactRole.Role, 'Decision Maker'))
                            .WithRelatedField(OpportunityContactRole.ContactId, Contact.Name)
                            .WithRelatedField(OpportunityContactRole.ContactId, Contact.Phone)
                            .WithRelatedField(OpportunityContactRole.ContactId, Contact.Email))
                .Execute();
    }

所有值都在那里,但接触角色是空的。请建议

I am very new to apex, I am trying to understand apex code written by someone else. Its retrieving opportunity data. It gets all the fields except opportunity contact role. Its always empty, even though there is data in it.

It calls the opportunity selector from the service class

Opportunity opp = cq.Opportunities.GetByIdWithOCR(new Set{opportunityId})[0];

in the opportunitySelector.apxc

public List<Opportunity> GetByIdWithOCR(Set<Id> idSet) {
        return (List<Opportunity>) GetQueryFactory()
                .WithCriteria(cq_Criteria.ValueIn(Opportunity.Id, idSet))
                .WithRelatedField(Opportunity.AccountId, Account.Name)
                .WithRelatedField(Opportunity.AccountId, Account.BillingStreet)
                .WithRelatedField(Opportunity.AccountId, Account.BillingCity)
                .WithRelatedField(Opportunity.AccountId, Account.BillingState)
                .WithRelatedField(Opportunity.AccountId, Account.BillingPostalCode)
                .WithRelatedField(Opportunity.AccountId, Account.BillingCountry)
                .WithChildQuery(
                        cq.OpportunityContactRoles.GetQueryFactory()
                            .WithCriteria(cq_Criteria.Equals(OpportunityContactRole.Role, 'Decision Maker'))
                            .WithRelatedField(OpportunityContactRole.ContactId, Contact.Name)
                            .WithRelatedField(OpportunityContactRole.ContactId, Contact.Phone)
                            .WithRelatedField(OpportunityContactRole.ContactId, Contact.Email))
                .Execute();
    }

all the values are there but contact role is empty. Please advice

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2025-02-10 08:11:43

这都是您的同事撰写的全部定制,有些尝试在ORM层。 “正常”的顶点是直接编写查询,更好的性能,一些编译时间检查...很难说出该代码中的潜伏。

它是哪个社区?客户还是伙伴?最后我检查了客户社区无法获得机会。假设它是合作伙伴 - 您知道如何检查社区用户的配置文件并访问整个机会contactrole表及其中的所有字段吗?

有一些黑客可以让代码跳出Salesforce安全模型(而无需共享等),但是除非您真的知道您在做什么,并且可以控制数据可见性(Profiless Profiles,否则我不建议您建议/权限集,共享规则,例如共享集)。

尝试捕获调试日志。打开开发人员控制台(如果可能的话,将其标记为社区),并运行页面或实验设置 - &gt;调试日志。您应该能够找到查询并尝试手动执行它。

如果您想排除此查询工厂的问题,请尝试将代码交换并查看是否更好:

return [SELECT Account.Name, Account.BillingStreet, Account.BillingCity,
    Account.BillingState, Account.BillingPostalCode, Account.BillingCountry,
    (SELECT Contact.Name, Contact.Phone, Contact.Email
    FROM OpportunityContactRoles
    WHERE Role = 'Decision Maker')
    FROM Opportunity
    WHERE Id IN :idSet];

This is all custom written by your colleague, some attempt at ORM layer. "Normal" apex would be to write the query directly, better performance, some compile-time checks... Hard to say what lurks in that code.

Which community it is? Customer or Partner? Last I checked customer community has no access to Opportunity. Assuming it's Partner - do you know how to check the Profile of the community user and access to whole OpportunityContactRole table and all fields in it?

There are some hacks to let code jump out of the Salesforce security model (without sharing etc) but I wouldn't recommend unless you really know what you're doing and normal ways of controlling data visibility (profiles/permission sets, sharing rules, like sharing sets) failed you.

Try to capture debug logs. Open developer console (if possible, you tagged this as communities) and run your page or experiment with Setup -> Debug Logs. You should be able to find the query and try to execute it manually.

If you want to rule out issues with this query factory try to swap the code with this and see if it's any better:

return [SELECT Account.Name, Account.BillingStreet, Account.BillingCity,
    Account.BillingState, Account.BillingPostalCode, Account.BillingCountry,
    (SELECT Contact.Name, Contact.Phone, Contact.Email
    FROM OpportunityContactRoles
    WHERE Role = 'Decision Maker')
    FROM Opportunity
    WHERE Id IN :idSet];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文