Automated testing of chained Queueable jobs in SalesforceQueueable DML capabilityExecute method not getting...
How can I make my enemies feel real and make combat more engaging?
What happens when someone with a mature clone is turned into a vampire?
Badly designed reimbursement form. What does that say about the company?
Why did some CPUs use two Read/Write lines, and others just one?
Is it possible to detect 100% of SQLi with a simple regex?
How do sentient birds/theropods build their seats?
align is aligning to the right
Which was the first story to feature space elevators?
Does changing "sa" password require a SQL restart (in mixed mode)?
Short Story - Man lives in isolation in a compound, plays tennis against a robot, arranges meeting with a woman
Is it ethical to apply for a job on someone's behalf?
Run a command that requires sudo after a time has passed
Microphone on Mars
ErrorListPlot crops error bars
How do I handle a blinded enemy which wants to attack someone it's sure is there?
How can I differentiate duration vs starting time
How to not forget my phone in the bathroom?
Do error bars on probabilities have any meaning?
Why does finding small effects in large studies indicate publication bias?
Under which circumstances can »werden« stand at the end of a sentence?
find command cannot find my files which do exist
prepositions at the end of What and Which/that clauses
Can I legally make a website about boycotting a certain company?
Have any astronauts or cosmonauts died in space?
Automated testing of chained Queueable jobs in Salesforce
Queueable DML capabilityExecute method not getting invoked in QueueableKeep track of chained QueueableAre queueable jobs actually queueable?Queueable class throws Uncommitted Work Pending error in one test, but not othersLimit of Queueable Jobs Added to the Queue?Can Queueable Apex Jobs Run in Parallel?Callout and chain Queueable - Spring 17Chaining Queueables: Clarification & Practical UsagePost callout behavior assertions for unit test with static resource callout mock fail
I am currently writing a queueable class for asynchronous processing in my triggers since triggers do not allow callouts. I am going achieve it by calling a class which implements the queueable interface.
When reading the documentation I found out that you can have 50 queueable in one transaction but can call only one queueable from a queueable class.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm
Also, I can not chain the queueable jobs in apex test.

Example of working class / method:
Below class will work in its own transaction.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
Now, Salesforce documentation says, above mentioned code will work but wont be testable and I need to wrap it around Test.isRunningTest() and I may be wrong but what I understood from that is, these queueables needs to be tested separately and not in the test of EventTriggerHandler itself.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
This was working on its own as expected all the unit tests were working too per my understanding of queueable class and apex tests. Above code will not work when Event is being created from a queueable itself. We did a clean up exercise to consolidate all the logic in one queueable class.
But, I am not sure how to code a smoke test / automated tests so that we catch these beforehand without manual tests of entire org.
queueable-interface queueable-apex asynchronous-testing queueable
add a comment |
I am currently writing a queueable class for asynchronous processing in my triggers since triggers do not allow callouts. I am going achieve it by calling a class which implements the queueable interface.
When reading the documentation I found out that you can have 50 queueable in one transaction but can call only one queueable from a queueable class.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm
Also, I can not chain the queueable jobs in apex test.

Example of working class / method:
Below class will work in its own transaction.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
Now, Salesforce documentation says, above mentioned code will work but wont be testable and I need to wrap it around Test.isRunningTest() and I may be wrong but what I understood from that is, these queueables needs to be tested separately and not in the test of EventTriggerHandler itself.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
This was working on its own as expected all the unit tests were working too per my understanding of queueable class and apex tests. Above code will not work when Event is being created from a queueable itself. We did a clean up exercise to consolidate all the logic in one queueable class.
But, I am not sure how to code a smoke test / automated tests so that we catch these beforehand without manual tests of entire org.
queueable-interface queueable-apex asynchronous-testing queueable
if response of 1st condition triggers queuebale of second, why not make callouuts first and then do DML?
– user3209853
55 mins ago
add a comment |
I am currently writing a queueable class for asynchronous processing in my triggers since triggers do not allow callouts. I am going achieve it by calling a class which implements the queueable interface.
When reading the documentation I found out that you can have 50 queueable in one transaction but can call only one queueable from a queueable class.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm
Also, I can not chain the queueable jobs in apex test.

Example of working class / method:
Below class will work in its own transaction.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
Now, Salesforce documentation says, above mentioned code will work but wont be testable and I need to wrap it around Test.isRunningTest() and I may be wrong but what I understood from that is, these queueables needs to be tested separately and not in the test of EventTriggerHandler itself.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
This was working on its own as expected all the unit tests were working too per my understanding of queueable class and apex tests. Above code will not work when Event is being created from a queueable itself. We did a clean up exercise to consolidate all the logic in one queueable class.
But, I am not sure how to code a smoke test / automated tests so that we catch these beforehand without manual tests of entire org.
queueable-interface queueable-apex asynchronous-testing queueable
I am currently writing a queueable class for asynchronous processing in my triggers since triggers do not allow callouts. I am going achieve it by calling a class which implements the queueable interface.
When reading the documentation I found out that you can have 50 queueable in one transaction but can call only one queueable from a queueable class.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm
Also, I can not chain the queueable jobs in apex test.

Example of working class / method:
Below class will work in its own transaction.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
Now, Salesforce documentation says, above mentioned code will work but wont be testable and I need to wrap it around Test.isRunningTest() and I may be wrong but what I understood from that is, these queueables needs to be tested separately and not in the test of EventTriggerHandler itself.
EventTriggerHandler.afterInsert(){
Boolean bDoACallout = isCalloutNecessary();
if(bDoACallout){
System.enqueueJob(new EventTriggerHandlerCallout((Map<Id, Event>)Trigger.newMap));
}
Boolean bSecondCondition = isSecondConditionTrue();
if(bSecondCondition){
System.enqueueJob(new Trial1Queueable((Map<Id, Event>)Trigger.newMap));
}
Boolean bThirdCondition = isThirdConditionTrue();
if(bThirdCondition){
System.enqueueJob(new Trial2Queueable((Map<Id, Event>)Trigger.newMap));
}
}
This was working on its own as expected all the unit tests were working too per my understanding of queueable class and apex tests. Above code will not work when Event is being created from a queueable itself. We did a clean up exercise to consolidate all the logic in one queueable class.
But, I am not sure how to code a smoke test / automated tests so that we catch these beforehand without manual tests of entire org.
queueable-interface queueable-apex asynchronous-testing queueable
queueable-interface queueable-apex asynchronous-testing queueable
asked 1 hour ago
Json Bourne ShellJson Bourne Shell
134111
134111
if response of 1st condition triggers queuebale of second, why not make callouuts first and then do DML?
– user3209853
55 mins ago
add a comment |
if response of 1st condition triggers queuebale of second, why not make callouuts first and then do DML?
– user3209853
55 mins ago
if response of 1st condition triggers queuebale of second, why not make callouuts first and then do DML?
– user3209853
55 mins ago
if response of 1st condition triggers queuebale of second, why not make callouuts first and then do DML?
– user3209853
55 mins ago
add a comment |
2 Answers
2
active
oldest
votes
A quick note to start off, the code you've provided right now doesn't display chaining of queueable classes. Chaining would be that you set up the execution of a queueable class from inside the execute() method of another queueable class. Rather, you have shown us a sequence of queueable calls.
A class that implements the Queueable interface, and the execute(QueueableContext ctx) method required to be in it, aren't really that different from any other class/method.
The QueueableContext parameter, which has official documentation, doesn't end up doing much of anything for you. It contains a job id, and nothing else (from what I can tell).
You can call the execute() method synchronously by simply passing in null as the argument for the execute() method (provided that you aren't actually using the job id).
So, in this case, testing your chained queueable methods breaks down to simply testing each method one at a time (likely in different test methods). You'll need to set up your test environment appropriately so that you are guaranteed to take the code path(s) that you want to test, but that's no different from your ordinary, run-of-the-mill unit test.
You may need to keep the chained calls behind a check against test.isRunningTest(), but that's about it.
You could possibly write a test that calls your queueable class from your trigger handler (not sure if you can call more than one per test), but that'd be less of a unit test, and more like an integration test.
+edit:
To write a test for your trigger handler that is closer to being a unit test, you should look into the Stub API to mock your calls to your queueable classes. The idea here is that you'll only care that the queueable class has its execute() method called (and not the result of running the actual code, which would be a unit test of the queueable classes themselves)
Thank you for the response. I have queueable because I want to make callouts in the after triggers. By calling the execute() synchronously, I wont be able to make callouts to outside systems in the trigger.
– Json Bourne Shell
59 mins ago
@JsonBourneShell you can make at least one (maybe more, I'm not 100% sure right now) call to a queueable class in a unit test if you make use ofTest.startTest()andTest.stopTest()as part of your test method. The point still stands, though, that testing the functionality of your queueable classes in your test for your trigger handler is closer to integration testing than unit testing.
– Derek F
54 mins ago
Yes, you've hit the nail on the head here. I am looking for a way to write automated smoke / integration test so that I will be able to catch it beforehand.
– Json Bourne Shell
50 mins ago
add a comment |
When you need more than one execution, but you want to test the asynchronous code independently, you can cheat by rolling them back. Here's an example in a unit test:
Test.startTest();
SavePoint sp = Database.setSavePoint();
// Replace this with real code
executeTheTrigger();
// Do any asserts, etc...
// Roll back the transaction
Database.rollback(sp);
Test.stopTest();
Then, you can get a natural 100% coverage of your trigger code without this error. Note that you should prefer to do any assertions before you roll back the state, since any modifications will disappear. Also remember you'll need to unit test your Queueables independently.
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%2f251054%2fautomated-testing-of-chained-queueable-jobs-in-salesforce%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A quick note to start off, the code you've provided right now doesn't display chaining of queueable classes. Chaining would be that you set up the execution of a queueable class from inside the execute() method of another queueable class. Rather, you have shown us a sequence of queueable calls.
A class that implements the Queueable interface, and the execute(QueueableContext ctx) method required to be in it, aren't really that different from any other class/method.
The QueueableContext parameter, which has official documentation, doesn't end up doing much of anything for you. It contains a job id, and nothing else (from what I can tell).
You can call the execute() method synchronously by simply passing in null as the argument for the execute() method (provided that you aren't actually using the job id).
So, in this case, testing your chained queueable methods breaks down to simply testing each method one at a time (likely in different test methods). You'll need to set up your test environment appropriately so that you are guaranteed to take the code path(s) that you want to test, but that's no different from your ordinary, run-of-the-mill unit test.
You may need to keep the chained calls behind a check against test.isRunningTest(), but that's about it.
You could possibly write a test that calls your queueable class from your trigger handler (not sure if you can call more than one per test), but that'd be less of a unit test, and more like an integration test.
+edit:
To write a test for your trigger handler that is closer to being a unit test, you should look into the Stub API to mock your calls to your queueable classes. The idea here is that you'll only care that the queueable class has its execute() method called (and not the result of running the actual code, which would be a unit test of the queueable classes themselves)
Thank you for the response. I have queueable because I want to make callouts in the after triggers. By calling the execute() synchronously, I wont be able to make callouts to outside systems in the trigger.
– Json Bourne Shell
59 mins ago
@JsonBourneShell you can make at least one (maybe more, I'm not 100% sure right now) call to a queueable class in a unit test if you make use ofTest.startTest()andTest.stopTest()as part of your test method. The point still stands, though, that testing the functionality of your queueable classes in your test for your trigger handler is closer to integration testing than unit testing.
– Derek F
54 mins ago
Yes, you've hit the nail on the head here. I am looking for a way to write automated smoke / integration test so that I will be able to catch it beforehand.
– Json Bourne Shell
50 mins ago
add a comment |
A quick note to start off, the code you've provided right now doesn't display chaining of queueable classes. Chaining would be that you set up the execution of a queueable class from inside the execute() method of another queueable class. Rather, you have shown us a sequence of queueable calls.
A class that implements the Queueable interface, and the execute(QueueableContext ctx) method required to be in it, aren't really that different from any other class/method.
The QueueableContext parameter, which has official documentation, doesn't end up doing much of anything for you. It contains a job id, and nothing else (from what I can tell).
You can call the execute() method synchronously by simply passing in null as the argument for the execute() method (provided that you aren't actually using the job id).
So, in this case, testing your chained queueable methods breaks down to simply testing each method one at a time (likely in different test methods). You'll need to set up your test environment appropriately so that you are guaranteed to take the code path(s) that you want to test, but that's no different from your ordinary, run-of-the-mill unit test.
You may need to keep the chained calls behind a check against test.isRunningTest(), but that's about it.
You could possibly write a test that calls your queueable class from your trigger handler (not sure if you can call more than one per test), but that'd be less of a unit test, and more like an integration test.
+edit:
To write a test for your trigger handler that is closer to being a unit test, you should look into the Stub API to mock your calls to your queueable classes. The idea here is that you'll only care that the queueable class has its execute() method called (and not the result of running the actual code, which would be a unit test of the queueable classes themselves)
Thank you for the response. I have queueable because I want to make callouts in the after triggers. By calling the execute() synchronously, I wont be able to make callouts to outside systems in the trigger.
– Json Bourne Shell
59 mins ago
@JsonBourneShell you can make at least one (maybe more, I'm not 100% sure right now) call to a queueable class in a unit test if you make use ofTest.startTest()andTest.stopTest()as part of your test method. The point still stands, though, that testing the functionality of your queueable classes in your test for your trigger handler is closer to integration testing than unit testing.
– Derek F
54 mins ago
Yes, you've hit the nail on the head here. I am looking for a way to write automated smoke / integration test so that I will be able to catch it beforehand.
– Json Bourne Shell
50 mins ago
add a comment |
A quick note to start off, the code you've provided right now doesn't display chaining of queueable classes. Chaining would be that you set up the execution of a queueable class from inside the execute() method of another queueable class. Rather, you have shown us a sequence of queueable calls.
A class that implements the Queueable interface, and the execute(QueueableContext ctx) method required to be in it, aren't really that different from any other class/method.
The QueueableContext parameter, which has official documentation, doesn't end up doing much of anything for you. It contains a job id, and nothing else (from what I can tell).
You can call the execute() method synchronously by simply passing in null as the argument for the execute() method (provided that you aren't actually using the job id).
So, in this case, testing your chained queueable methods breaks down to simply testing each method one at a time (likely in different test methods). You'll need to set up your test environment appropriately so that you are guaranteed to take the code path(s) that you want to test, but that's no different from your ordinary, run-of-the-mill unit test.
You may need to keep the chained calls behind a check against test.isRunningTest(), but that's about it.
You could possibly write a test that calls your queueable class from your trigger handler (not sure if you can call more than one per test), but that'd be less of a unit test, and more like an integration test.
+edit:
To write a test for your trigger handler that is closer to being a unit test, you should look into the Stub API to mock your calls to your queueable classes. The idea here is that you'll only care that the queueable class has its execute() method called (and not the result of running the actual code, which would be a unit test of the queueable classes themselves)
A quick note to start off, the code you've provided right now doesn't display chaining of queueable classes. Chaining would be that you set up the execution of a queueable class from inside the execute() method of another queueable class. Rather, you have shown us a sequence of queueable calls.
A class that implements the Queueable interface, and the execute(QueueableContext ctx) method required to be in it, aren't really that different from any other class/method.
The QueueableContext parameter, which has official documentation, doesn't end up doing much of anything for you. It contains a job id, and nothing else (from what I can tell).
You can call the execute() method synchronously by simply passing in null as the argument for the execute() method (provided that you aren't actually using the job id).
So, in this case, testing your chained queueable methods breaks down to simply testing each method one at a time (likely in different test methods). You'll need to set up your test environment appropriately so that you are guaranteed to take the code path(s) that you want to test, but that's no different from your ordinary, run-of-the-mill unit test.
You may need to keep the chained calls behind a check against test.isRunningTest(), but that's about it.
You could possibly write a test that calls your queueable class from your trigger handler (not sure if you can call more than one per test), but that'd be less of a unit test, and more like an integration test.
+edit:
To write a test for your trigger handler that is closer to being a unit test, you should look into the Stub API to mock your calls to your queueable classes. The idea here is that you'll only care that the queueable class has its execute() method called (and not the result of running the actual code, which would be a unit test of the queueable classes themselves)
edited 50 mins ago
answered 1 hour ago
Derek FDerek F
20k32152
20k32152
Thank you for the response. I have queueable because I want to make callouts in the after triggers. By calling the execute() synchronously, I wont be able to make callouts to outside systems in the trigger.
– Json Bourne Shell
59 mins ago
@JsonBourneShell you can make at least one (maybe more, I'm not 100% sure right now) call to a queueable class in a unit test if you make use ofTest.startTest()andTest.stopTest()as part of your test method. The point still stands, though, that testing the functionality of your queueable classes in your test for your trigger handler is closer to integration testing than unit testing.
– Derek F
54 mins ago
Yes, you've hit the nail on the head here. I am looking for a way to write automated smoke / integration test so that I will be able to catch it beforehand.
– Json Bourne Shell
50 mins ago
add a comment |
Thank you for the response. I have queueable because I want to make callouts in the after triggers. By calling the execute() synchronously, I wont be able to make callouts to outside systems in the trigger.
– Json Bourne Shell
59 mins ago
@JsonBourneShell you can make at least one (maybe more, I'm not 100% sure right now) call to a queueable class in a unit test if you make use ofTest.startTest()andTest.stopTest()as part of your test method. The point still stands, though, that testing the functionality of your queueable classes in your test for your trigger handler is closer to integration testing than unit testing.
– Derek F
54 mins ago
Yes, you've hit the nail on the head here. I am looking for a way to write automated smoke / integration test so that I will be able to catch it beforehand.
– Json Bourne Shell
50 mins ago
Thank you for the response. I have queueable because I want to make callouts in the after triggers. By calling the execute() synchronously, I wont be able to make callouts to outside systems in the trigger.
– Json Bourne Shell
59 mins ago
Thank you for the response. I have queueable because I want to make callouts in the after triggers. By calling the execute() synchronously, I wont be able to make callouts to outside systems in the trigger.
– Json Bourne Shell
59 mins ago
@JsonBourneShell you can make at least one (maybe more, I'm not 100% sure right now) call to a queueable class in a unit test if you make use of
Test.startTest() and Test.stopTest() as part of your test method. The point still stands, though, that testing the functionality of your queueable classes in your test for your trigger handler is closer to integration testing than unit testing.– Derek F
54 mins ago
@JsonBourneShell you can make at least one (maybe more, I'm not 100% sure right now) call to a queueable class in a unit test if you make use of
Test.startTest() and Test.stopTest() as part of your test method. The point still stands, though, that testing the functionality of your queueable classes in your test for your trigger handler is closer to integration testing than unit testing.– Derek F
54 mins ago
Yes, you've hit the nail on the head here. I am looking for a way to write automated smoke / integration test so that I will be able to catch it beforehand.
– Json Bourne Shell
50 mins ago
Yes, you've hit the nail on the head here. I am looking for a way to write automated smoke / integration test so that I will be able to catch it beforehand.
– Json Bourne Shell
50 mins ago
add a comment |
When you need more than one execution, but you want to test the asynchronous code independently, you can cheat by rolling them back. Here's an example in a unit test:
Test.startTest();
SavePoint sp = Database.setSavePoint();
// Replace this with real code
executeTheTrigger();
// Do any asserts, etc...
// Roll back the transaction
Database.rollback(sp);
Test.stopTest();
Then, you can get a natural 100% coverage of your trigger code without this error. Note that you should prefer to do any assertions before you roll back the state, since any modifications will disappear. Also remember you'll need to unit test your Queueables independently.
add a comment |
When you need more than one execution, but you want to test the asynchronous code independently, you can cheat by rolling them back. Here's an example in a unit test:
Test.startTest();
SavePoint sp = Database.setSavePoint();
// Replace this with real code
executeTheTrigger();
// Do any asserts, etc...
// Roll back the transaction
Database.rollback(sp);
Test.stopTest();
Then, you can get a natural 100% coverage of your trigger code without this error. Note that you should prefer to do any assertions before you roll back the state, since any modifications will disappear. Also remember you'll need to unit test your Queueables independently.
add a comment |
When you need more than one execution, but you want to test the asynchronous code independently, you can cheat by rolling them back. Here's an example in a unit test:
Test.startTest();
SavePoint sp = Database.setSavePoint();
// Replace this with real code
executeTheTrigger();
// Do any asserts, etc...
// Roll back the transaction
Database.rollback(sp);
Test.stopTest();
Then, you can get a natural 100% coverage of your trigger code without this error. Note that you should prefer to do any assertions before you roll back the state, since any modifications will disappear. Also remember you'll need to unit test your Queueables independently.
When you need more than one execution, but you want to test the asynchronous code independently, you can cheat by rolling them back. Here's an example in a unit test:
Test.startTest();
SavePoint sp = Database.setSavePoint();
// Replace this with real code
executeTheTrigger();
// Do any asserts, etc...
// Roll back the transaction
Database.rollback(sp);
Test.stopTest();
Then, you can get a natural 100% coverage of your trigger code without this error. Note that you should prefer to do any assertions before you roll back the state, since any modifications will disappear. Also remember you'll need to unit test your Queueables independently.
answered 55 mins ago
sfdcfoxsfdcfox
256k11201441
256k11201441
add a comment |
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.
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%2f251054%2fautomated-testing-of-chained-queueable-jobs-in-salesforce%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
if response of 1st condition triggers queuebale of second, why not make callouuts first and then do DML?
– user3209853
55 mins ago