function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sales4cesales4ce 

Help with Opportunity & Contacts

Hi,

 

I am building a visualforce page.Let me explain the use-case:

 

I need to create a visualforce page, which will be embedded as a custom link on opportunity record.

I am using standard controller of Opportunity.

 

Now, salesforce gives us OpportunityContactRole, which gives contacts associated with the opportunity.

But, this does not give all the information related to a contact,Like email address, phoneNo or any other custom fields on the contact.

 

In the visualforce page i also need to  displaythe contact's other information.

 

I tried extending the standardcontroller and doing a semi join with opportunitycontactrole, but was not able to pull off.

 

Here is the query: [select Contact.email from Contact where Id in (Select ContactId from OpportunityContactRole where OpportunityId='SomeId')].

 

How can i accomplish this? any ideas/help on this is greatly appreciated.

 

Here is the VF code:

 

 <apex:Page standardcontroller="Opportunity">

<apex:pageBlock Title="Contacts" >
        <apex:pageblockSection Columns="2" >
            <apex:pageBlockTable value="{!Opportunity.OpportunityContactRoles}" var="cts">           
                <apex:column headerValue="Contact Name">
                    <apex:outputText value="{!cts.Contact.Name}">
                    </apex:outputText>
                 </apex:column>
                 <apex:column headerValue="Contact Role">
                    <apex:outputText value="{!cts.Role}">
                    </apex:outputText>
                 </apex:column>                
            </apex:pageBlockTable>                                           
        </apex:pageblockSection>                                                           
    </apex:pageBlock> 
 </apex:Page>

 

Thanks in Advance!

Sales4ce

Message Edited by sales4ce on 03-24-2010 02:24 PM
Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae

What type of error are you getting?

I tried your page, without an extension controller, and it works fine.

On mine, I added the contact email address as well.

 

 

<apex:page standardcontroller="Opportunity"> <apex:pageBlock Title="Contacts" > <apex:pageblockSection Columns="2" > <apex:pageBlockTable value="{!Opportunity.OpportunityContactRoles}" var="cts"> <apex:column headerValue="Contact Name"> <apex:outputText value="{!cts.Contact.Name}"> </apex:outputText> </apex:column> <apex:column headerValue="Contact Role"> <apex:outputText value="{!cts.Role}"> </apex:outputText> </apex:column> <apex:column headerValue="Contact Email"> <apex:outputText value="{!cts.Contact.Email}"> </apex:outputText> </apex:column> </apex:pageBlockTable> </apex:pageblockSection> </apex:pageBlock> </apex:page>

 

 

 

All Answers

JimRaeJimRae

What type of error are you getting?

I tried your page, without an extension controller, and it works fine.

On mine, I added the contact email address as well.

 

 

<apex:page standardcontroller="Opportunity"> <apex:pageBlock Title="Contacts" > <apex:pageblockSection Columns="2" > <apex:pageBlockTable value="{!Opportunity.OpportunityContactRoles}" var="cts"> <apex:column headerValue="Contact Name"> <apex:outputText value="{!cts.Contact.Name}"> </apex:outputText> </apex:column> <apex:column headerValue="Contact Role"> <apex:outputText value="{!cts.Role}"> </apex:outputText> </apex:column> <apex:column headerValue="Contact Email"> <apex:outputText value="{!cts.Contact.Email}"> </apex:outputText> </apex:column> </apex:pageBlockTable> </apex:pageblockSection> </apex:pageBlock> </apex:page>

 

 

 

This was selected as the best answer
sales4cesales4ce

Thanks Jim. It worked fine.

I did not know that we could query all the fields on the contact from opportunitycontactrole using "Contact.FieldName".

 

 

Thanks,

Sales4ce

jgood2009jgood2009

Hi Jim,

 

Is it possible to pull Contact Role information into the Oppty Product page as well?  I tried changing the code as follows, but received the following error message:

 

Error: ; nested exception is: common.exception.ApiQueryException: SELECT id, opportunity.opportunitycontactroles.role ^ ERROR at Row:1:Column:12 Didn't understand relationship 'opportunitycontactroles' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

 

<apex:page standardcontroller="OpportunityLineItem">

<apex:pageBlock Title="Contact Roles" >
        <apex:pageblockSection Columns="2" >
            <apex:pageBlockTable value="{!OpportunityLineItem.Opportunity.OpportunityContactRoles}" var="cts">           
                <apex:column headerValue="Contact Name">
                    <apex:outputText value="{!cts.Contact.Name}">
                    </apex:outputText>
                 </apex:column>
                 <apex:column headerValue="Contact Role">
                    <apex:outputText value="{!cts.Role}">
                    </apex:outputText>
                 </apex:column>    
                 <apex:column headerValue="Contact Email">
                    <apex:outputText value="{!cts.Contact.Email}">
                    </apex:outputText>
                 </apex:column>                
            </apex:pageBlockTable>                                           
        </apex:pageblockSection>                                                           
    </apex:pageBlock> 
 </apex:page>

 I have a group of users who needs to see contact info at the oppty product level.

 

Thanks,

Jennifer

JimRaeJimRae

Unfortunately, that is not supported.  According to the API documenation,

In each specified relationship, only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specified Account, the SELECT clause could only specify the Contact or other objects at that level. It could not specify a child object of Contact.

 

So you can't go up, then go back down again.  Not sure if there is an easy way to accomplish this, you may have to create some custom fields on the OLI and use a trigger to update them.

 

 

jgood2009jgood2009

That's what I thought.  Thanks for your response.

 

Jennifer

Bob_zBob_z

I am trying to figure out a solution to send an email out to a contact via timebased workflow rule. Can a visualforce page or visualforce email template work with contact role fields?

JimRaeJimRae

Need more information on that.  What contact, and based on what type of timeframe? Is this someone that is on the opportunity?  what triggers the email to be sent (condition and time)?

Bob_zBob_z

We want to follow-up 5 days after creation date to the contact associated (contact role contact) to the opportunity.  So whatever contact that is assigned to that opportunity, we need an email sent to that contact. 

JimRaeJimRae

If the contact was directly on the Opportunity, you could do it with Timebased workflow.  Since it isn't, you would need to use either scheduled Apex, or an add in like CronKit. 

With Scheduled Apex, you could set up a schedule that runs every day at the same time, and selects all opportunities that were created 5 days earlier. Then, from that list of Opportunities, collects all of the ContactRole contacts and sends each a message.

Look at scheduled Apex and sendmail in the apex documentation for more details.

 

 

Bob_zBob_z

Does anyone have any sample code I could start with? I am new to apex development.