You need to sign in to do that
Don't have an account?
Michael Snow 5
Link Contact Activities to Opportunities using Visualforce
Hi There,
So I am attempting to create a VF page that brings in all Activities onto an Opportunity from the Opportunities Primary Contact that is identified on the Opportunity. I attempted to create a custom controller class to complete this but then learned that you have to use the standard controller i norder to be able to embed the VF section onto SFDC.
Also unfortunately now you can no longer switch the Controller from a standard controller to a custom controller anymore :(
Any ideas on how to work around this? I shared the VF page and custom controller below
VF Page:
Custom Controller:
So I am attempting to create a VF page that brings in all Activities onto an Opportunity from the Opportunities Primary Contact that is identified on the Opportunity. I attempted to create a custom controller class to complete this but then learned that you have to use the standard controller i norder to be able to embed the VF section onto SFDC.
Also unfortunately now you can no longer switch the Controller from a standard controller to a custom controller anymore :(
Any ideas on how to work around this? I shared the VF page and custom controller below
VF Page:
<apex:page controller="related_activities_from_contacts"> <apex:form > <apex:pageBlock title="Activites with Contacts" id="activites_list"> <!-- Events List --> <apex:pageBlockTable value="{! events }" var="evt"> <apex:column value="{! evt.ActivityDate }"/> <apex:column value="{! evt.ActivityType }"/> <apex:column value="{! evt.Description }"/> <apex:column value="{! evt.OwnerId }"/> <apex:column value="{! evt.PrimaryWhoId }"/> <apex:column value="{! evt.Subject }"/> <apex:column value="{! evt.WhoId }"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Custom Controller:
public class related_activities_from_contacts { // This would be the Id of the Opportunity Id OppID = (Id) ApexPages.currentPage().getParameters().get('id'); // Select only one of those contacts for use in the Contact ID Below OpportunityContactRole[] contactRoleArray = [select ContactID from OpportunityContactRole where OpportunityId =: OppID AND isPrimary = TRUE]; // Id ContactID = contactRoleArray[0]; public List<ActivityHistory> getEvents() { List<ActivityHistory> results = Database.query( 'SELECT ActivityDate, ActivityType, Description, OwnerId, PrimaryWhoId, Subject, WhoId' + 'FROM ActivityHistory ' + 'Where WhoId =' + contactRoleArray[0] ); return results; } }
Try this.
All Answers
Try this.
The only issue now that I'm running into on the Opportunity page itself where I am running into the following error:
"Content cannot be displayed: unexpected token: Where"
Do you know what is causing this error? (Also looking currently on my end) And thanks again for your quick and helpful support on this!
For reference for others that use this, there is just a slight error around the if/else logic with missing {} as well with the Apex pages add a message. I was able to replace that with a code example from this SFDC documentation (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_message.htm) to get rid of the error
Check this controller now.
- https://developer.salesforce.com/forums/?id=906F000000099ZNIAY
- https://stackoverflow.com/questions/10939796/soql-issue-when-querying-activityhistory-as-a-subquery
So I am attempting to write a subquery here but then get the following error on the APEX Page: "Illegal assignment from List to ist"Here are the adjustments I made:
Is there something wrong earlier in the public class maybe?
Here are the adjustments that I was able to make: