Help Interpret Peculiar Way of Handling SUCCESS and ERROR in Lightning Callback
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
6
down vote
favorite
I didn't write but rather I'm reviewing the following Lightning JS function:
InitializeComponent : function (component)
var recId = component.get("v.recordId");
var action = component.get("c.Init");
action.setParams( "recordId" : recId );
action.setCallback(this, function(response)
var resp = response.getReturnValue();
if (component.isValid())
// Success Code
,"SUCCESS");
action.setCallback(this, function(response)
// Error Code
,"ERROR");
$A.enqueueAction(action);
I've never seen and am trying to understand the way successes and failures of server side actions are being handled in this code.
It's less intuitive to me (but maybe more efficient?) than the developer guide's way here:
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
// do something with return value
else if (state === "INCOMPLETE")
// do something
else if (state === "ERROR")
// do something with error
);
I don't understand how setting up two call backs, making the SUCCESS action state an additional parameter in one and ERROR in the other, handles what to do in each of those conditons.
lightning-components javascript javascript-controller callback
add a comment |Â
up vote
6
down vote
favorite
I didn't write but rather I'm reviewing the following Lightning JS function:
InitializeComponent : function (component)
var recId = component.get("v.recordId");
var action = component.get("c.Init");
action.setParams( "recordId" : recId );
action.setCallback(this, function(response)
var resp = response.getReturnValue();
if (component.isValid())
// Success Code
,"SUCCESS");
action.setCallback(this, function(response)
// Error Code
,"ERROR");
$A.enqueueAction(action);
I've never seen and am trying to understand the way successes and failures of server side actions are being handled in this code.
It's less intuitive to me (but maybe more efficient?) than the developer guide's way here:
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
// do something with return value
else if (state === "INCOMPLETE")
// do something
else if (state === "ERROR")
// do something with error
);
I don't understand how setting up two call backs, making the SUCCESS action state an additional parameter in one and ERROR in the other, handles what to do in each of those conditons.
lightning-components javascript javascript-controller callback
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
I didn't write but rather I'm reviewing the following Lightning JS function:
InitializeComponent : function (component)
var recId = component.get("v.recordId");
var action = component.get("c.Init");
action.setParams( "recordId" : recId );
action.setCallback(this, function(response)
var resp = response.getReturnValue();
if (component.isValid())
// Success Code
,"SUCCESS");
action.setCallback(this, function(response)
// Error Code
,"ERROR");
$A.enqueueAction(action);
I've never seen and am trying to understand the way successes and failures of server side actions are being handled in this code.
It's less intuitive to me (but maybe more efficient?) than the developer guide's way here:
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
// do something with return value
else if (state === "INCOMPLETE")
// do something
else if (state === "ERROR")
// do something with error
);
I don't understand how setting up two call backs, making the SUCCESS action state an additional parameter in one and ERROR in the other, handles what to do in each of those conditons.
lightning-components javascript javascript-controller callback
I didn't write but rather I'm reviewing the following Lightning JS function:
InitializeComponent : function (component)
var recId = component.get("v.recordId");
var action = component.get("c.Init");
action.setParams( "recordId" : recId );
action.setCallback(this, function(response)
var resp = response.getReturnValue();
if (component.isValid())
// Success Code
,"SUCCESS");
action.setCallback(this, function(response)
// Error Code
,"ERROR");
$A.enqueueAction(action);
I've never seen and am trying to understand the way successes and failures of server side actions are being handled in this code.
It's less intuitive to me (but maybe more efficient?) than the developer guide's way here:
action.setCallback(this, function(response)
var state = response.getState();
if (state === "SUCCESS")
// do something with return value
else if (state === "INCOMPLETE")
// do something
else if (state === "ERROR")
// do something with error
);
I don't understand how setting up two call backs, making the SUCCESS action state an additional parameter in one and ERROR in the other, handles what to do in each of those conditons.
lightning-components javascript javascript-controller callback
lightning-components javascript javascript-controller callback
asked 3 hours ago
Gabriel Rivera
35113
35113
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
This is in the documentation, under JavaScript API / Action.
setCallback (Object scope, function callback, String name)
Sets the callback function that is executed after the server-side action returns. Call a server-side action from a client-side controller using callback. Note that you can register a callback for an explicit state, or you can use 'ALL' which registers callbacks for "SUCCESS", "ERROR", and "INCOMPLETE" (but not "ABORTED" for historical compatibility). It is recommended that you use an explicit name, and not the default 'undefined' to signify 'ALL'. The valid names are: * SUCCESS: if the action successfully completes. * ERROR: if the action has an error (including javascript errors for client side actions) * INCOMPLETE: if a server side action failed to complete because there is no connection * ABORTED: if the action is aborted via abort() * REFRESH: for server side storable actions, this will be called instead of the SUCCESS action when the storage is refreshed.
Basically, setCallback does allow you to register up to five different handlers, two of which aren't covered by the default undefined
/"ALL"
scenario. This can make code easier to read, especially if you have a common error handler, for example. This isn't well explained in any of the trailheads, but is officially supported.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
This is in the documentation, under JavaScript API / Action.
setCallback (Object scope, function callback, String name)
Sets the callback function that is executed after the server-side action returns. Call a server-side action from a client-side controller using callback. Note that you can register a callback for an explicit state, or you can use 'ALL' which registers callbacks for "SUCCESS", "ERROR", and "INCOMPLETE" (but not "ABORTED" for historical compatibility). It is recommended that you use an explicit name, and not the default 'undefined' to signify 'ALL'. The valid names are: * SUCCESS: if the action successfully completes. * ERROR: if the action has an error (including javascript errors for client side actions) * INCOMPLETE: if a server side action failed to complete because there is no connection * ABORTED: if the action is aborted via abort() * REFRESH: for server side storable actions, this will be called instead of the SUCCESS action when the storage is refreshed.
Basically, setCallback does allow you to register up to five different handlers, two of which aren't covered by the default undefined
/"ALL"
scenario. This can make code easier to read, especially if you have a common error handler, for example. This isn't well explained in any of the trailheads, but is officially supported.
add a comment |Â
up vote
3
down vote
accepted
This is in the documentation, under JavaScript API / Action.
setCallback (Object scope, function callback, String name)
Sets the callback function that is executed after the server-side action returns. Call a server-side action from a client-side controller using callback. Note that you can register a callback for an explicit state, or you can use 'ALL' which registers callbacks for "SUCCESS", "ERROR", and "INCOMPLETE" (but not "ABORTED" for historical compatibility). It is recommended that you use an explicit name, and not the default 'undefined' to signify 'ALL'. The valid names are: * SUCCESS: if the action successfully completes. * ERROR: if the action has an error (including javascript errors for client side actions) * INCOMPLETE: if a server side action failed to complete because there is no connection * ABORTED: if the action is aborted via abort() * REFRESH: for server side storable actions, this will be called instead of the SUCCESS action when the storage is refreshed.
Basically, setCallback does allow you to register up to five different handlers, two of which aren't covered by the default undefined
/"ALL"
scenario. This can make code easier to read, especially if you have a common error handler, for example. This isn't well explained in any of the trailheads, but is officially supported.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
This is in the documentation, under JavaScript API / Action.
setCallback (Object scope, function callback, String name)
Sets the callback function that is executed after the server-side action returns. Call a server-side action from a client-side controller using callback. Note that you can register a callback for an explicit state, or you can use 'ALL' which registers callbacks for "SUCCESS", "ERROR", and "INCOMPLETE" (but not "ABORTED" for historical compatibility). It is recommended that you use an explicit name, and not the default 'undefined' to signify 'ALL'. The valid names are: * SUCCESS: if the action successfully completes. * ERROR: if the action has an error (including javascript errors for client side actions) * INCOMPLETE: if a server side action failed to complete because there is no connection * ABORTED: if the action is aborted via abort() * REFRESH: for server side storable actions, this will be called instead of the SUCCESS action when the storage is refreshed.
Basically, setCallback does allow you to register up to five different handlers, two of which aren't covered by the default undefined
/"ALL"
scenario. This can make code easier to read, especially if you have a common error handler, for example. This isn't well explained in any of the trailheads, but is officially supported.
This is in the documentation, under JavaScript API / Action.
setCallback (Object scope, function callback, String name)
Sets the callback function that is executed after the server-side action returns. Call a server-side action from a client-side controller using callback. Note that you can register a callback for an explicit state, or you can use 'ALL' which registers callbacks for "SUCCESS", "ERROR", and "INCOMPLETE" (but not "ABORTED" for historical compatibility). It is recommended that you use an explicit name, and not the default 'undefined' to signify 'ALL'. The valid names are: * SUCCESS: if the action successfully completes. * ERROR: if the action has an error (including javascript errors for client side actions) * INCOMPLETE: if a server side action failed to complete because there is no connection * ABORTED: if the action is aborted via abort() * REFRESH: for server side storable actions, this will be called instead of the SUCCESS action when the storage is refreshed.
Basically, setCallback does allow you to register up to five different handlers, two of which aren't covered by the default undefined
/"ALL"
scenario. This can make code easier to read, especially if you have a common error handler, for example. This isn't well explained in any of the trailheads, but is officially supported.
answered 3 hours ago
sfdcfox
231k10178394
231k10178394
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235333%2fhelp-interpret-peculiar-way-of-handling-success-and-error-in-lightning-callback%23new-answer', 'question_page');
);
Post as a guest
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
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
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