+ Start a Discussion
louisa barrett 7louisa barrett 7 

VF page not showing after deployment

Hi,

I just deployed my first VF page and associated Apex Class. The validation and deployment were all successful and if I open the developer console in the live org I can see the VF page and APEX class and test class. When I go to the Account Page layout though in the live org to add the VF page there is no option for VisualForce Pages. It's all working fine and displaying in the Sandbox.
The page simply gets all of the open opportunities for accounts where the Parent Account is equal to the account that is currently being displayed.
This is my code that is working in the Sandbox

VF Page:
<apex:page sidebar="false" showHeader="false" Controller="ChildOpportunitiesAP">
   <apex:form >
          <apex:pageBlock title="Open child opportunities" id="pb"> 
              Filter:
              <apex:selectList value="{! selectListValue }" size="1">
                  <apex:selectOptions value="{!availableFilters}"/>
                  <apex:actionSupport event="onchange" action="{!refresh}" reRender="pb"/>
              </apex:selectList>
          <apex:pageBlockTable value="{!RelatedOpportunities}" var="opp">
              <apex:column >
                  <apex:facet name="header"> 
                      <apex:commandLink action="{!sortByAccountName}"
                                    reRender="pb">Account Name
                      </apex:commandLink>
                  </apex:facet>    
                     <apex:outputLink value="/{! opp.Account.id}" target="_top">
                                {!opp.Account.Name}
                     </apex:outputLink>     
               </apex:column>
              <!--<apex:column value="{! opp.Account.Name}" >
                  <apex:facet name="header"> 
                      <apex:commandLink action="{!sortByAccountName}"
                                    reRender="pb">Account Name
                      </apex:commandLink>
                  </apex:facet>        
               </apex:column>-->
              <apex:column >
                  <apex:facet name="header"> 
                      <apex:commandLink action="{!sortByOpportunityName}"
                                    reRender="pb">Opportunity Name
                      </apex:commandLink>
                  </apex:facet>    
                     <apex:outputLink value="/{! opp.id}" target="_top">
                                {!opp.Name}
                     </apex:outputLink>     
               </apex:column>
              <!--<apex:column value="{! opp.Name}">
                  <apex:facet name="header">
                  <apex:commandLink action="{!sortByOpportunityName}"
                                    reRender="pb">Opportunity Name
                      </apex:commandLink>
                  </apex:facet>
              </apex:column>-->
              <apex:column value="{! opp.Total_Opportunity_Amount__c}">
                  <apex:facet name="header">
                  <apex:commandLink action="{!sortByAmount}"
                                    reRender="pb">Total Opportunity Amount
                      </apex:commandLink>
                  </apex:facet>
              </apex:column>
              <apex:column value="{! opp.StageName}">
                  <apex:facet name="header">
                  <apex:commandLink action="{!sortByStage}"
                                    reRender="pb">Stage
                      </apex:commandLink>
                  </apex:facet>
              </apex:column>
          </apex:pageBlockTable>
        <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!controller.first}" disabled="{!!controller.hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!controller.previous}" disabled="{!!controller.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!controller.next}" disabled="{!!controller.hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!controller.last}" disabled="{!!controller.hasNext}" title="Last Page"/>
                <apex:outputText >{!(controller.pageNumber * size)+1-size}-{!IF((controller.pageNumber * size)>noOfRecords, noOfRecords,(controller.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                </apex:outputPanel>
            </apex:panelGrid>
    </apex:pageBlock>
  </apex:form>
</apex:page>

APEX page:

public with sharing class ChildOpportunitiesAP {
    private id Parent_Acc_Id;
    Public Integer noOfRecords{Get;Set;}
    Public Integer size {get;Set;}
    public String selectListValue{get;Set;}
    private String sortColumn = 'Name';
    private String previousSortColumn = null;
    private String sortOrder = 'ASC';
     
          public ApexPages.StandardSetController controller {
                    get{
                 Parent_Acc_Id = ApexPages.currentPage().getparameters().get('id');
                        system.debug('ChildOpps-Test:' + Parent_Acc_Id);
                        if(controller == null){
                            system.debug('ChildOpps-Test-2');
                            size = 4;
                            string queryString = '';
                             system.debug(' Before query - Sort order = ' + sortColumn);
                            if (selectListValue == 'All') {
                                system.debug('ChildOpps-Test-3');
                                queryString = 'SELECT Account.Name, Name, Total_Opportunity_Amount__c, StageName ' +
                                ' FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id AND IsWon = False ORDER BY ' + sortColumn + ' ' + sortOrder;
                            }
                            else {
                                system.debug('ChildOpps-Test-4');
                                queryString = 'SELECT Account.Name, Name, Total_Opportunity_Amount__c, StageName ' +
                                ' FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id AND IsWon = False AND Name =: selectListValue ORDER BY ' + sortColumn + ' ' + sortOrder ;
                            }
                            system.debug(queryString);
                            system.debug(Parent_Acc_Id);
                                 controller = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                        controller.setPageSize(size);
                            noOfRecords = controller.getResultSize();
             }
             return controller;                              
            }set;
        }
    
    public ChildOpportunitiesAP() {
        selectListValue = 'All';
    }
    
        public List<Opportunity> getRelatedOpportunities(){
                        List <Opportunity> childOpps = New List<Opportunity>();
        FOR(Opportunity opp:(List<Opportunity>)controller.getRecords())
            childOpps.add(opp);
                 Return childOpps;   
         }
    
        public pageReference refresh(){
            controller = null;
            /*getRelatedOpportunities();*/
            controller.setPageNumber(1);
            return null;
        }  
    
    public List<selectOption> getAvailableFilters(){
        List<selectOption> options = new List<SelectOption>();
        List<Opportunity> availableOpps = new List<Opportunity>();
        availableOpps = [SELECT Account.Name, Name, Total_Opportunity_Amount__c, StageName FROM Opportunity WHERE IsWon = False AND Account.Parent.id=: Parent_Acc_Id];
        options.add(new SelectOption('All','All'));
        
        Set<Id> accountIdSet = new Set<Id>();
        for (Opportunity opp:availableOpps){
            if(!accountIdSet.contains(opp.accountID)) {
                options.add(new SelectOption(opp.AccountId, opp.Account.Name));
                accountIdSet.add(opp.AccountId);
            }
        }
        return options;
    }
    
    Public pageReference getFilteredOpportunities(){
        /*getRelatedOpportunities();*/
        controller.setPageNumber(1);
        return Null;
    }
    
    public pageReference sortByAccountName() {
        setSortOrder('Account.Name');
        return Refresh();
    }
    
    public pageReference sortByOpportunityName(){
        setSortOrder('Name');
         return Refresh();
    }
    
    public pageReference sortByAmount(){
        setSortOrder('Total_Opportunity_Amount__C');
        return Refresh();
    }
      
    public pageReference sortByStage() {
        setSortOrder('StageName');
        return Refresh();
    }
    
    private void setSortOrder(string columnName){
        sortColumn = columnName;
        if (previousSortColumn == sortColumn){
            sortOrder = 'DESC';
            previousSortColumn = null;
        }
        else{
            previousSortColumn = sortColumn;
            sortOrder = 'ASC';
        }        
    }
}

Could you someone offer some advice please

Thanks
Best Answer chosen by louisa barrett 7
RaidanRaidan
Just change the constructor from 
 
public ChildOpportunitiesAP() {
    selectListValue = 'All';
}

to
public ChildOpportunitiesAP(ApexPages.StandardController ctrl) {
    //set the parent account id here
    Parent_Acc_Id = ctrl.getId();

    selectListValue = 'All';
}

In this case you also set the account Id through the controller.

All Answers

RaidanRaidan
Hi Louisa,

I think you need to use a Standard Controller in your VFP to be able to add the page to the Account Layout. The page will look like this:
 
<apex:page sidebar="false" showHeader="false" StandardController="Account" extensions="ChildOpportunitiesAP">
You probably will have to tweak the controller code later.
 
Nitin Wader 21Nitin Wader 21
Please check account page layout and see which layout you have added button for VF page
louisa barrett 7louisa barrett 7
Hi,
I thought that could be the issue as when I first created the page and class I was using a standard account controller, but then changed it over several attempts to get it working.
When I change it back to StandardController = "Account" Extensions = "ChildOpportunitiesAP" I get an unknown contructor error.
I'm not sure how to fix that given I'm using a StandardSetController in the APEX code
louisa barrett 7louisa barrett 7
I only have one Account page layout in both the live and sandbox. The ChildOpportunities VF page isn't launched from a button, it simply displays as a section within the Accounts page.
RaidanRaidan
Just change the constructor from 
 
public ChildOpportunitiesAP() {
    selectListValue = 'All';
}

to
public ChildOpportunitiesAP(ApexPages.StandardController ctrl) {
    //set the parent account id here
    Parent_Acc_Id = ctrl.getId();

    selectListValue = 'All';
}

In this case you also set the account Id through the controller.
This was selected as the best answer
louisa barrett 7louisa barrett 7
You are an absolute star, thank you.
All tested, validated and deployed :)