0

I am having issues integrating a wrapper class generated in one controller/VF Page into another Visualforce Page displayed. With an action, the selected accounts generated by one VF Page would be inputted into another page with a different functionality. I am using a wrapper class to hold the list variables.

I have created 2 visual force pages which side by side act as a list generator - with select boxes identifying the selected accounts (a wrapper class) - and another visual force page which automatically mass generates an inputted list as opportunities.

And so here is the visual force page for the mass opportunity generator with 2 controllers (one of which simply saves/returns the page back)


I have a public class

AddmultipleOpportunitiesController

For visualforce page Which displays a table:

<apex:pageBlockTable value="{!listOpportunity}" var="acc">
        <apex:column headerValue="Opportunity Name">
        <apex:inputField value="{!acc.Name}"/>
        </apex:column>
        <apex:column headerValue="Opportunity Type">
        <apex:inputField value="{!acc.Type}"/>
        </apex:column>
        <apex:column headerValue="Stage">
        <apex:inputField value="{!acc.StageName}"/>
        </apex:column>
        <apex:column headerValue="Close Date">
        <apex:inputField value="{!acc.CloseDate}"/>
        </apex:column>
        </apex:pageBlockTable>
        <apex:pageBlockButtons >
        <apex:commandButton value="Add Opportunity Row" action="{!addOpportunity}" />
        <apex:commandButton value="Save Opportunity" action="{!saveOpportunity}" />
    

    </apex:pageBlockButtons>
        </apex:pageBlock>

With a button afterwards which SAVES each inputted line as an opportunity.

I am working with another class: public class MassEmailFromCampaign {

Which has a VF page which acts as an account search function and allows me to select the filtered results and store them into a wrapper class:


public List<cAccount> getresults()
{
return AccountList;
}
/* End of Method */
/* Wrapper class to contain contact record and a boolean flag */
public class cAccount
{
 public Account con {get; set;}
 public Boolean selected {get; set;}
/*This is the contructor method. When we create a new cContact object we pass a
 Contact that is set to the con property. We also set the selected value to false*/
 public cAccount(Account c)
 {
     con = c;
     selected = false;
 }
}
/* end of Wrapper class */

public PageReference processSelected()
{
List<Account> selectedAccounts = new List<Account>();
  if (AccountList!= null)
  {
     for(cAccount cCon : getresults()){
        if(cCon.selected == true){
             selectedAccounts.add(cCon.con);
         }
     }
}
 /* return error message if no contact is selected */
if (selectedAccounts.size()==0)
 {
     errormsg=true;
     return null;
}
else
 {
     errormsg=false;
     String id=System.currentpagereference().getparameters().get('id');
     Pagereference p=new Pagereference ('/apex/Deal_Contact2');
     return p;
}
}
public List<SelectOption> getItems()
{
 List<SelectOption> options = new List<SelectOption>();
 options.add(new SelectOption('YES','YES'));
 options.add(new SelectOption('NO','NO'));
 return options;
}
/* return error message if no contact is selected */
public boolean geterrormsg()
{
 return errormsg;
}

I would like this wrapper class to be input into the first visualforce page when a button is clicked.

Currently, the button is simply redirecting me towards a page which does not exit noted in the code as Deal_Contact2

I would like no page redirect, but simply a refresh, and an autopopulate into the first visual force page's UI.

All help is much appreciated.

  • Your nomenclature is very hard to follow and clearly does not line up with standard Salesforce. For instance, a trigger is apex event logic that kicks off when a DML Operation is fired. It has nothing to do with buttons. – Adrian Larson Aug 11 '15 at 19:19
  • 4
    Also this is way to much code and synopsis for most of us to read through, please try to trim this down so it is easier to digest what you are actually asking. – Adrian Larson Aug 11 '15 at 19:20
  • Without really understanding your problem, I'll mention that if you use the same controller class for both pages then the selections made in one page are available to the other page. – Keith C Aug 11 '15 at 19:31
  • @ Keith C - I will try and put together both of the controllers as to create one multi-purpose controller. However, the coding issues I am having are actually accessing the wrapper class (selected accounts from a list) - and having them inputted onto a visual force page list. – apolk Aug 11 '15 at 19:37
  • @AdrianLarson I cleaned the code a bit and tried to clarify my question – apolk Aug 12 '15 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.