0

I have a requirement where if the profile value on the picklist is changed then need to call a delete API.

Approach which I have followed to check the current and the previous values of the picklist using javascript function and call the controller method from action function, which is passing the changed picklist value from vf page to the controller and which I am using to call the API from the controller.

I have written a function which capture the profile values before and after update on the vf page.

Function:

    (function () {
             var prevVal;
             var currVal;
            $("[id$='ProfileChangeEvent']").on('focus', function () {
               prevVal = this.value;
             }).change(function() {
            currVal = this.value;
            alert('old val:: '+prevVal);
            alert('new val:: '+currVal);
         if (prevVal != currVal){
              alert('Condition Satisfied');
              alert('current val:: '+currVal);                                                              
              CallAPIFunction(currVal);

           } 

      });
    })();

This function works successfully and calling the action function.

        <apex:actionFunction name="CallAPIFunction" action="{!CallDeleteAPI}">
        <apex:param value="" assignTo="{!currentValue1}" name="currentValue1" />
 </apex:actionFunction>

This action function is further calling the controller method "CallDeleteAPI" and I am passing the currentValue from page to this method.

public class myClass
{
    public string currentValue1{get; set;}

    public PageReference CallDeleteAPI()
    {

       System.debug('*******picklist value after Update*****'+currentValue1);
       PageReference pg = Page.demo;
       myAPIClass.doDelete(currentValue1);
       pg.getParameters().put('id', currentProject.Id);
       pg.setRedirect(true); 
       return pg;
    }
}

But the issue is the value of currentValue1 is coming null in the CallDeleteAPI() from the action function due to which my API method doDelete() not invoking.

Also, I can achieve the picklist previous value and the current values using configuration but I would like to go with the coding approach.

Can somebody please help me to understand what's going wrong here?

0

To make actionFunction to be fully workable you need to add rerender attribute in the actionFunction, then only it will work correctly.

 <apex:actionFunction name="CallAPIFunction" action="{!CallDeleteAPI}" rerender="<what you want to rerender like form, or panel>">
        <apex:param value="" assignTo="{!currentValue1}" name="currentValue1" />
 </apex:actionFunction>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.