Difference between setCallBack and getCallBack function?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












3














Please tell the difference between setCallBack and getCallBack function? Also, If possible can someone please tell me why what is .this function and what does this code is actually doing. (Its related to Instant Notification App https://trailhead.salesforce.com/content/learn/projects/workshop-platform-events/platform-event-subscribe)



const callback = function (message) 
console.log('Event Received : ' + JSON.stringify(message));
helper.onReceiveNotification(component, message);
;

// Subscribe to the channel and save the returned subscription object.

empApi.subscribe(channel, replayId, $A.getCallback(callback)).then($A.getCallback(function (newSubscription)
console.log('Subscribed to channel ' + channel);
component.set('v.subscription', newSubscription);
));









share|improve this question




























    3














    Please tell the difference between setCallBack and getCallBack function? Also, If possible can someone please tell me why what is .this function and what does this code is actually doing. (Its related to Instant Notification App https://trailhead.salesforce.com/content/learn/projects/workshop-platform-events/platform-event-subscribe)



    const callback = function (message) 
    console.log('Event Received : ' + JSON.stringify(message));
    helper.onReceiveNotification(component, message);
    ;

    // Subscribe to the channel and save the returned subscription object.

    empApi.subscribe(channel, replayId, $A.getCallback(callback)).then($A.getCallback(function (newSubscription)
    console.log('Subscribed to channel ' + channel);
    component.set('v.subscription', newSubscription);
    ));









    share|improve this question


























      3












      3








      3







      Please tell the difference between setCallBack and getCallBack function? Also, If possible can someone please tell me why what is .this function and what does this code is actually doing. (Its related to Instant Notification App https://trailhead.salesforce.com/content/learn/projects/workshop-platform-events/platform-event-subscribe)



      const callback = function (message) 
      console.log('Event Received : ' + JSON.stringify(message));
      helper.onReceiveNotification(component, message);
      ;

      // Subscribe to the channel and save the returned subscription object.

      empApi.subscribe(channel, replayId, $A.getCallback(callback)).then($A.getCallback(function (newSubscription)
      console.log('Subscribed to channel ' + channel);
      component.set('v.subscription', newSubscription);
      ));









      share|improve this question















      Please tell the difference between setCallBack and getCallBack function? Also, If possible can someone please tell me why what is .this function and what does this code is actually doing. (Its related to Instant Notification App https://trailhead.salesforce.com/content/learn/projects/workshop-platform-events/platform-event-subscribe)



      const callback = function (message) 
      console.log('Event Received : ' + JSON.stringify(message));
      helper.onReceiveNotification(component, message);
      ;

      // Subscribe to the channel and save the returned subscription object.

      empApi.subscribe(channel, replayId, $A.getCallback(callback)).then($A.getCallback(function (newSubscription)
      console.log('Subscribed to channel ' + channel);
      component.set('v.subscription', newSubscription);
      ));






      lightning-aura-components






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 25 '18 at 12:45

























      asked Dec 25 '18 at 12:07









      Sukruti

      406




      406




















          1 Answer
          1






          active

          oldest

          votes


















          6














          action.setCallback() is used to provide a callback function when making a call to a server-side Apex controller:



           var action = component.get("c.someMethod");
          action.setParams( param: cmp.get("v.aParameter") );
          action.setCallback(this, function(response)
          // Do things.

          $A.enqueueAction(action);


          $A.getCallback() is used when passing a callback function to a function outside the Lightning framework that might interact with a component outside the normal rendering lifecycle, such as setTimeout():



          window.setTimeout(
          $A.getCallback(function()
          cmp.set("v.visible", true);
          ), 5000
          );


          You do not need to use $A.getCallback() when interacting with Apex server controller methods.



          The code that you posted is using the <lightning:empApi> component to subscribe to a Platform Event. The subscription is handled by a JavaScript library that speaks the CometD protocol and callbacks are performed asynchronously at any time. Hence the use case falls into the realm of $A.getCallback() as described above.






          share|improve this answer






















          • Thanks David for explanation. So the getCallBack method will execute when we are calling a method that is not part of aura framework. If possible can tell please tell me how below code is working:
            – Sukruti
            Dec 25 '18 at 12:41










          • If you have specific code, please edit it into your question.
            – David Reed
            Dec 25 '18 at 12:42










          • Hi David, Please let me know if you can help here.
            – Sukruti
            Dec 25 '18 at 12:46










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244602%2fdifference-between-setcallback-and-getcallback-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          action.setCallback() is used to provide a callback function when making a call to a server-side Apex controller:



           var action = component.get("c.someMethod");
          action.setParams( param: cmp.get("v.aParameter") );
          action.setCallback(this, function(response)
          // Do things.

          $A.enqueueAction(action);


          $A.getCallback() is used when passing a callback function to a function outside the Lightning framework that might interact with a component outside the normal rendering lifecycle, such as setTimeout():



          window.setTimeout(
          $A.getCallback(function()
          cmp.set("v.visible", true);
          ), 5000
          );


          You do not need to use $A.getCallback() when interacting with Apex server controller methods.



          The code that you posted is using the <lightning:empApi> component to subscribe to a Platform Event. The subscription is handled by a JavaScript library that speaks the CometD protocol and callbacks are performed asynchronously at any time. Hence the use case falls into the realm of $A.getCallback() as described above.






          share|improve this answer






















          • Thanks David for explanation. So the getCallBack method will execute when we are calling a method that is not part of aura framework. If possible can tell please tell me how below code is working:
            – Sukruti
            Dec 25 '18 at 12:41










          • If you have specific code, please edit it into your question.
            – David Reed
            Dec 25 '18 at 12:42










          • Hi David, Please let me know if you can help here.
            – Sukruti
            Dec 25 '18 at 12:46















          6














          action.setCallback() is used to provide a callback function when making a call to a server-side Apex controller:



           var action = component.get("c.someMethod");
          action.setParams( param: cmp.get("v.aParameter") );
          action.setCallback(this, function(response)
          // Do things.

          $A.enqueueAction(action);


          $A.getCallback() is used when passing a callback function to a function outside the Lightning framework that might interact with a component outside the normal rendering lifecycle, such as setTimeout():



          window.setTimeout(
          $A.getCallback(function()
          cmp.set("v.visible", true);
          ), 5000
          );


          You do not need to use $A.getCallback() when interacting with Apex server controller methods.



          The code that you posted is using the <lightning:empApi> component to subscribe to a Platform Event. The subscription is handled by a JavaScript library that speaks the CometD protocol and callbacks are performed asynchronously at any time. Hence the use case falls into the realm of $A.getCallback() as described above.






          share|improve this answer






















          • Thanks David for explanation. So the getCallBack method will execute when we are calling a method that is not part of aura framework. If possible can tell please tell me how below code is working:
            – Sukruti
            Dec 25 '18 at 12:41










          • If you have specific code, please edit it into your question.
            – David Reed
            Dec 25 '18 at 12:42










          • Hi David, Please let me know if you can help here.
            – Sukruti
            Dec 25 '18 at 12:46













          6












          6








          6






          action.setCallback() is used to provide a callback function when making a call to a server-side Apex controller:



           var action = component.get("c.someMethod");
          action.setParams( param: cmp.get("v.aParameter") );
          action.setCallback(this, function(response)
          // Do things.

          $A.enqueueAction(action);


          $A.getCallback() is used when passing a callback function to a function outside the Lightning framework that might interact with a component outside the normal rendering lifecycle, such as setTimeout():



          window.setTimeout(
          $A.getCallback(function()
          cmp.set("v.visible", true);
          ), 5000
          );


          You do not need to use $A.getCallback() when interacting with Apex server controller methods.



          The code that you posted is using the <lightning:empApi> component to subscribe to a Platform Event. The subscription is handled by a JavaScript library that speaks the CometD protocol and callbacks are performed asynchronously at any time. Hence the use case falls into the realm of $A.getCallback() as described above.






          share|improve this answer














          action.setCallback() is used to provide a callback function when making a call to a server-side Apex controller:



           var action = component.get("c.someMethod");
          action.setParams( param: cmp.get("v.aParameter") );
          action.setCallback(this, function(response)
          // Do things.

          $A.enqueueAction(action);


          $A.getCallback() is used when passing a callback function to a function outside the Lightning framework that might interact with a component outside the normal rendering lifecycle, such as setTimeout():



          window.setTimeout(
          $A.getCallback(function()
          cmp.set("v.visible", true);
          ), 5000
          );


          You do not need to use $A.getCallback() when interacting with Apex server controller methods.



          The code that you posted is using the <lightning:empApi> component to subscribe to a Platform Event. The subscription is handled by a JavaScript library that speaks the CometD protocol and callbacks are performed asynchronously at any time. Hence the use case falls into the realm of $A.getCallback() as described above.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 25 '18 at 12:50

























          answered Dec 25 '18 at 12:21









          David Reed

          30.8k61746




          30.8k61746











          • Thanks David for explanation. So the getCallBack method will execute when we are calling a method that is not part of aura framework. If possible can tell please tell me how below code is working:
            – Sukruti
            Dec 25 '18 at 12:41










          • If you have specific code, please edit it into your question.
            – David Reed
            Dec 25 '18 at 12:42










          • Hi David, Please let me know if you can help here.
            – Sukruti
            Dec 25 '18 at 12:46
















          • Thanks David for explanation. So the getCallBack method will execute when we are calling a method that is not part of aura framework. If possible can tell please tell me how below code is working:
            – Sukruti
            Dec 25 '18 at 12:41










          • If you have specific code, please edit it into your question.
            – David Reed
            Dec 25 '18 at 12:42










          • Hi David, Please let me know if you can help here.
            – Sukruti
            Dec 25 '18 at 12:46















          Thanks David for explanation. So the getCallBack method will execute when we are calling a method that is not part of aura framework. If possible can tell please tell me how below code is working:
          – Sukruti
          Dec 25 '18 at 12:41




          Thanks David for explanation. So the getCallBack method will execute when we are calling a method that is not part of aura framework. If possible can tell please tell me how below code is working:
          – Sukruti
          Dec 25 '18 at 12:41












          If you have specific code, please edit it into your question.
          – David Reed
          Dec 25 '18 at 12:42




          If you have specific code, please edit it into your question.
          – David Reed
          Dec 25 '18 at 12:42












          Hi David, Please let me know if you can help here.
          – Sukruti
          Dec 25 '18 at 12:46




          Hi David, Please let me know if you can help here.
          – Sukruti
          Dec 25 '18 at 12:46

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f244602%2fdifference-between-setcallback-and-getcallback-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay