I want to return all the opportunity contact roles for each opportunity where it's roles for an Opportunity, and I want to access a field in the contact role. my query looks ok, but I can't access the fields directly in Apex. Also, how do I access this in Visualforce?


        Opportunity opp = [SELECT id, Name, StageName,
    (select contact.name, contact.phone from OpportunityContactRoles where isPrimary = true  )  
    FROM Opportunity
    where id = '006e0000003V3NNAA0'];



Invalid foreign key relationship: Opportunity.OpportunityContactRoles


<apex:outputText value="{!opps.???????


The problem is in how you're accessing the Opportunity Contact Roles. Your query is returning this data as a list; you need to select a specific Opportunity Contact Role.

Try this:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.