You need to sign in to do that
Don't have an account?
Kimberly Allen 15
displaying list on unrelated object
Hi,
I am trying to display the opportunitycontactroles list on an object (Deal_Desk_Request__c) related to the opportunity. I am not getting errors when saving the code, but nothing is appearing in the visualforce page other than the headers. I am new to apex/visualforce development and not sure what I am doing wrong. Can someone please help?
Here is the visualforce page:
Here is the extension class:
I am trying to display the opportunitycontactroles list on an object (Deal_Desk_Request__c) related to the opportunity. I am not getting errors when saving the code, but nothing is appearing in the visualforce page other than the headers. I am new to apex/visualforce development and not sure what I am doing wrong. Can someone please help?
Here is the visualforce page:
<apex:page standardcontroller="deal_desk_request__c" extensions="dealdeskcontactrole" > <apex:pageblock > <apex:pageblocktable value="{!roles}" var="role"> <apex:column headervalue="Contact" > <apex:outputfield value="{!role.contactid}"/> </apex:column> <apex:column headervalue="Role" > <apex:outputfield value="{!role.role}"/> </apex:column> <apex:column headervalue="Primary" > <apex:outputfield value="{!role.isprimary}"/> </apex:column> </apex:pageblocktable> </apex:pageblock> </apex:page>
Here is the extension class:
public with sharing class dealdeskcontactrole { list<opportunitycontactrole> roles; public final Deal_Desk_Request__c DDR; public dealdeskcontactrole(ApexPages.StandardController controller) { this.DDR = (Deal_Desk_Request__c)controller.getRecord(); } public list<opportunitycontactrole> getroles() { try{ list<opportunitycontactrole> roles = [select id, contactID, Role, Isprimary from opportunitycontactrole where Opportunityid =: DDR.Opportunity__r.id]; return roles; } catch(system.exception e){ return null; } } }
The way you have extracted current Deal_Desk_Request__c .i,e, will only give you the ID of Deal_Desk_Request__c . Not all the information. [You can test this by debugging entire DDR in next line in constructor. You will only get the ID].
The error is when in getRoles() you are refering the field that is not fetched in SOQL. So, the DDR.Opportunity__r.id is null.
So, you can add a SOQL query that will fetch the related opportunity. And pass that opp in original query. Hope this helps.
All Answers
The way you have extracted current Deal_Desk_Request__c .i,e, will only give you the ID of Deal_Desk_Request__c . Not all the information. [You can test this by debugging entire DDR in next line in constructor. You will only get the ID].
The error is when in getRoles() you are refering the field that is not fetched in SOQL. So, the DDR.Opportunity__r.id is null.
So, you can add a SOQL query that will fetch the related opportunity. And pass that opp in original query. Hope this helps.
Thank you so much for your reply and help on the class. It solved my issue!!
Thanks,
Kimberly