1

hi i am sending some data to controller method through action function using jquery. but in controller method i am getting null value, please help. i am getting a response from ajax method and then want to send that response to controller method through action function. using apex:param but getting null values in debug

visualforce page

<apex:page controller="SendAgreementExt">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
   <form id="data" method="post" enctype="multipart/form-data">
     <apex:pageBlock >

   <apex:pageBlockSection showHeader="false" columns="2">
    <apex:pageBlockSectionItem >
        <apex:outputLabel value="File Name" for="fileName" />
   <input type="text" name="File-Name" value="" />
  <input type="hidden" name="Mime-Type" value="application/pdf" />
  </apex:pageBlockSectionItem>
  <apex:pageBlockSectionItem >
  <apex:outputLabel value="File" for="file" />
 <input name="File" type="file" />
 </apex:pageBlockSectionItem>
 </apex:pageBlockSection>
   <apex:pageBlockButtons >
        <button>Submit</button>
     </apex:pageBlockButtons>
        </apex:pageBlock>

    </form>


  <script type="text/javascript">
 $("form#data").submit(function(){

 var formData = new FormData($(this)[0]);

$.ajax({
url: 'https://api.na1.echosign.com/api/rest/v5/transientDocuments',
type: 'POST',
    headers: {'Access-Token' :'3AAABLblqZhCG8fU-alud8zcDf-N8I68P7yfB6nIi6U_PcCQsnobiSYzIpfzmgYaCMnl2PwcuVlSbk7yS_uNV8BkF8ymc3f2m'},
data: formData,
async: false,
success: function (data) {
     document.getElementById("myHiddendid").value = data.transientDocumentId;

     myFun(data.transientDocumentId);
    //SendAgreementExt.send(data);
},
cache: false,
contentType: false,
processData: false
 });

  return false;
 });
 </script>
 <apex:form >
 <input type="hidden" value="{!documentid}" id="myHiddendid"/>
  <apex:actionFunction name="myFun" action="{!send}">
   <apex:param name="myParam" value="" id="y" assignTo="{!documentid}" />
   </apex:actionFunction>
  </apex:form>
 </apex:page>

Controller

     Public with Sharing Class SendAgreementExt
  {


public string LeadMessage{get;set;}
 public string documentid{get; set;}
public string docid{get; set;}

public PageReference send()
{  
  System.debug('VARIABLE documentid------' + documentid);
                       documentid=Apexpages.currentPage().getParameters().get('documentid');
   System.debug('VARIABLE documentid------' + documentid);
  //system.debug('==in method');
 string passedParam1 =Apexpages.currentPage().getParameters().get('myParam');
 string passedParam2 =    system.CurrentPageReference().getParameters().get('myParam');
  system.debug(passedParam1);
  system.debug(passedParam2);

   return null;        
      }


   }   
1

You will have to reRender the elements on the page to set the values at backend

I would designate an Id with an outputPanel and reRender

<apex:page controller="SendAgreementExt" id="thePage">
   <apex:actionFunction name="myFun" action="{!send}" reRender="thePage">
       <apex:param name="myParam" value="" id="y" assignTo="{!documentid}"/>
   </apex:actionFunction>
</apex:page>
  • thanx it works. thankyou for the solution – Vishal Chaudhary May 20 '16 at 0:44
0

does rendring affect pagemessages as it not working because page is not reloading. i have set the pagemessages. does they have any relation with page reloading

visualforce page

                        <apex:page controller="SendAgreementExt" id="thepage" rendered="true">
                      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
                       <form id="data" method="post" enctype="multipart/form-data">
                         <apex:pageBlock >
                     <apex:pageMessages id="msg" >     </apex:pageMessages>
                       <apex:pageBlockSection showHeader="false" columns="2">
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="File Name" for="fileName" />
                       <input type="text" name="File-Name" value="" />
                      <input type="hidden" name="Mime-Type" value="application/pdf" />
                      </apex:pageBlockSectionItem>
                      <apex:pageBlockSectionItem >
                      <apex:outputLabel value="File" for="file" />
                     <input name="File" type="file" />
                     </apex:pageBlockSectionItem>
                     </apex:pageBlockSection>
                       <apex:pageBlockButtons >
                            <button>Submit</button>
                         </apex:pageBlockButtons>
                            </apex:pageBlock>

                        </form>


                      <script type="text/javascript">
                     $("form#data").submit(function(){

                     var formData = new FormData($(this)[0]);

                    $.ajax({
                    url: 'https://api.na1.echosign.com/api/rest/v5/transientDocuments',
                    type: 'POST',
                        headers: {'Access-Token' :'3AAABLblqZhCG8fU-alud8zcDf-N8I68P7yfB6nIi6U_PcCQsnobiSYzIpfzmgYaCMnl2PwcuVlSbk7yS_uNV8BkF8ymc3f2m'},
                    data: formData,
                    async: false,
                    success: function (data) {
                         //document.getElementById("myHiddendid").value = data.transientDocumentId;

                         myFun(data.transientDocumentId);
                        //SendAgreementExt.send(data);
                    },
                    cache: false,
                    contentType: false,
                    processData: false
                     });

                      return false;
                     });
                     </script>
                     <apex:form id="actionform">

                      <apex:actionFunction name="myFun" action="{!send}" reRender="thepage msg">
                       <apex:param name="myParam" value="" id="y" assignTo="{!documentid}" />
                       </apex:actionFunction>
                      </apex:form>
                      {!LeadMessage}
                     </apex:page>

Controller

                        Public with Sharing Class SendAgreementExt
                      {


                    public string LeadMessage{get;set;}
                     public string documentid{get; set;}
                    public string docid{get; set;}
                    public List <Lead> leadlist = new List<Lead>();
                    public pagereference send()
                    {  


                                 string AgreementCreationInfo;    
                                 string AgreementID;     
                                 JSONParser parser;
                                 Http h = new Http();
                                   ID leadid=ApexPages.currentPage().getParameters().get('id');  
                                    Lead leadrec = [SELECT ID,Email,AgreementID__c,Name FROM Lead WHERE ID =: leadid LIMIT 1];
                                   String recpentemail=leadrec.Email;
                                   String recpentname=leadrec.Name;

                                   AgreementCreationInfo='{"documentCreationInfo":{"fileInfos":[{"transientDocumentId":"'+documentid+'"}],"name":"'+recpentname+'","recipientSetInfos":[{"recipientSetMemberInfos":[{"email":"'+recpentemail+'","fax":""}],"recipientSetRole":"SIGNER"}],"signatureType":"ESIGN","signatureFlow":"SENDER_SIGNATURE_NOT_REQUIRED"}}';
                                   system.debug('===AgreementCreationInfo'+AgreementCreationInfo);
                                   HttpRequest req = new HttpRequest();
                                   req.setMethod('POST');
                                   req.setHeader('Access-Token', Label.echosign_access_token); 
                                   req.setEndpoint('https://api.na1.echosign.com:443/api/rest/v5/agreements');
                                   req.setBody(AgreementCreationInfo);
                                   req.setHeader('Content-Type', 'application/json');  
                                   req.setHeader('Content-Length', '462817');
                                   HttpResponse res;
                                   res = h.send(req);
                                   system.debug('==='+res.getBody());
                                   string LeadMessage=res.getBody();
                                parser = JSON.createParser(res.getBody());
                                 while(parser.nextToken() != null){
                                   if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
                                       if(parser.getText() == 'agreementId'){
                                           parser.nextToken();
                                           AgreementID=parser.getText();
                                       }
                                   }      

                                 }
                                 system.debug('===AgreementID'+AgreementID);
                                 List <Lead> leaddata = new List<Lead>();
                                 if(AgreementID!=null) {
                                    leadrec.AgreementID__c=AgreementID;
                                 }
                                 system.debug('===leadrec'+leadrec);
                                   update leadrec;

                               ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,'Agreement Sent!');
                        ApexPages.addMessage(myMsg);
                                  return null;

                          }


                       }
  • Vishal, this is not an answer; if you need to edit your OP, use the edit link – cropredy May 20 '16 at 23:42

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.