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
Dileep KumarDileep Kumar 

How I will call controller method from selectList ?

Hi All


<apex:selectList id="actionsList" multiselect="false" size="1">
                        <apex:selectOption itemValue="--None--" itemLabel="--None--" />  
                        <apex:selectOption itemValue="Edit" itemLabel="Edit"/>
                        <apex:selectOption itemValue="Delete" itemLabel="Delete" />
                        <apex:selectOption itemValue="VAT+" itemLabel="VAT+"  >
                            <apex:actionSupport event="onchange" action="{!applyVat}" reRender="masterPanel">
                            <apex:param value="{!er.entry.id}" assignTo="{!EntryToUpdate}"/>
                            </apex:actionSupport>
                        </apex:selectOption> 
</apex:selectList>


public void applyVat(){
        Id toUpdate = ApexPages.currentPage().getParameters().get('EntryToUpdate');
        Ledger_Entry__c leEntry= [select Id,Apply_Vat__c,Type__c,Disbursement__c,DisbValAndVat__c from Ledger_Entry__c where id = :toUpdate];
        if(leEntry.Apply_Vat__c==false && calculateVat=='VAT+'){
            leEntry.Apply_Vat__c=true;
            update leEntry;
        }
}

Thanks in Advance,

Dileep Kumar

Victor FelisbinoVictor Felisbino
You are doing it correctly by calling the function in the apex:actionSupport.
Try changing the return value of your method to PageReference and add a return null in the end.

public PageReference applyVat(){
        Id toUpdate = ApexPages.currentPage().getParameters().get('EntryToUpdate');
        Ledger_Entry__c leEntry= [select Id,Apply_Vat__c,Type__c,Disbursement__c,DisbValAndVat__c from Ledger_Entry__c where id = :toUpdate];
        if(leEntry.Apply_Vat__c==false && calculateVat=='VAT+'){
            leEntry.Apply_Vat__c=true;
            update leEntry;
        }
    return null;
}

also, make sure you are rerendering the right pageblock or outputpanel in order to see any updates in the page. To troubleshoot that and make sure the error is not within your method, remove the rerender and see if it works (with the pagereference the entire page should reload.)

sometimes creating a public string, just for troubleshooting also helps, just to make sure the panels are being rerendered correctly and the method is also being called and the variables are being assigned the values you expect.

public String testString{get;set;}
public void applyVat(){
    Id toUpdate = ApexPages.currentPage().getParameters().get('EntryToUpdate');
//assign values to your test string    
testString = toUpdate;
        Ledger_Entry__c leEntry= [select Id,Apply_Vat__c,Type__c,Disbursement__c,DisbValAndVat__c from Ledger_Entry__c where id = :toUpdate];
         testString += ' apply_vat__c: '+leEntry.Apply_Vat__c+ ' calculateVat: '+calculateVat);
        if(leEntry.Apply_Vat__c==false && calculateVat=='VAT+'){
            leEntry.Apply_Vat__c=true;
            update leEntry;
        }
}

print the value of {!testString} in your visualforce and you will be able to troubleshoot.