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
Skip KSkip K 

Method not called from commandLink in a pageBlockTable

In my pageblocktable I have expand/collapse functionality that mostly works. The one issue I'm having is that it doesn't make the call to setExpandCollapse when I have one expanded and try to expand another (I don't see my debug messages in the consoleUser-added image). Any help would be greatly appreciated.

<apex:column style="vertical-align:top">
             <apex:outputpanel id="outputpanel">
                       <apex:commandLink action="{!setExpandCollapse}" rerender="outputpanel, inlinetablesec" rendered="{!!expandCollapse}" immediate="true">
                        <apex:outputtext value="{!opp.oppList.size} Product(s)"/>
                        <apex:param assignTo="{!expandCollapseTF}" value="true" name="expandCollapseTF"/>
                        <apex:param assignTo="{!expandCollapseOppId}" value="{!opp.o.Id}" name="expandCollapseOppId"/>
                           <apex:image url="{!$Resource.Plus_Image}"  title="Expand - Product List"/>
                       </apex:commandLink>

                       <apex:commandLink action="{!setExpandCollapse}" rerender="outputpanel, inlinetablesec" rendered="{!expandCollapse}" immediate="true">
                        <apex:outputtext value="{!opp.oppList.size} Product(s)"/>
                        <apex:param assignTo="{!expandCollapseTF}" value="false" name="expandCollapseTF"/>
                        <apex:param assignTo="{!expandCollapseOppId}" value="{!opp.o.Id}" name="expandCollapseOppId"/>
                           <apex:image url="{!$Resource.Minus_Image}"  title="Collapse - Product List"/>
                       </apex:commandLink>
            </apex:outputpanel>
                    </apex:column>

public void setExpandCollapse() {
  System.debug('++++++++++++++++++++++++++++++++++++++++++++++');
  expandCollapseOppId = ApexPages.currentPage().getParameters().get('expandCollapseOppId');
  expandCollapseTF = boolean.valueOf(ApexPages.currentPage().getParameters().get('expandCollapseTF'));
  System.debug('++++++++++++++++expandCollapseOppId++++++++++++++++++++++++++++++'+expandCollapseOppId);
  System.debug('++++++++++++++++expandCollapseTF++++++++++++++++++++++++++++++'+expandCollapseTF);
  expandCollapseMap.put(expandCollapseOppId, expandCollapseTF);
  System.debug('expandCollapseMap------'+expandCollapseMap);
}
Best Answer chosen by Skip K
Skip KSkip K
So I figured out my problem (with some help). It involved my rendered attribute on the commandLink:
                      <apex:commandLink action="{!setExpandCollapse}" rerender="outputpanel, inlinetablesec" rendered="{!!expandCollapse}" immediate="true">
                        <apex:outputtext value="{!opp.oppList.size} Product(s)"/>
                        <apex:param assignTo="{!expandCollapseTF}" value="true" name="expandCollapseTF"/>
                        <apex:param assignTo="{!expandCollapseOppId}" value="{!opp.o.Id}" name="expandCollapseOppId"/>
                        <apex:image url="{!$Resource.Plus_Image}"  title="Expand - Product List"/>
                     </apex:commandLink>
I didn't know that the expandCollapseOppId param would only get assigned once. I changed my rendered="{!!expandCollapseMap[opp.o.Id]}" and made the necessary changes on the controller to make it work.

All Answers

SFDC_DevloperSFDC_Devloper
Hi,

   Please paste complete code ....


Thanks,
Rockzz
Skip KSkip K
<apex:page tabstyle="Opportunity" controller="OpportunityMassUpdate" sidebar="false">


<style type="text/css">
  .alignTop {
   vertical-align: top;
  }

</style>

<apex:form id="form" >
<apex:pageMessages />
    <apex:pageblock id="pageBlock">

  <apex:pageBlockButtons >
      <apex:commandButton action="{!save}" value="Save" rerender="pbt"/>
      <apex:commandButton action="{!save}" value="Save & Continue" rerender="pbt"/>
      <apex:commandButton action="{!cancel}" value="Cancel"/>
  </apex:pageBlockButtons>
      
        <apex:pageblocktable id="pbt" value="{!opportunityList}"  var="opp" columnsWidth="20%,8%,8%,8%,8%,8%,8%,32%">
            <apex:column style="vertical-align:top">
    <apex:facet name="header"> 
     <apex:commandLink action="{!sortOppData}">
      <apex:outputtext value="Opportunity Name"/>
      <apex:image url="{!$Resource.Sort_Up}" style="vertical-align:bottom" title="Ascending" rendered="{!oSortDirection=='ASC' && oSortExpression=='name'}"/>
      <apex:image url="{!$Resource.Sort_Down}" style="vertical-align:bottom" title="Descending" rendered="{!oSortDirection=='DESC' && oSortExpression=='name'}"/>
      <apex:param value="name" name="column" assignTo="{!oSortExpression}" ></apex:param>
     </apex:commandLink>
    </apex:facet>
    <apex:outputlink value="/{!opp.o.Id}">{!opp.o.Name}</apex:outputlink>
            </apex:column>
                    <apex:column style="vertical-align:top">
             <apex:outputpanel id="outputpanel">
                       <apex:commandLink action="{!setExpandCollapse}" rerender="pageblock, outputpanel, inlinetablesec" rendered="{!!expandCollapse}" immediate="true">
                        <apex:outputtext value="{!opp.oppList.size} Product(s)"/>
                        <apex:param assignTo="{!expandCollapseTF}" value="true" name="expandCollapseTF"/>
                        <apex:param assignTo="{!expandCollapseOppId}" value="{!opp.o.Id}" name="expandCollapseOppId"/>
                           <apex:image url="{!$Resource.Plus_Image}"  title="Expand - Product List"/>
                       </apex:commandLink>

                       <apex:commandLink action="{!setExpandCollapse}" rerender="pageblock, outputpanel, inlinetablesec" rendered="{!expandCollapse}" immediate="true">
                        <apex:outputtext value="{!opp.oppList.size} Product(s)"/>
                        <apex:param assignTo="{!expandCollapseTF}" value="false" name="expandCollapseTF"/>
                        <apex:param assignTo="{!expandCollapseOppId}" value="{!opp.o.Id}" name="expandCollapseOppId"/>
                           <apex:image url="{!$Resource.Minus_Image}"  title="Collapse - Product List"/>
                       </apex:commandLink>
            </apex:outputpanel>
                    </apex:column>
            <apex:column style="vertical-align:top">
             <apex:facet name="header"> 
     <apex:commandLink action="{!sortOppData}" value=" Amount ACV{!IF(oSortExpression=='Amount_ACV__c','','')}" >
      <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oSortDirection=='ASC' && oSortExpression=='Amount_ACV__c'}"/>
      <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oSortDirection=='DESC' && oSortExpression=='Amount_ACV__c'}"/>
      <apex:param value="Amount_ACV__c" name="column" assignTo="{!oSortExpression}" ></apex:param>
     </apex:commandLink>
    </apex:facet>           
             <apex:outputpanel rendered="{!opp.oppList.size == 0}">
              <apex:inputField value="{!opp.o.Amount_ACV__c}"/>
             </apex:outputpanel>
             <apex:outputpanel rendered="{!opp.oppList.size > 0}">
              <apex:outputtext style="color: #c0c2c4" value="{!opp.o.Amount_ACV__c}"/>
             </apex:outputpanel>
            </apex:column>
            <apex:column style="vertical-align:top">
             <apex:facet name="header"> 
     <apex:commandLink action="{!sortOppData}" value="Close Date{!IF(oSortExpression=='CloseDate','','')}" >
      <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oSortDirection=='ASC' && oSortExpression=='CloseDate'}"/>
      <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oSortDirection=='DESC' && oSortExpression=='CloseDate'}"/>
      <apex:param value="CloseDate" name="column" assignTo="{!oSortExpression}" ></apex:param>
     </apex:commandLink>
    </apex:facet>           
             <apex:inputField value="{!opp.o.CloseDate}"/>
            </apex:column>
            <apex:column style="vertical-align:top">
             <apex:facet name="header"> 
     <apex:commandLink action="{!sortOppData}" value="Probability{!IF(oSortExpression=='Probability','','')}" >
      <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oSortDirection=='ASC' && oSortExpression=='Probability'}"/>
      <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oSortDirection=='DESC' && oSortExpression=='Probability'}"/>
      <apex:param value="Probability" name="column" assignTo="{!oSortExpression}" ></apex:param>
     </apex:commandLink>
    </apex:facet>           
             <apex:inputField value="{!opp.o.Probability}"/>
            </apex:column>
            <apex:column style="vertical-align:top">
             <apex:facet name="header"> 
     <apex:commandLink action="{!sortOppData}" value="Stage{!IF(oSortExpression=='StageName','','')}" >
      <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oSortDirection=='ASC' && oSortExpression=='StageName'}"/>
      <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oSortDirection=='DESC' && oSortExpression=='StageName'}"/>
      <apex:param value="StageName" name="column" assignTo="{!oSortExpression}" ></apex:param>
     </apex:commandLink>
    </apex:facet>           
             <apex:inputField value="{!opp.o.StageName}"/>
            </apex:column>
            <apex:column style="vertical-align:top">
             <apex:facet name="header"> 
     <apex:commandLink action="{!sortOppData}" value="Status{!IF(oSortExpression=='Status__c','','')}" >
      <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oSortDirection=='ASC' && oSortExpression=='Status__c'}"/>
      <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oSortDirection=='DESC' && oSortExpression=='Status__c'}"/>
      <apex:param value="Status__c" name="column" assignTo="{!oSortExpression}" ></apex:param>
     </apex:commandLink>
    </apex:facet>           
             <apex:inputField value="{!opp.o.Status__c}"/>
            </apex:column>
          
          
            <apex:column style="vertical-align:top" breakBefore="true">
             <apex:outputtext value="  "/>
            </apex:column>
            <apex:column style="vertical-align:top" colspan="4">
             <apex:outputpanel id="inlinetablesec"  >
                 <apex:variable value="{!0}" var="rowNum"/>
                 <apex:repeat var="count" value="{!opp.oppList}">
                     <apex:variable var="rowNum" value="{!rowNum+1}"/>
                 </apex:repeat>
                 <apex:outputText rendered="{!rowNum==0}">  No Products  </apex:outputText>
                 <apex:pageblocktable value="{!opp.oppList}" var="op" rendered="{!expandCollapse}" >
               
                     <apex:column >
                   
                <apex:facet name="header"> 
        <apex:commandLink action="{!sortOppData}" value="Product Name{!IF(oliSortExpression=='PricebookEntry.Product2.Name','','')}" >
         <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oliSortDirection=='ASC' && oliSortExpression=='PricebookEntry.Product2.Name'}"/>
         <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oliSortDirection=='DESC' && oliSortExpression=='PricebookEntry.Product2.Name'}"/>
         <apex:param value="PricebookEntry.Product2.Name" name="column" assignTo="{!oliSortExpression}" ></apex:param>
        </apex:commandLink>
       </apex:facet>           
                         <apex:outputLink value="/{!op.PricebookEntry.Product2.Id}">{!op.PricebookEntry.Product2.Name}</apex:outputLink>
                      </apex:column>
                    
                      <apex:column >
                <apex:facet name="header"> 
        <apex:commandLink action="{!sortOppData}" value="Price{!IF(oliSortExpression=='UnitPrice','','')}" >
         <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oliSortDirection=='ASC' && oliSortExpression=='UnitPrice'}"/>
         <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oliSortDirection=='DESC' && oliSortExpression=='UnitPrice'}"/>
         <apex:param value="UnitPrice" name="column" assignTo="{!oliSortExpression}" ></apex:param>
        </apex:commandLink>
       </apex:facet>           
                         <apex:inputField value="{!op.UnitPrice}"/>
                      </apex:column>
                                       
                      <apex:column >
                       <apex:facet name="header">
        <apex:commandLink action="{!sortOppData}" value="Quantity{!IF(oliSortExpression=='Quantity','','')}" >
         <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oliSortDirection=='ASC' && oliSortExpression=='Quantity'}"/>
         <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oliSortDirection=='DESC' && oliSortExpression=='Quantity'}"/>
         <apex:param value="Quantity" name="column" assignTo="{!oliSortExpression}" ></apex:param>
        </apex:commandLink>
       </apex:facet>
                         <apex:inputField value="{!op.Quantity}"/>
                      </apex:column>
                                        
                      <apex:column >
                       <apex:facet name="header">
        <apex:commandLink action="{!sortOppData}" value="Total{!IF(oliSortExpression=='TotalPrice','','')}" >
         <apex:image url="{!$Resource.Sort_Up}" title="Ascending" rendered="{!oliSortDirection=='ASC' && oliSortExpression=='TotalPrice'}"/>
         <apex:image url="{!$Resource.Sort_Down}" title="Descending" rendered="{!oliSortDirection=='DESC' && oliSortExpression=='TotalPrice'}"/>
         <apex:param value="TotalPrice" name="column" assignTo="{!oliSortExpression}" ></apex:param>
        </apex:commandLink>
       </apex:facet>
                         <apex:outputText value="{!op.TotalPrice}"/>
                      </apex:column>
                                             
                 </apex:pageblocktable>
            </apex:outputpanel>   
            </apex:column>

        </apex:pageblocktable>
    </apex:pageblock>
    </apex:form>
</apex:page>




public with sharing class OpportunityMassUpdate {

//private Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>();
private boolean sorting = false;
public Id expandCollapseOppId { get; set; }
public boolean expandCollapseTF { get; set; }
private Map<Id, boolean> expandCollapseMap = new Map<Id, boolean>();

private boolean expandCollapse;
public boolean getExpandCollapse() {

 expandCollapse = expandCollapseMap.get(expandCollapseOppId);
  if (expandCollapse != null)
   return expandCollapse;
  else
   return false;
}
public void setExpandCollapse() {
  expandCollapseOppId = ApexPages.currentPage().getParameters().get('expandCollapseOppId');
  expandCollapseTF = boolean.valueOf(ApexPages.currentPage().getParameters().get('expandCollapseTF'));
  expandCollapseMap.put(expandCollapseOppId, expandCollapseTF);
}

Id userId = System.UserInfo.getUserId();

private List<ShowOpportunities> opportunityList = new List<ShowOpportunities>();
public List<ShowOpportunities> getOpportunityList() {
   
  opportunityList = new List<ShowOpportunities>();

  List<OpportunityLineItem> oppLIList = Database.query('SELECT Id, Opportunity.Id, UnitPrice, Quantity, TotalPrice, PricebookEntry.Product2.Name, Opportunity.CloseDate ' +
           'FROM OpportunityLineItem ' +
           'WHERE Opportunity.isClosed = false AND Opportunity.OwnerId = :userId ' +
           'ORDER BY ' + oliSortFullExp + ' limit 1000');               

  List<Opportunity> oppList = Database.query('SELECT Id, Amount_ACV__c, CloseDate, Probability, StageName, Status__c, Name ' +
          'FROM Opportunity ' +
          'WHERE OwnerId = :userId ' +
          'AND isClosed = false ' +
          'ORDER BY ' + oSortFullExp + ' limit 1000');
        
  List<OpportunityLineItem> tempList = new List<OpportunityLineItem>();           
  ShowOpportunities opps = new ShowOpportunities();
  for ( Opportunity opp : oppList ) {
 
   opps = new ShowOpportunities();

   for (OpportunityLineItem oli : oppLIList) {
    if (oli.OpportunityId == opp.Id) {
     opps.oppList.add(oli);
     if (sorting) {
      expandCollapseMap.put(opp.Id, false);
     }    
    }
  
    opps.o = opp;
    //opps.expand = 'false';
   }
   opportunityList.add(opps);
  }
  return opportunityList;       
}
public void save() {
  //save changes
  sorting = false;
  List<Opportunity> oppListForSave = new List<Opportunity>();
  List<OpportunityLineItem> oliListForSave = new List<OpportunityLineItem>();
  for (ShowOpportunities so : opportunityList) {
   oppListForSave.add(so.o);
 
   for (OpportunityLineItem oli : so.oppList) {
    oliListForSave.add(oli);
   }
  }

  if (!oppListForSave.isEmpty())
   update oppListForSave;
 
  if (!oliListForSave.isEmpty())
   update oliListForSave;

}
public void cancel() {
  //cancel changes

}
public class ShowOpportunities {

  public List<OpportunityLineItem> oppList = new List<OpportunityLineItem>();
  public List<OpportunityLineItem> getOppList () {
   return oppList;
  }
  public Opportunity o { get; set; }

}

public PageReference sortOppData () {
  sorting = true;
  oSortFullExp = oSortExpression  + ' ' + oSortDirection;
  oliSortFullExp = oliSortExpression  + ' ' + oliSortDirection;
  getOpportunityList();
  return null;
}
//some sorting code omitted due to character limit
Skip KSkip K
So I figured out my problem (with some help). It involved my rendered attribute on the commandLink:
                      <apex:commandLink action="{!setExpandCollapse}" rerender="outputpanel, inlinetablesec" rendered="{!!expandCollapse}" immediate="true">
                        <apex:outputtext value="{!opp.oppList.size} Product(s)"/>
                        <apex:param assignTo="{!expandCollapseTF}" value="true" name="expandCollapseTF"/>
                        <apex:param assignTo="{!expandCollapseOppId}" value="{!opp.o.Id}" name="expandCollapseOppId"/>
                        <apex:image url="{!$Resource.Plus_Image}"  title="Expand - Product List"/>
                     </apex:commandLink>
I didn't know that the expandCollapseOppId param would only get assigned once. I changed my rendered="{!!expandCollapseMap[opp.o.Id]}" and made the necessary changes on the controller to make it work.
This was selected as the best answer