Difference between setCallBack and getCallBack function?
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
add a comment |
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
add a comment |
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
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
lightning-aura-components
edited 1 hour ago
asked 1 hour ago
Sukruti
326
326
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
1 hour ago
If you have specific code, please edit it into your question.
– David Reed
1 hour ago
Hi David, Please let me know if you can help here.
– Sukruti
1 hour ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
1 hour ago
If you have specific code, please edit it into your question.
– David Reed
1 hour ago
Hi David, Please let me know if you can help here.
– Sukruti
1 hour ago
add a comment |
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.
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
1 hour ago
If you have specific code, please edit it into your question.
– David Reed
1 hour ago
Hi David, Please let me know if you can help here.
– Sukruti
1 hour ago
add a comment |
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.
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.
edited 1 hour ago
answered 1 hour ago
David Reed
29.5k61746
29.5k61746
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
1 hour ago
If you have specific code, please edit it into your question.
– David Reed
1 hour ago
Hi David, Please let me know if you can help here.
– Sukruti
1 hour ago
add a comment |
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
1 hour ago
If you have specific code, please edit it into your question.
– David Reed
1 hour ago
Hi David, Please let me know if you can help here.
– Sukruti
1 hour ago
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
1 hour ago
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
1 hour ago
If you have specific code, please edit it into your question.
– David Reed
1 hour ago
If you have specific code, please edit it into your question.
– David Reed
1 hour ago
Hi David, Please let me know if you can help here.
– Sukruti
1 hour ago
Hi David, Please let me know if you can help here.
– Sukruti
1 hour ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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