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
DannyK88DannyK88 

Apex Method not firing when called from a Visualforce page

HI Everyone,

I have been having a weird issue and I don't know where to turn. I have a visualforce component with a Apex Controller. The Compoenent has a Command Button on it and has a method linked to it. When I click the button the method does not seem to trigger. The page just seems to reload and call the controllers constructor. I'm not sure why this is happening. The same code was working yesterday. I did make some changes but when I look at the code I can't seem to find anything wrong. When I put a breakpoint at the beginnig of the Apex Method it doesn't look like the method is even called. The Visualforce compoent is embbeded in a visualforce page that has a controller of it's own. I have no clue as to what the issue is. If you have run into a simmialr situation please let me know what your solution was if you found one. I am running out of options and ideas.

Thanks,
Best Answer chosen by DannyK88
DannyK88DannyK88
I figured out what the issue was. I had some apex:inputtext in the component that I had disabled so that they coud just show the values. However for some reason they were causing me issues. Once I removed them and changed them to apex:outputtext everything working fine. I'm not sure why the disabled apex:inputtext fields caused me so much greif.

All Answers

Roy LuoRoy Luo
Check browser developer tools console (press F12 for chrome), also look at sfdc Developer Console. Likely you would see some clues.
DannyK88DannyK88
I have had the sfdc Developer Console open but I have found no usesful information. It might be be because I don't know exactly where to look. Is there a spesific place I should look for clues using both tools?
Roy LuoRoy Luo
any script error from the brower developer console?
DannyK88DannyK88
When I have the browser developer console open I get this error:  GET https://test.salesforce.com/javascript/1415089663000/sfdc/source/SessionServer190.js.map 404 (Not Found) test.salesforce.com/javascript/1415089663000/sfdc/source/SessionServer190.js.map:1
Parvinder SinghParvinder Singh
Put immediate=true on the command button, some time the request is blocked becasue of some pending ajax validations on the page.
DannyK88DannyK88
Ok so adding immediate=true to the command button made the method fire but it does not take into account a variable that was changed. I use a variable in some dynamic soql and when I change the variable and click the button it does not use the new value for the variable. 
Roy LuoRoy Luo
The variblae must be visible in the same scope of your dynamic soql. 
DannyK88DannyK88
Well the problem isn't that the dynamic soql statement causes an error or anything. I have a if statemtn that adds query logic to the end of the dynamic query if the variable has a certain value. When I change the value on the visualforce page and click the button it almost seems like the value doesn't change so the query logic is never added to the end of the dynaimc query.
Parvinder SinghParvinder Singh
Put apex action region around the fields that you want to be communicated back to the controller and remove the immediate='true' from the button.
Details - https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm
DannyK88DannyK88
I have put the variable into an action region like you said but that doesn't seem to work either. Here is how I but the variable into the action region:

<apex:actionRegion >
    <apex:inputField value="{!TempPlace.Pay_Frequency__c}"/>
</apex:actionRegion>
Parvinder SinghParvinder Singh
Sorry that did not help, did you remove the immediate='true' from the command button and make sure this action region and the button are in the same apex:form.
DannyK88DannyK88
Yes I removed the immediate='true' but when I do that the method does not trigger when I click the button. Also this is a visualforce component. I'm not sure if that helps or not but the button is in a visualforce component. All the components are on the same page in the same apex:form. 
DannyK88DannyK88
I figured out what the issue was. I had some apex:inputtext in the component that I had disabled so that they coud just show the values. However for some reason they were causing me issues. Once I removed them and changed them to apex:outputtext everything working fine. I'm not sure why the disabled apex:inputtext fields caused me so much greif.
This was selected as the best answer