+ Start a Discussion
notsosmartnotsosmart 

Action Event for Wrapper Class line item

I have a wrapper class for Opportunities associated to a Custom Object.  The query includes related fields for display only.

This is functioning for existing Custom Object record associations as it comes from the database.  The problem is that the display of related fields need to come from a query on the related objects so that I get data for new and record changes.

 

I have that query also but I haven't figured out how to merge that data into the wrapper items or just reference the query in the Visualforce page for this. When I attempt the latter, I get an error stating that it's not a part of the controller (Custom Object).  My page declares the Custom Object Standard controller and an extenstion that includes the above queries.

 

i think the latter concept is the cleanest solution but I have to fiqure out how to gett the system to understand these processes.

 

The Page:  It does not include the attempts to add the events

 

<apex:page standardController="Trip_Report__c" extensions="TripRptExt" showHeader="false"><apex:sectionHeader title="Trip Report" subtitle="Step 3 of 5 - Opportunities"/>

<apex:form >
<apex:PageMessages id="pageMessage" showDetail="false"/>
<apex:pageBlock title="Trip Information">
<apex:pageBlockButtons location="both">
<apex:commandButton value="Cancel" action="{!cancel}"/>
<apex:commandButton value="Prev" action="{!step2}" />
<apex:commandButton value="Next" action="{!step4}" />
</apex:pageBlockButtons>
<apex:PageBlockSection title="Information" columns="2" collapsible="false" >
<apex:outputField value="{!tripReport.Unique_Name__c}" />
<apex:outputField value="{!tripReport.Date_of_Meeting__c}" />
<apex:outputField value="{!tripReport.Campaign__c}" />
<apex:outputField value="{!tripReport.Company__c}" />
<apex:outputField value="{!tripReport.Location_of_Meeting__c}" />
</apex:PageBlockSection>
</apex:PageBlock>

<apex:PageBlock id="opportunityItemBlock" title="Opportunities" mode="Edit">
<apex:PageMessage id="itemsMessage" summary="{!reportItemsMessage}" severity="error" strength="2" rendered="{!NOT(IsNull(reportItemsMessage))}" />
<apex:pageBlockButtons location="top">
<apex:commandButton value="Add Opportunity" immediate="true" action="{!addOpportunity}" status="addStatus" rerender="opportunityItemBlock" />
&nbsp;
<apex:actionStatus id="addStatus" startText="wait..."/>
</apex:pageBlockButtons>
<apex:PageblockTable id="itemList" value="{!opportunityItemListNotDeleted}" var="item" >
<apex:column width="40px" >
<apex:commandLink immediate="true" action="{!removeOpportunity}" status="removeStatus" rerender="opportunityItemBlock" type="image/png" >
<apex:image value="{Remove}" />
<apex:param name="lineno" assignTo="{!selectLineNumber}" value="{!item.lineNumber}"/>
</apex:commandLink>
&nbsp;<apex:actionStatus id="removeStatus" startText="wait..."/>
</apex:column>

<apex:column width="50px" >
<apex:facet name="header" >
<apex:outputText value="Line#" />
</apex:facet>
<apex:outputText value="{!item.lineNumber}" />
</apex:column>

<apex:column >
<apex:facet name="header" >
<apex:outputText value="Opportunity" />
</apex:facet>
<apex:InputField value="{!item.opportunity.Opportunity__c}" />
</apex:column>

<apex:column rendered="true">
<apex:facet name="header" >
<apex:outputText value="Company" />
</apex:facet>
<apex:OutputField value="{!item.opportunity.Opportunity__r.Account.Name}" rendered="true" />
</apex:column>

<apex:column rendered="true" >
<apex:facet name="header" >
<apex:outputText value="Type" />
</apex:facet>
<apex:OutputField value="{!item.opportunity.opportunity__r.Type}" rendered="true"/>
</apex:column>

<apex:column rendered="true" >
<apex:facet name="header" >
<apex:outputText value="Stage" />
</apex:facet>
<apex:OutputField value="{!item.opportunity.opportunity__r.StageName}" rendered="true"/>
</apex:column>

<apex:column rendered="true" >
<apex:facet name="header" >
<apex:outputText value="Amount" />
</apex:facet>
<apex:OutputField value="{!item.opportunity.opportunity__r.Amount}" rendered="true" />
</apex:column>

</apex:PageblockTable>

</apex:PageBlock>

</apex:form>
</apex:page>

 

Wrapper Class:

 

/**
* Purpose : This class is a supporting Data Transfer Objects for the Trip Report custom UI.
*/
public class OpportunityLineItem {

public Integer lineNumber{ get; set; }
public Boolean isDeleted{ get; set; }
public tripOpportunityAssociation__c opportunity { get; set;}

public opportunityLineItem(){
opportunity = new tripOpportunityAssociation__c();
lineNumber = 0;
isDeleted = false;
}

public OpportunityLineItem(Integer pLineNumber, tripOpportunityAssociation__c pOpportunityItem){
opportunity = pOpportunityItem;
lineNumber = pLineNumber;
isDeleted = false;
}
}

 

Snipets from Controller Extension:

 

/**
* Purpose : This class is a controller Extension for the Trip Report custom UI.
*/
public with sharing class TripRptExt {

public TripRptExt() {

}

 

.....

 

private List<TripOpportunityAssociation__c> opportunityList {
get{
List<TripOpportunityAssociation__c> returnValue = new List<TripOpportunityAssociation__c>();
if(opportunityList == null && reportId != null) {
returnValue = TripRptManager.getOpportunitiesForReport(reportId);
}
return returnValue;
}
set;
}

//List of wrapper objects.
private List<OpportunityLineItem> opportunityLineItemList{
get{
if (opportunityLineItemList == null){
opportunityLineItemList = new List<opportunityLineItem>();

//Only loaded on isUpdate.
if (isUpdate){

for(TripOpportunityAssociation__c opportunity : opportunityList ){
opportunityLineCount ++;
OpportunityLineItem lineItem = new OpportunityLineItem( opportunityLineCount , opportunity);
opportunityLineItemList.add(lineItem);
}
}
}
return opportunityLineItemList;
}
set;
}

 

.....

 

The TripRptManager methods called are:

 

//Returns a list of Opportunity Associations for a trip report.
// di not Change the relalationship name between the
//TripOpportunityAssociation__c and the Trip_Report__c back to the default.
//The parent lookup field on the child should be named:
//Trip_Report__c NOT Trip_Opportunity__c This is the report field
public static List<TripOpportunityAssociation__c> getOpportunitiesForReport(Id reportId){

return [SELECT
Id
,Trip_Opportunity__c
,Opportunity__c
,Opportunity__r.name
,Opportunity__r.Type
,Opportunity__r.Amount
,Opportunity__r.Account.Name
,Opportunity__r.StageName
//,Opportunity.EstimatedCloseDate__c
FROM
TripOpportunityAssociation__c
WHERE
Trip_Opportunity__c = :reportId
];
}

...  The one for the prefered approach but not incorporated yet due to syntax errors on page

 

public static List<Opportunity> refreshOpportunities(Id opportunityId){

return [SELECT
Id
,Name
,Type
,Amount
,Account.Name
,StageName
FROM
Opportunity
WHERE
Opportunity.Id = :opportunityId
];
}

 

-----------------------------------------------------

 

If you have any suggestions or just a model of something similar, I would greatly appreciate it.

 

Thanks.