• Infu
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
i wonder if someone could help me please.
My Filter list is being populated, but I'm not sure how you pass the value of the SelectList value back to the controller, so the results are filtered appropriately.
I've looked at a lot of examples and they all have a Get;Set property for he value but I cannot see on any of them where that is actually being set.

Apex Code:

public with sharing class ChildOpportunitiesAP {
    private id Parent_Acc_Id;
    private string selectedValue;
    Public Integer noOfRecords{Get;Set;}
    Public Integer size {get;Set;}
    public String selectListValue{get;Set;}
    
          public ApexPages.StandardSetController controller {
                    get{
                 Parent_Acc_Id = ApexPages.currentPage().getparameters().get('id');
                        if(controller == null){
                            size = 4;
                            string queryString = 'SELECT Account.Name, Name, Total_Opportunity_Amount__c ' +
                                ' FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id';
                                 controller = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                        controller.setPageSize(size);
                            noOfRecords = controller.getResultSize();
             }
             return controller;                              
            }set;
        }
    
         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 FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id];
        FOR(Opportunity opp: availableOpps)
        {
           options.add(new SelectOption(opp.Account.name, opp.account.name));
        }
       
        return options;
    }
    }


VF Page:
<apex:page sidebar="false" showHeader="false" Controller="ChildOpportunitiesAP">
   <apex:form >
          <apex:pageBlock title="Linked child opportunities" id="pb"> 
              Filter:
              <apex:selectList value="{! selectListValue }" size="1">
                  <apex:selectOptions value="{!availableFilters}"/>
                  <apex:actionSupport event="onchange" reRender="pb"/>
              </apex:selectList>
          <apex:pageBlockTable value="{! RelatedOpportunities}" var="opp">
              <apex:column value="{! opp.Account.Name}"/>
              <apex:column value="{! opp.Name}"/>
              <apex:column value="{! opp.Total_Opportunity_Amount__c}"/>
          </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>

What I also don't understand is why I can't filter the list directly, or cycle through the relatedOpportunities method as that already contains the relavant results, rather than having to hit the DB again.
So something like:
 FOR(Opportunity opp: getRelatedOpportunities)
        {
           options.add(new SelectOption(opp.Account.name, opp.account.name));
        }

Many thanks for any help
       

 
Hi,

i have one SOQL query like 
SELECT id FROM businesshours WHERE Name = 'UK'
Is it possible to get using dynamic apex...........................

Adv Thnx
VSK
  • April 25, 2016
  • Like
  • 1
i wonder if someone could help me please.
My Filter list is being populated, but I'm not sure how you pass the value of the SelectList value back to the controller, so the results are filtered appropriately.
I've looked at a lot of examples and they all have a Get;Set property for he value but I cannot see on any of them where that is actually being set.

Apex Code:

public with sharing class ChildOpportunitiesAP {
    private id Parent_Acc_Id;
    private string selectedValue;
    Public Integer noOfRecords{Get;Set;}
    Public Integer size {get;Set;}
    public String selectListValue{get;Set;}
    
          public ApexPages.StandardSetController controller {
                    get{
                 Parent_Acc_Id = ApexPages.currentPage().getparameters().get('id');
                        if(controller == null){
                            size = 4;
                            string queryString = 'SELECT Account.Name, Name, Total_Opportunity_Amount__c ' +
                                ' FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id';
                                 controller = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                        controller.setPageSize(size);
                            noOfRecords = controller.getResultSize();
             }
             return controller;                              
            }set;
        }
    
         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 FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id];
        FOR(Opportunity opp: availableOpps)
        {
           options.add(new SelectOption(opp.Account.name, opp.account.name));
        }
       
        return options;
    }
    }


VF Page:
<apex:page sidebar="false" showHeader="false" Controller="ChildOpportunitiesAP">
   <apex:form >
          <apex:pageBlock title="Linked child opportunities" id="pb"> 
              Filter:
              <apex:selectList value="{! selectListValue }" size="1">
                  <apex:selectOptions value="{!availableFilters}"/>
                  <apex:actionSupport event="onchange" reRender="pb"/>
              </apex:selectList>
          <apex:pageBlockTable value="{! RelatedOpportunities}" var="opp">
              <apex:column value="{! opp.Account.Name}"/>
              <apex:column value="{! opp.Name}"/>
              <apex:column value="{! opp.Total_Opportunity_Amount__c}"/>
          </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>

What I also don't understand is why I can't filter the list directly, or cycle through the relatedOpportunities method as that already contains the relavant results, rather than having to hit the DB again.
So something like:
 FOR(Opportunity opp: getRelatedOpportunities)
        {
           options.add(new SelectOption(opp.Account.name, opp.account.name));
        }

Many thanks for any help
       

 
Hello, how do I test add.Error ?

This is my trigger trigger 

trigger CannotDeleteMQL on Event (before delete){
  for (Event e : Trigger.old){
    if (e.MQL__c=='Yes'){
      e.addError('You can\'t delete a MQL');
    }
  }
}

I tried this test class but it doesn't work: 

@isTest
public with sharing class CannotDeleteMQLTest {

     @isTest
    public static void cannotDeleteMQLTest () {
        
        // Event creation 
        Event e = new Event(
            Subject ='Fake Event',
            MQL__c = 'Yes',
            StartDateTime = datetime.newInstance(2014, 9, 15, 12, 30, 0),
            EndDateTime = datetime.newInstance(2014, 9, 15, 13, 30, 0)
        );

        try
           {
               Delete e;
            }
           catch(Exception z) 
           {    
                System.Assert(z.getMessage().contains('You can\'t delete a MQL!'));
            }

    }
}