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
test269test269 

apex command button action command not working

Hi All,

  i have written following class for inserting and updating the record.in this updateledger method calling upsert command.when new record is inserted.this method not called.Can u please help me this.

public with sharing class newpagecontroller {
public void ledgerNewTable() {
ledgeradd = true;
}
public PageReference addLEdger() {
insert newledger;
newLedger = new Ledger__c();
return null;
}
public boolean ledgeradd{get;set;}
public string editid{get;set;}
public string updateid{get;set;}
public string delid{get;set;}
public string anum{get;set;}
public string aname{get;set;}
public string atype{get;set;}
public boolean addglopp{get;set;}
public Ledger__c newLedger { get; set; }
public Ledger__c ledgercreation { get; set; }
private List<Ledger__c> ledgertable;
public List<Ledger__c> getledgertable(){
ledgertable = [ SELECT Id,Name,Account_Name__c,Account_Number__c,Account_Type__c,Description__c,Notes__c,Sub_Account__c FROM Ledger__c where Id != null];
if(ledgeradd == true){
ledgertable.add(new Ledger__c());
}
ledgeradd =false;
return ledgertable;
}
public void setledgertable(List<Ledger__c> ledgertable){this.ledgertable= ledgertable;}


public list<Ledger__c> editLedger{get;set;}

public void editLedger() {
editid = ApexPages.currentPage().getParameters().get('editid');
editLedger = [ SELECT Id,Name,Account_Name__c,Account_Number__c,Account_Type__c,Description__c,Notes__c,Sub_Account__c FROM Ledger__c where Id =:editid];
}
public void updateLedger(){
System.debug('updateeeeeeeeeeeeeee');
upsert ledgertable;
}

}

 

 

Page:

<apex:page controller="newpage">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="General Ledgers" id="ledgerlist" columns="1">

<apex:pageBlockSectionItem >
<apex:inputcheckbox value="{!addglopp}">
<apex:actionsupport event="onchange" />
</apeX:inputCheckbox>
<apex:outputLabel value="Add GL Information to opportunities"></apex:outputLabel>
</apex:pageBlockSectionItem>

<apex:outputPanel id="glgr">
<apex:outputPanel rendered="{!addglopp}">

<apex:pageblocktable value="{!ledgertable}" var="lgredit" id="lgrtable" cellspacing="-10px" styleclass="datatables">
<apex:variable value="0" var="rowNumlgr"/>
<apex:column headerValue="Account Name">
<apex:outputField value="{!lgredit.Account_Name__c}" rendered="{!IF(lgredit.Id == editid ,false,true)}"/>
<apex:inputField value="{!lgredit.Account_Name__c}" rendered="{!IF(lgredit.Id == editid,true,false)}" styleClass="aname{!rowNumlgr}"/>
</apex:column>
<apex:column >
<apex:commandbutton action="{!editLedger}" value="Edit" rerender="glgr" rendered="{!IF(lgredit.Id == editid ,false,true)}" >
<apex:param name="editid" value="{!lgredit.Id}"/>
</apex:commandbutton>
<apex:commandbutton action="{!updateLedger}" value="Update" rendered="{!IF(lgredit.Id == editid ,true ,false)}"/ >
<apex:param name="updateid " value="{!lgredit.Id}"/>
</apex:column>

</apex:pageblocktable>
</apex:outputPanel>
</apex:outputPanel>
<apex:commandButton action="{!ledgerNewTable}" value="Add GL Account" rerender="glgr" rendered="{!addglopp}"/>
</apex:pageblocksection>
</apex:pageBlock>

</apex:form>
</apex:page>

 

 

Thanks in advance

Adam HowarthAdam Howarth

Hey,

 

I had a similar problem which turned out to be the output panel I was using. I, like you, had said to render it based on a value in the controller.

 

So change:

 

<apex:outputPanel rendered="{!addglopp}">

 

To:

 

<apex:outputPanel>

 

Let me know. I still dont know why it is happening though.

 

Cheers