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
NeedHelp55NeedHelp55 

Command button is not working

hi i am trying to call a apex method from a command button but it's not woring.attached the class and page below.

 

Details: a output panel with id "panelId" is render when one clicks on Edit button. In the output panel i have written a command button Save which should call a apex method saveRec . but when i clicked the button the method is not getting called , i have debuged it. Please help!!

------------------------------------------------------page-------------------------------------------------------------

<apex:page controller="noteListView" tabStyle="Quick_Note__c" sidebar="false" id="pdId">

<script>
function deleteARow(recordId){
actionFunc1(recordId);
}
function editARow(recordId){
actionFunc2(recordId);

</script>

<apex:form id="formId">
<apex:pageMessages id="pgmsg"/>
<apex:actionfunction name="actionFunc1" action="{!deleteRec}" rerender="pb,proxy">
<apex:param name="recId" id="paramId" value=""/>
</apex:actionFunction>

<apex:actionfunction name="actionFunc2" action="{!editRec}" rerender="panelId,proxy">
<apex:param name="recId" id="param1Id" value=""/>
</apex:actionFunction>

<apex:sectionHeader title="Case Note" subtitle="Home"/>

<b>View: </b>

<apex:selectList value="{!timeSpan}" multiselect="false" size="1" >
<apex:selectOptions value="{!items}"/>
</apex:selectList>

<apex:commandButton value=" Go " action="{!fetchDataBase}" rerender="pb"/>

<apex:pageBlock id="pb">

<apex:pageBlockTable value="{!noteList}" var="perNote" id="pbt1" rendered="{!IF(noteList.size>0,True,False)}">
<apex:column style="width:80px">
<apex:facet name="header">Action</apex:facet>
<apex:commandLink value="Edit" onclick="editARow('{!perNote.id}');" rerender="proxy"/>
&nbsp; | &nbsp;
<apex:commandLink value="Del" onclick="deleteARow('{!perNote.id}');" rerender="proxy"/>
&nbsp; |
</apex:column>

<apex:column value="{!perNote.Name}"/>
<apex:column value="{!perNote.Notes__c}"/>
<apex:column value="{!perNote.Long_Note__c}"/>
</apex:pageBlockTable>

</apex:pageBlock>

<apex:outputpanel id="panelId">
<apex:pageBlock title="Case Note Edit" rendered="{!isEdit}">
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!saveRec}" rerender="proxy,pb,panelId"/>
</apex:pageBlockButtons> 
<apex:pageBlockSection >
<apex:inputField value="{!noteRec.Notes__c}"/>
<apex:inputField value="{!noteRec.Long_Note__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputpanel>

</apex:form>

</apex:page>

------------------------------------------------------------class----------------------------------------------------------

public class noteListView {

public List<Quick_Note__c> noteList{get;set;}
public String soqlQuery{get;set;}
public String timeSpan{get;set;}
//public String selectedRecordId
public Quick_Note__c noteRec{get;set;}
//public Quick_Note__c toUpdate{get;set;}
public Boolean isEdit{get;set;}

public noteListView(){
noteList = new List<Quick_Note__c>();
fetchDataBase();
isEdit = false;
}

public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Top 50 Notes','Top 50 Notes'));
options.add(new SelectOption('Notes Last Week','Notes Last Week'));
options.add(new SelectOption('Notes Last Month','Notes Last Month'));
return options;
}

public void fetchDataBase(){

System.debug('Method called');

if(timeSpan == 'Top 50 Notes'){
soqlQuery = 'Select Id,Name,Notes__c,Long_Note__c from Quick_Note__c Limit 50 OFFSET 0';
}else if(timeSpan == 'Notes Last Week'){
soqlQuery = 'Select Id,Name,Notes__c,Long_Note__c from Quick_Note__c WHERE LastModifiedDate = LAST_N_DAYS:7';
}else{
soqlQuery = 'Select Id,Name,Notes__c,Long_Note__c from Quick_Note__c WHERE LastModifiedDate = LAST_N_DAYS:30';
}

noteList = DataBase.Query(soqlQuery);

system.debug('List Size'+noteList.Size());

}

public void deleteRec(){
String recordId = Apexpages.currentPage().getParameters().get('recId');
system.debug('Delete Id:::'+recordId);
List<Quick_Note__c> deleteId = [select Id from Quick_Note__c where Id =:recordId];
system.debug('Size::'+deleteId.size());
delete deleteId[0];
fetchDataBase();
}

public void editRec(){
system.debug('Method Called');
String recordId = Apexpages.currentPage().getParameters().get('recId');
noteRec = [Select Id,Name,Notes__c,Long_Note__c from Quick_Note__c where Id =:recordId];
isEdit = true;
system.debug('value ::::::::'+noteRec.Id);
Apexpages.currentPage().getParameters().put('recId',noteRec.Id);
}

public void saveRec(){
System.debug('Method Called - Save ::');
/*try{
upsert noteRec;
}catch(DMLException e){
ApexPages.addMessages(e);
}*/
isEdit = false;
}

}

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Usually when I hit this problem, its because there is an error that I am swallowing - lack of required fields or validation rules for example.

 

Try adding the pagemessages id "pgmsg" to the list of components to rerender - that will display any errors.

All Answers

bob_buzzardbob_buzzard

Usually when I hit this problem, its because there is an error that I am swallowing - lack of required fields or validation rules for example.

 

Try adding the pagemessages id "pgmsg" to the list of components to rerender - that will display any errors.

This was selected as the best answer
NeedHelp55NeedHelp55

Bingo!!! problemo solved. Thanks bob :)