+ Start a Discussion
DixitDixit 

Commandlink method (controller) in action not working

Hello, 

I have this commandlink on a visualforce page:
 
<apex:commandlink action="{!saveProdChanges}" rerender="Messages" value="Save" immediate="true" styleclass="buttonprod" onclick="console.log('click save')">
                                                                    <apex:param name="buttonsave" value="{!product.id}" id="saveParam" assignTo="{!saveProd}"/>                                                                  
                                            </apex:commandlink>

which calls this method on my controller:
public string saveProd {get; set;}

public pageReference saveProdChanges(){

producto_simulacion__c productoEdit = new producto_simulacion__c();
productoEdit = [SELECT Id, categoria__c, cantidad__c, importe__c, descripcion__c, costo_unitario__c FROM producto_simulacion__c WHERE id =: saveProd];

update productoEdit;
}
I edited so i can try the button, I also trying with just:
 
public pageReference saveProdChanges(){

system.debug('Hello, this is saveProdChanges method');

}

but is not doing anything when i press the button. Browser console is not showing any error, it's displaying correctly the console.log on it.
Log in developer console is not showing the debug, but it does a log when I click it....

What could be wrong?

 
Krishnamoorthi PeriasamyKrishnamoorthi Periasamy
Plese try see this example and try... If this answers is helful to solve your issue, please mark it as "Solved'. Thanks

VF page
======
<apex:page standardController="Contact" extensions="CommandLinkParamController">
<apex:form >
<apex:commandLink value="Process Nickname" action="{!processLinkClick}">
<apex:param name="nickName" value="{!contact.firstname}" assignTo="{!nickName}"/>
</apex:commandLink>
</apex:form>
</apex:page>

Controller:
========
public with sharing class CommandLinkParamController {

    // an instance variable for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // the object being referenced via url
    private Contact contact {get;set;}
    // the variable being set from the commandlink
    public String nickName {get; set;}

    // initialize the controller
    public CommandLinkParamController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        // load the current record
        this.contact = (Contact)controller.getRecord();

    }

    // handle the action of the commandlink
    public PageReference processLinkClick() {
        System.debug('nickName: '+nickName);
        // now process the variable by doing something...
        return null;
    }

}
Vinuthh SVinuthh S
Hi Dixit

Please remove the immediate = ''True" from the Outputlink and try the Same code.

Thanks
Vinuthh S
DixitDixit
I have already tried with "tue", "false" and removing all the statement and still not working. 

I have tried with a void statement in the method declaration and "public pageReference" with return null and still not working.
Vinuthh SVinuthh S
Hi Dixit

<apex:commandLink value="{!emp.Employee_ID__c}" action="{!showEmpDetails}" styleClass="hyperlink-text" reRender="theForm" title="Employee Edit" status="splashStatus">
                <apex:param name="empId" value="{!emp.Id}" assignTo="{!empId}"/>
</apex:commandLink>

public Id empId { get; set;} 

public void showEmpDetails() {
<!----Your logic ---->
}

This is sample code,its working in my org, Check ir.

Thanks
Vinuthh S
DixitDixit
I just edit the button to be alike the example and the method.... but it does nothing. 
Where " <!-- your logic -->" is i just have a "system.debug('hello');" and is not appearing in the log. 

When i click the link it generates a log, but it doesn't have the debug of the method.
DixitDixit
The button was part of a div who his parent div had a display condition (which in some cases was "none")... I read about it and the post said it can't be a button where all this conditions (condition on the parent of the button and the parent of the parent)... So i put the action on an "action function" and called the action support from jquery (the action function by itself didn't work either) when clicking and problem solved.