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
EfratDEfratD 

commandLink not working

Hello experts!

 

I am trying to use a standard command link functionality in my VF page but for some reason the controller function is not being called (I know this by putting debug messages).

 

Can you help me spot my rookie's mistake?

 

Page:

 

<apex:page standardController="My_Request__c" action="{!doSometing}"  extensions="My_Request_View_Override" title="My Request" showHeader="true" id="myPageID" cache="false">

 

<apex:form id="myFormID"  >

 

<apex:pageBlock title="Request Products">

 

    <apex:pageBlockTable value="{!My_Request__c.Products__r}" var="product">

 

        <apex:column headerValue="Action">

 

<apex:commandLink action="{!delProd}" onClick="return window.confirm('Are you sure?');"  rendered="{!My_Request__c.Stage__c = 'Draft'}" id="clDelId" value="Del">
                <apex:param value="{!product.Id}" name="pid" />
            </apex:commandLink>

 

</apex:column> 

</apex:pageBlockTable>
   
 </apex:pageBlock>
     
</apex:form>

 

</apex:page>

 

 

Controller function:

 

public PageReference delProd(){
   

    try{
        if(ApexPages.currentPage().getParameters().get('pid') != ''){
        if (productID != null){
            ID productID = ApexPages.currentPage().getParameters().get('pid');
            List<Product__c> n = [select id from Product__c where Id =: productID ];
            if(n.size() > 0){
                delete n;
            }
        }
    }catch(DmlException e){
       
        }
    }
   
    return new Pagereference('/'+record.Id);
}

 

Thanks a bunch!!!

 

Shashikant SharmaShashikant Sharma

First thing that I notices is that in apex:param you have assigned the parameter value to 

product.id , but in controller I see productID , i think if you will change 

 

product.id to productID in apex:param assignedTo will solve your issue, one more thing any assignedTo property should be a public property , please make sure your productID is public in controller.

 

try with above suggestion , Please let me know if any issue .

Sam27Sam27

One thing I noticed not usual in

 

<apex:commandLink action="{!delProd}" onClick="return window.confirm('Are you sure?');"  rendered="{!My_Request__c.Stage__c = 'Draft'}" id="clDelId" value="Del">
                <apex:param value="{!product.Id}" name="pid" />
            </apex:commandLink>

 was that for rendered you are using single "=" mark, whereas it's a boolean data type (true or false), hence for comparing you should use

rendered="{!My_Request__c.Stage__c == 'Draft'}"

I don't know if it's the real bone of contention. 

 

Regards

EfratDEfratD

Hi,

 

Thank you guys for your tips but I'm afraid the problem is deeper then that.

Even when removing all parameters and attributes and just leaving the below, the function in the controller is not getting called.

I know this because I have put debug printouts as the first line of the function and I can see they are not printed.

 

<apex:commandLink action="{!delProd}" id="clDelId" value="Del"/>

 

Somehow the commandLink is not getting associated with that function (or any other function I tried of that controller).

All other functionalities work perfectly, inlcuding the confirm pop up and the rendered option.

 

Any idea?

 

Thanks and regards,

EfratD

Shashikant SharmaShashikant Sharma

I think you should change your if condition like this 

 

 

if(ApexPages.currentPage().getParameters().get('pid') != null && ApexPages.currentPage().getParameters().get('pid') != ''){

This should work for you.

Shashikant SharmaShashikant Sharma

 

 In case it does not work 

There must be some exception in your code

Do one thing , either remove try catch block

or

 

 

Change your catch block to this 

public PageReference delProd(){
   
    try{
        if(ApexPages.currentPage().getParameters().get('pid') != null && ApexPages.currentPage().getParameters().get('pid') != ''){
        if (productID != null){
            ID productID = ApexPages.currentPage().getParameters().get('pid');
            List<Product__c> n = [select id from Product__c where Id =: productID ];
            if(n.size() > 0){
                delete n;
            }
        }
    }catch(DmlException e){
ApexPages.addMessages(e);
       
        }
    }
   
    return new Pagereference('/'+record.Id);
}

 also add a pageMessages control in your VFP

<apex:pageMessages id="msgs" />

Sam27Sam27

well everything seems fine to me....but as you said its not even attaching to the method......

 

might be some problem with 'return' statement. However it's a wild guess try to return some other pagereferences.

DivyA123DivyA123

Hi EfratD,


hav you got ur question's correct answer ?

i am getting the same problem.. searched alot.. its a salesforce issue i guess..

 

any help in this regard will be appreciated

 

regards

Divya

Aditya ShastriAditya Shastri


I have VF page with commandlink as
<apex:commandLink value="Policy" action="{!method2}" rerender="page"/>

Method in controller is
public void method2(){
//some DB operation
}

However the method does not get called ever. I tried putting debug statements. The same commandlink works from beginning of page.

Any ideas hwo to troubleshoot?