0

I have a Controller method savetask(). It is called from javascript where I am inserting task after insertion I am getting that Taskid into String variable and I have to show this variable into alert() in javascript. But it is showing null. Find my code below:

 function testOpenSubtab() {
        //First find the ID of the primary tab to put the new subtab in
        SavetAsk();
       // alert();  

        sforce.console.getEnclosingPrimaryTabId(openSubtabtest); 
    };

public class SaveProviders {

       public string var{get{
            if(var==null) 
                var='Set from get method'; 
                return var; 
             } 
            set; }


Public SaveProviders(ApexPages.StandardController controller){
    tsk = (Task)controller.getRecord();
    TskId = ApexPages.currentPage().getParameters().get('Id');
    //tsk1 = new Task();
}

Public String SavetAsk(){

    Rich_Prenotazione = tsk.Rich_Prenotazione__c; 
    Centro_Nome = tsk.Centro_Nome__c; 
    Task tsk1 = new Task(Rich_Prenotazione__c = Rich_Prenotazione,
                        Esito__c = Esito, 
                        Priority=tsk.Priority);

    Insert tsk1;
    varA = tsk1.id;
    system.debug('***12344'+varA);
    var='Set from inside callMe';

    return tsk1.id;

}

}

This var value I have to show on alert(). WhatEver I have assingned to method like [var = Set from inside callMe']. But Its showing [var='Set from get method'; ] means I am getting null here. Please help !

0

After you call that SaveTask method just rerender the section in which you are displaying alert and you Will get updated value.

Or you can do something like <apex:actionFunction name="SavetAsk" action="{!SavetAsk}" reRender="a" oncomplete="alert('{!var}');"/>

  • 1
    Here I want to show into alert() only which is after SavetAsk(). Something like this alert(var). – RAHUL SRIVASTAVA Aug 23 '16 at 15:38
  • How are you calling controller method from which actionfunction – Tushar Sharma Aug 23 '16 at 15:53
  • yes, <apex:actionFunction name="SavetAsk" action="{!SavetAsk}" reRender="a" /> – RAHUL SRIVASTAVA Aug 23 '16 at 15:56
  • @RAHULSRIVASTAVA check my updated answer. – Tushar Sharma Aug 23 '16 at 15:59
  • It is not showing the alert(). – RAHUL SRIVASTAVA Aug 23 '16 at 16:07

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.