0

I am trying to pass from my JS to my controller and in the console log, All the values appear correctly. When I check the controller they are all null.

I have looked it over 1000 Times. It could be a small mistake that I'm not seeing anymore because I've looked at it so much. Any direction would be great.

Here is my VF:

 <apex:form>.....
 HTML here.....

 <apex:actionFunction name="SaveFunc" action="{!AutoSave}">
      <apex:param name="Cid" value="" />
      <apex:param name="Amount" value="" />
      <apex:param name="Feed" value="" />
  </apex:actionFunction>
    </apex:form>

<script>
function Asave(Cid, Eid){
    console.log(Cid);
    console.log(Eid);
SaveFunc(
      Cid,
    document.getElementById(Eid).value,
    'Blank'
    );
}
function Fsave(Cid, Eid){
 SaveFunc(
      Cid,
    'Blank',
   document.getElementById(Eid).value
    );

}

</script>

Here is the code from my controller:

   public PageReference AutoSave(){
    string CMid = Apexpages.currentPage().getParameters().get('Cid');
    string Amount = Apexpages.currentPage().getParameters().get('Amount');
    String Feedback = Apexpages.currentPage().getParameters().get('Feed');
        system.debug(CMid);
        system.debug(Amount);
        system.debug(FeedBack);
        CampaignMember c = New Campaignmember();
        c.id = CMid;
        if(Amount != 'Blank'){
        c.Call_Debit__c = decimal.valueOf(Amount);
            update c;}
        if(Feedback != 'Blank'){
        c.Feedback__c = Feedback;
        update c;
        }

        return null;
    }

Thanks in advanced.

3
  • Are you trying to pass them as URL parameters?
    – highfive
    Apr 16, 2014 at 17:06
  • No, Im trying to pass them through the actionfunction
    – AlphaBravo
    Apr 16, 2014 at 17:06
  • If when you look at the SaveFunc generated in your page it is missing any parameters, you could try this work-around laceysnr.com/2010/11/…. The pattern you are using is not something I've ever tried or seen so there may be other problems.
    – Keith C
    Apr 16, 2014 at 17:21

1 Answer 1

2

Use assignto attribute in <apex:param />. Apexpages.currentPage().getParameters().get('Cid') is for reading URL parameters, but you are not trying to pass them as like that. Try updating your code as below.

<apex:actionFunction name="SaveFunc" action="{!AutoSave}">
      <apex:param name="Cid" value="" assignTo="{!CMid}" />
      <apex:param name="Amount" value="" assignTo="{!Amount}" />
      <apex:param name="Feed" value="" assignTo="{!Feedback}" />
  </apex:actionFunction>

And keep your controller variables public so that the page can access them.

public class Your_Controller{
    string CMid {get;set;}
    string Amount {get;set;}
    String Feedback {get;set;}

    public PageReference AutoSave(){    
        system.debug(CMid);
        system.debug(Amount);
        system.debug(FeedBack);

        ...
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .