0

I am trying to create a table of the list of competitors on the opportunity. this list will be shown as part of a VF email template. Like the opportunity team, opportunity partners and so on, I assume I can also present the opportunity competitors. I am trying to write this:

<apex:repeat var="competitor" value="{!relatedTo.OpportunityCompetitor}">
                    <tr>
                        <td>
                            {!competitor.Name}

                        </td>
                        <td>
                            {!competitor.id}
                        </td>

                    </tr>
            </apex:repeat>

but the system just shouts:

Error: Invalid field OpportunityCompetitor for SObject Opportunity

I looked in the documentation for the API name of competitors and only found "OpportunityCompetitor"

I would be thankful if you could help me solve this.

Udi

1

Well I think you are just missing an 's'. It should be OpportunityCompetitors assuming relatedTo is the opportunity.

Controller

Opportunity relatedTo = [Select Name, Id, (Select Id, CompetitorName,Strengths,Weaknesses From OpportunityCompetitors) From Opportunity where id =: someOpptyid];

VF Page

<table>
    <apex:repeat var="competitor" value="{!relatedTo.OpportunityCompetitors}">
    <tr>
    <td>{!competitor.CompetitorName}</td>
    <td>{!competitor.Strengths}</td>
    <td>{!competitor.Weaknesses}</td>
    </tr>
    </apex:repeat>
</table>

Option 2

If you are using the Opportunity standard controller, then you can simply do this

 <apex:page standardController="Opportunity" >

        <apex:relatedList list="OpportunityCompetitors"> 

        </apex:relatedList>

 </apex:page>
2
  • thanks AslamK! this actually solved one problem and got me closer to the finish line but unfortunately I am not there yet :) Now it does not let me reference ANY of this object's fields! So annoying! Do you have a clue? – Shvek-Vek Nov 12 '14 at 12:15
  • What do you mean that id does not let you reference any of the object? Are you querying that related object and its field in your controller? – AslamK Nov 12 '14 at 13:31

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.