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
SFDC n12SFDC n12 

vf page

Hi,

I am having 2 VF pages which shares the same controller

I want to consolidate these 2 VF page into a single one , Please help me how to do it


VF PAGE 1 :

<apex:page controller="AF_AccountExtension">
   <apex:form >
    <apex:pageMessages >
    </apex:pageMessages>

    <apex:pageBlock id="exRepTable">
        <apex:pageBlockTable value="{!exMyRepList}"  var="exRep">
          <apex:column headerValue="Action">
                <apex:commandLink target="_blank" value="Generate Report" action="{!generateReport}" styleClass="btn" style="color:Black;text-decoration:none">
                    <apex:param name="repLink" value="{!exRep.Report_Link__c}" assignTo="{!repLink}"/>
                    <apex:param name="acPDN" value="{!accnt.Ally_Primary_Dealer_Number__c}" assignTo="{!acPDN}"/>
                    <apex:param name="repName" value="{!exRep.Id}" assignTo="{!repName}"/>
                    <apex:param name="storageLocation" value="{!exRep.Storage_Location__c}" assignTo="{!storageLocation}"/>
                    <apex:param name="FileName" value="{!exRep.FileNameFilter__c}" assignTo="{!fileNameFilter}"/>
                    <apex:param name="extension" value="{!exRep.FileName_Extension__c}" assignTo="{!fileNameExtension}"/>
                </apex:commandLink>
            </apex:column>
          
            <apex:column headerValue="Name">
                <apex:outputLink value="/{!exRep.Id}" target="_blank">{!exRep.Name}</apex:outputLink>
            </apex:column>
            <apex:column headerValue="Report Description" value="{!exRep.Short_Description__c}"/>
            <apex:column headerValue="Primary Contact" value="{!exRep.Primary_Contact__c}"/>


        </apex:pageBlockTable>
      
      
    </apex:pageBlock>
</apex:form>
</apex:page>

VF PAGE 2 :

<apex:page controller="AF_AccountExtension">
   <apex:form >
    <apex:pageMessages >
    </apex:pageMessages>

    <apex:pageBlock id="exRepTable">
        <apex:pageBlockTable value="{!exPivotRepList}" var="exRep">
          <apex:column headerValue="Action">
                <apex:commandLink target="_blank" value="Generate Report" action="{!generateReport}" styleClass="btn" style="color:Black;text-decoration:none">
                    <apex:param name="repLink" value="{!exRep.Report_Link__c}" assignTo="{!repLink}"/>
                    <apex:param name="acPDN" value="{!accnt.Ally_Primary_Dealer_Number__c}" assignTo="{!acPDN}"/>
                    <apex:param name="repName" value="{!exRep.Id}" assignTo="{!repName}"/>
                    <apex:param name="storageLocation" value="{!exRep.Storage_Location__c}" assignTo="{!storageLocation}"/>
                    <apex:param name="FileName" value="{!exRep.FileNameFilter__c}" assignTo="{!fileNameFilter}"/>
                    <apex:param name="extension" value="{!exRep.FileName_Extension__c}" assignTo="{!fileNameExtension}"/>
                </apex:commandLink>
            </apex:column>
          
            <apex:column headerValue="Name">
                <apex:outputLink value="/{!exRep.Id}" target="_blank">{!exRep.Name}</apex:outputLink>
            </apex:column>
            <apex:column headerValue="Report Description" value="{!exRep.Short_Description__c}"/>
            <apex:column headerValue="Primary Contact" value="{!exRep.Primary_Contact__c}"/>

        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

Those 2 highlighted lists are used in my controller


Please help me how to combine those 2 to one, so that if i click on the link related to 1st list only th e 1st list to be displayed not the second one

Thanks in advance
Best Answer chosen by SFDC n12
Deepak Kumar ShyoranDeepak Kumar Shyoran
It seems that you've used created two different page which display two different PageBlock Table. Why don't you use a single page to display multiple table.

You can bind some variable to the rendered Attribute of pageBlockTable which decide which of those table will be display on Page.

Try below code by declaring two/one new variable which is bind with rendered attribute of page block. Hope below code will help you.
<apex:page controller="AF_AccountExtension">
<apex:form >
<apex:pageMessages >
</apex:pageMessages>
<apex:pageBlock id="exRepTable" rendered="{!showRepTable}>
<apex:pageBlockTable value="{!exMyRepList}"  var="exRep">
<apex:column headerValue="Action">
<apex:commandLink target="_blank" value="Generate Report" action="{!generateReport}" styleClass="btn" style="color:Black;text-decoration:none">
<apex:param name="repLink" value="{!exRep.Report_Link__c}" assignTo="{!repLink}"/>
<apex:param name="acPDN" value="{!accnt.Ally_Primary_Dealer_Number__c}" assignTo="{!acPDN}"/>
<apex:param name="repName" value="{!exRep.Id}" assignTo="{!repName}"/>
<apex:param name="storageLocation" value="{!exRep.Storage_Location__c}" assignTo="{!storageLocation}"/>
<apex:param name="FileName" value="{!exRep.FileNameFilter__c}" assignTo="{!fileNameFilter}"/>
<apex:param name="extension" value="{!exRep.FileName_Extension__c}" assignTo="{!fileNameExtension}"/>
</apex:commandLink>
</apex:column>         
<apex:column headerValue="Name">
<apex:outputLink value="/{!exRep.Id}" target="_blank">{!exRep.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Report Description" value="{!exRep.Short_Description__c}"/>
<apex:column headerValue="Primary Contact" value="{!exRep.Primary_Contact__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:pageBlock id="exPivotRepTable" rendered="{!showPivotTable}">
<apex:pageBlockTable value="{!exPivotRepList}" var="exRep">
<apex:column headerValue="Action">
<apex:commandLink target="_blank" value="Generate Report" action="{!generateReport}" styleClass="btn" style="color:Black;text-decoration:none">
<apex:param name="repLink" value="{!exRep.Report_Link__c}" assignTo="{!repLink}"/>
<apex:param name="acPDN" value="{!accnt.Ally_Primary_Dealer_Number__c}" assignTo="{!acPDN}"/>
<apex:param name="repName" value="{!exRep.Id}" assignTo="{!repName}"/>
<apex:param name="storageLocation" value="{!exRep.Storage_Location__c}" assignTo="{!storageLocation}"/>
<apex:param name="FileName" value="{!exRep.FileNameFilter__c}" assignTo="{!fileNameFilter}"/>
<apex:param name="extension" value="{!exRep.FileName_Extension__c}" assignTo="{!fileNameExtension}"/>
</apex:commandLink>
</apex:column>      
<apex:column headerValue="Name">
<apex:outputLink value="/{!exRep.Id}" target="_blank">{!exRep.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Report Description" value="{!exRep.Short_Description__c}"/>
<apex:column headerValue="Primary Contact" value="{!exRep.Primary_Contact__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Please mark my answer as a best solution to your question to help others if it solves your problem.

All Answers

Kathir DevanKathir Devan
Hi,

Please go through the URL:

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_quick_start_wizard.htm
Deepak Kumar ShyoranDeepak Kumar Shyoran
It seems that you've used created two different page which display two different PageBlock Table. Why don't you use a single page to display multiple table.

You can bind some variable to the rendered Attribute of pageBlockTable which decide which of those table will be display on Page.

Try below code by declaring two/one new variable which is bind with rendered attribute of page block. Hope below code will help you.
<apex:page controller="AF_AccountExtension">
<apex:form >
<apex:pageMessages >
</apex:pageMessages>
<apex:pageBlock id="exRepTable" rendered="{!showRepTable}>
<apex:pageBlockTable value="{!exMyRepList}"  var="exRep">
<apex:column headerValue="Action">
<apex:commandLink target="_blank" value="Generate Report" action="{!generateReport}" styleClass="btn" style="color:Black;text-decoration:none">
<apex:param name="repLink" value="{!exRep.Report_Link__c}" assignTo="{!repLink}"/>
<apex:param name="acPDN" value="{!accnt.Ally_Primary_Dealer_Number__c}" assignTo="{!acPDN}"/>
<apex:param name="repName" value="{!exRep.Id}" assignTo="{!repName}"/>
<apex:param name="storageLocation" value="{!exRep.Storage_Location__c}" assignTo="{!storageLocation}"/>
<apex:param name="FileName" value="{!exRep.FileNameFilter__c}" assignTo="{!fileNameFilter}"/>
<apex:param name="extension" value="{!exRep.FileName_Extension__c}" assignTo="{!fileNameExtension}"/>
</apex:commandLink>
</apex:column>         
<apex:column headerValue="Name">
<apex:outputLink value="/{!exRep.Id}" target="_blank">{!exRep.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Report Description" value="{!exRep.Short_Description__c}"/>
<apex:column headerValue="Primary Contact" value="{!exRep.Primary_Contact__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:pageBlock id="exPivotRepTable" rendered="{!showPivotTable}">
<apex:pageBlockTable value="{!exPivotRepList}" var="exRep">
<apex:column headerValue="Action">
<apex:commandLink target="_blank" value="Generate Report" action="{!generateReport}" styleClass="btn" style="color:Black;text-decoration:none">
<apex:param name="repLink" value="{!exRep.Report_Link__c}" assignTo="{!repLink}"/>
<apex:param name="acPDN" value="{!accnt.Ally_Primary_Dealer_Number__c}" assignTo="{!acPDN}"/>
<apex:param name="repName" value="{!exRep.Id}" assignTo="{!repName}"/>
<apex:param name="storageLocation" value="{!exRep.Storage_Location__c}" assignTo="{!storageLocation}"/>
<apex:param name="FileName" value="{!exRep.FileNameFilter__c}" assignTo="{!fileNameFilter}"/>
<apex:param name="extension" value="{!exRep.FileName_Extension__c}" assignTo="{!fileNameExtension}"/>
</apex:commandLink>
</apex:column>      
<apex:column headerValue="Name">
<apex:outputLink value="/{!exRep.Id}" target="_blank">{!exRep.Name}</apex:outputLink>
</apex:column>
<apex:column headerValue="Report Description" value="{!exRep.Short_Description__c}"/>
<apex:column headerValue="Primary Contact" value="{!exRep.Primary_Contact__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

Please mark my answer as a best solution to your question to help others if it solves your problem.
This was selected as the best answer
SFDC n12SFDC n12
Hi,

What changed to i need to make in my controller


Below is my controller

CONTROLLER CODE :

public class AF_AccountExtension
{

    public Account ac{get;set;}
    public ApexPages.StandardController controller{get; set;}
    public List<Account> acList{get; set;}
    private String acId;
    private String contUrl='';
    private String opType='';
    private String opName='';
    private String ownerId='';
    private String recordTypeId='';
    private String userObj='';
   
    //External Reports
    public List<External_Reports__c> exRepList{get; set;}
    public String repLink{get; set;}
    public String acPDN{get; set;}
    public Account accnt{get; set;}
    public String repName{get;set;}
    public String storageLocation{get; set;}
    public String fileNameFilter{get;set;}
    public String Roles{get;set;}
    public String fileNameExtension{get; set;}

    public List<External_Reports__c> exRegionalRepList{get; set;}
    public List<External_Reports__c> exPivotRepList{get; set;}
    public List<External_Reports__c> exMyRepList{get; set;}
    public List<External_Reports__c> exUSRepList{get; set;}
    private User usr;

    /**
    **
    **/
    public void getusers()
    {
     usr = AF_DealerCRM_Utility.getUserInfo();

    }
   
    /**
    **   Constructor
    **/
   
    public AF_AccountExtension() {
   
        usr = AF_DealerCRM_Utility.getUserInfo();
        System.debug ('user: ' + usr);
        exRepList = new List<External_Reports__c>();

     //   if (System.label.AF_AuthorizedToViewMyReports.contains (usr.profile.name) ) {
       
           Map<String,String> m = new Map<String ,String>();
           m.put('AF: Account Executive','AE');
           m.put('AF: GRC','GRC');
           m.put('AF: RVP','RVP');
           m.put('AF: Director of Sales','DOS');
             
           String url1 = m.get(usr.profile.name);
       
           for (External_Reports__c er: [SELECT Name,Profile__c, Role__c,Report_Link__c,Short_Description__c,
                                                Primary_Contact__c,Storage_Location__c,FileNameFilter__c,
                                                FileName_Extension__c, Display_Page__c
                                         FROM External_Reports__c
                                         WHERE isActive__c = true and FileNameFilter__c != 'PDN']) {
                                        
              String s1 = usr.userRole.Name;
              System.debug ('the user role is ' + s1);
              boolean roleExists = false;
          
              if (s1 != null) {
                 System.debug ('user role is not null : ' + usr.userRole.Name);
                 s1 = usr.userRole.Name.replace('\'', '');
                 roleExists = true;
              }
          
              // if this report is role specific
              if (er.Role__c != null && roleExists) {
                 System.debug ('verifying user role match : ' + er.id);
                 // if the logged in user has a role that matches the external report's role
                 if (s1.contains(er.Role__c)) {
                    system.debug('role : '+ er.Role__c);
                    exRepList.add(er);
                    System.debug ('Added to list: ' + er.Name);
                 }
              }
              else {
                 // not role specific report.check if it is available at the profile level
                 if (er.Profile__c.equals('All')) {
                    exRepList.add (er);
                 }
                 if (url1 != null && er.Profile__c.contains(url1)) { 
                    exRepList.add (er);
                 }
              }
           }
       // }

        exRegionalRepList = new List<External_Reports__c>();
        exPivotRepList = new List<External_Reports__c>();
        exMyRepList = new List<External_Reports__c>();
        exUSRepList = new List<External_Reports__c>();
       
        Set<String> myReportsSet = new Set<String>();
       
        // set the reports that should be displayed on other pages
        for (External_Reports__c erc: exRepList) {

           if (erc.display_page__c != null && erc.display_page__c.contains('Pivots')) {
              System.debug ('Display Page (Pivots)' + erc.display_page__c);
              exPivotRepList.add (erc);
           }
           if (erc.display_page__c != null && erc.display_page__c.contains('My')) {
              System.debug ('Display Page (MyReports)' + erc.display_page__c);
              exMyRepList.add (erc);
              myReportsSet.add (erc.name);
           }
           if (erc.display_page__c != null && erc.display_page__c.contains('US')) {
              System.debug ('Display Page (USReports)' + erc.display_page__c);
              exUSRepList.add (erc);
           }
           if (erc.display_page__c != null && erc.display_page__c.contains('Regional Reports')) {
              if (!myReportsSet.contains(erc.name)) {
                 System.debug ('Display Page (Regional)' + erc.display_page__c);
                 exRegionalRepList.add (erc);
              }
           }
        }

        if ( exRegionalRepList.size() == 0 && ApexPages.currentPage().GetURL().contains('Regional') ) {
         /*  exMyRepList.clear();
           exMyRepList.addAll (exRegionalRepList);
         */
           Apexpages.addMessage(new apexpages.message(Apexpages.Severity.ERROR,System.Label.AF_Home_Page_Reports));
        }
        if ( exPivotRepList.size() == 0 && ApexPages.currentPage().GetURL().contains('Pivot') ) {
           /*exMyRepList.clear();
           exMyRepList.addAll (exPivotRepList);
           */
           Apexpages.addMessage(new apexpages.message(Apexpages.Severity.ERROR,System.Label.AF_Home_Page_Reports));
        }
        if ( exMyRepList.size() == 0 && ApexPages.currentPage().GetURL().contains('My') ) {
           Apexpages.addMessage(new apexpages.message(Apexpages.Severity.ERROR,System.Label.AF_Home_Page_Reports));
        }
        if ( exUSRepList.size() == 0 && ApexPages.currentPage().GetURL().contains('US') ) {
           /*exMyRepList.clear();
           exMyRepList.addAll (exUSRepList);*/
           Apexpages.addMessage(new apexpages.message(Apexpages.Severity.ERROR,System.Label.AF_Home_Page_Reports));
        }
    }
      

    /**
    **
    **/   
    public AF_AccountExtension(ApexPages.StandardController controller)
    {
       if(usr == null)
       {
         getusers();
       }
        acId = ApexPages.currentPage().getParameters().get('acId');
        contUrl = ApexPages.currentPage().getParameters().get('newUrl');
        opType = ApexPages.currentPage().getParameters().get('opType');

        this.controller = controller;
        ac = (Account)controller.getRecord();
        accnt = [Select Ally_Primary_Dealer_Number__c from Account where Id=:ac.Id];
        exRepList = [Select Name,Role__c,Profile__c,Report_Link__c,Short_Description__c,Primary_Contact__c,
                            Storage_Location__c,FileNameFilter__c, FileName_Extension__c, Display_Page__c
                     FROM External_Reports__c
                     WHERE isActive__c = true AND FileNameFilter__c = 'PDN'];
  
   }
   
    /**
    **
    **/   
   
    public PageReference getNearByAccounts()
    {
        ac = [Select Name,ShippingLatitude,ShippingLongitude from Account where Id = :acId];
       
        try
        {
            acList = AF_DealerCRM_HelperClass.getNearByAccounts(ac.ShippingLatitude,ac.ShippingLongitude);
        }
        catch(Exception e)
        {
            System.debug('Query Exception'+e.getMessage());
        }
        return null;
    }

    /**
    **
    **/   
   
    public pageReference navigateToAccount()
    {
       PageReference pg = new PageReference('/'+acId);
       pg.setRedirect(true);
       return pg;
    }

    /**
    **
    **/   
   
    public pageReference contOpp()
    {  
        String finalUrl = ApexPages.currentPage().getHeaders().get('Host');
        system.debug('finalUrl****'+finalUrl);
       
        if(opType == 'Retail' || opType == 'Remarketing/SmartAuction' || opType == 'Insurance')
        {  
            finalUrl = 'https://'+finalUrl.substring(2,6)+'.salesforce.com'+contUrl;
        }
        else if(opType == 'Loans' || opType == 'Wholesale/Floorplan' || opType == 'contact' || opType == 'threat' || opType == 'ci' || opType == 'activity' || opType == 'case')
        {
            finalUrl = contUrl;
        }
        PageReference pg = new PageReference(finalUrl);
        return pg;
    }

    /**
    **
    **/  

    public PageReference generateReport() {
  
        PageReference pg = null;        
        System.debug (' ProfileName: ' + usr.Profile.Name);
        System.debug ('Link (Before): ' + repLink );
       
        if (repLink != null ) {
           System.debug ('storage location : ' + storageLocation);
          
           if ( fileNameFilter == 'PDN') {
              if (storageLocation  == 'Cognos') {
                 repLink += '&p_p_PDN=' + acPDN;
              }
             else if (storageLocation == 'Teamroom') {
                 repLink += '/' + acPDN + '.' + fileNameExtension;
              }
           }
           // Applies to both team room and cognos
           else if (fileNameFilter == 'Employee Number') {
               repLink +=  '/' + usr.EmployeeNumber + '.' + fileNameExtension;
               System.debug ('repLinkEmployeeNumber : ' + repLink );
           }
          
      
              
           else if (fileNameFilter == 'Employee HR ID') {
               repLink +=  '/' + usr.Employee_HR_ID__c + '.' + fileNameExtension;
               System.debug (' repLinkEmployeeHRId : ' + repLink );
           }
              
           else if (fileNameFilter == 'No Filter') {
               // no changes needed for the link
               System.debug (repLink );
           }
                  
           System.debug ('Link (After): ' + repLink );
              
           system.debug('Report Name****'+repName);
           External_Reports_Log__c er = new External_Reports_Log__c(Report_Name__c = repName,User__c = UserInfo.getUserId(),Report_generated_time__c = System.now());
           List<External_Reports_Log__c> extRepLogList = new List <External_Reports_Log__c>();
           extRepLogList.add (er);
          
           try {
                AF_DealerCRM_DML_Utility.insert_op (extRepLogList);
           }
           catch (system.DMLException e) {
              System.debug ('DML Exception'+e.getDMLMessage(0));
              return null;   
           }
           pg = new PageReference(repLink);
        }
        
        return pg;
       
   }

}

Thanks in Advance
SFDC n12SFDC n12
I am capturing those as a custom link in salesforce , when i click on the first link only that one should be displayed , but now if i click on the first the first and the second list is displayed
Deepak Kumar ShyoranDeepak Kumar Shyoran
Add these lines in your controller

// Variable to decide when to display First table
public Boolean showRepTable { get; set;}

// Variable to decide when to display Second table
public Boolean showPivotTable { get; set; }

you can easily set value for in your controller by getting parameter from you page
SFDC n12SFDC n12
Hi,

i got this one in a getter and setter methods

// Variable to decide when to display First table
public Boolean showRepTable { get; set;}

// Variable to decide when to display Second table
public Boolean showPivotTable { get; set; }

you can easily set value for in your controller by getting parameter from you page


In my controller how do i set the parameters for it,

like 
showRepTable = true;

is that right or h ow do i do it.


Thanks
Deepak Kumar ShyoranDeepak Kumar Shyoran
Yes same way you can Set a the value for above variable when a particular condition is satisfied.

Please mark my answer as a best solution to your question to help others if it solves your problem.