Assertions In A Mock Callout TestSystem.CalloutException: You have uncommitted work pending. Please commit or rollbackREST API calls to 3rd Party (Pardot), multiple @future calloutshow to test a future method which makes callouts?“Required fields are missing: [ProfileId]: [ProfileId]” when running Apex Class Test for ChatterAnswersAuthProviderRegTestCode Coverage to Test Custom Object Public ListApex Test Class Assert for Void?Testing future callout methodHow to cover global class and method in test classTest.setMock not working in Apex testHello i am not able to get the result from this test class

Binary Numbers Magic Trick

Would "lab meat" be able to feed a much larger global population

How to implement float hashing with approximate equality

Selecting a secure PIN for building access

Any examples of headwear for races with animal ears?

Feels like I am getting dragged into office politics

Airbnb - host wants to reduce rooms, can we get refund?

Is Cola "probably the best-known" Latin word in the world? If not, which might it be?

Stark VS Thanos

Can I use 1000v rectifier diodes instead of 600v rectifier diodes?

I’ve officially counted to infinity!

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

Why is this a valid proof for the harmonic series?

Why do computer-science majors learn calculus?

Entropy as a function of temperature: is temperature well defined?

Can PCs use nonmagical armor and weapons looted from monsters?

Junior developer struggles: how to communicate with management?

Was Unix ever a single-user OS?

Why do money exchangers give different rates to different bills

Write to EXCEL from SQL DB using VBA script

What are the spoon bit of a spoon and fork bit of a fork called?

Field Length Validation for Desktop Application which has maximum 1000 characters

Attending a conference where my ex-supervisor and his collaborator are present, should I attend?

What happened to Rhaegal?



Assertions In A Mock Callout Test


System.CalloutException: You have uncommitted work pending. Please commit or rollbackREST API calls to 3rd Party (Pardot), multiple @future calloutshow to test a future method which makes callouts?“Required fields are missing: [ProfileId]: [ProfileId]” when running Apex Class Test for ChatterAnswersAuthProviderRegTestCode Coverage to Test Custom Object Public ListApex Test Class Assert for Void?Testing future callout methodHow to cover global class and method in test classTest.setMock not working in Apex testHello i am not able to get the result from this test class






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















Working on my first call out class. When a contact is created or has an email changed we need to make a call out to a third party service that verifies the email address.



Everything is working excep the final assertion. I expect a result of valid but the result is null. I have been reading through the documentation but not making sense of the rules around DML and mocks. I have included my call out class, test class and Mock. How can I get my assertion to pass and validate that the field I want updated by my callout has been updated?



Web-service



public with sharing class NeverBounceCallout 

@Future(callout=true)
public static void checkNeverBounce(Id id)
Contact contact = [SELECT Email, Never_Bounce_Result__c FROM Contact WHERE Id =: id LIMIT 1];
String email = contact.Email;
String url = 'https://api.neverbounce.com/v4/single/check?key=api_key&email=' + email;

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(url);
request.setMethod('GET');
HttpResponse response = http.send(request);
if(response.getStatusCode()==200)
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());

contact.Never_Bounce_Result__c = (String)results.get('result');
System.debug('json body = ' + results);
update contact;





My Mock



@IsTest
global class NeverBounceMock implements HttpCalloutMock{

global HttpResponse respond(HttpRequest request)
System.assertEquals('GET', request.getMethod());

HttpResponse response = new HttpResponse();
response.setHeader('Content-Type', 'application/json');
response.setStatusCode(200);
response.setBody('"status" : "success", "result" : "valid"');
return response;




Test



@IsTest
private class NeverBounceTest
@IsTest
static void NeverbounceEmailTest()
Account a = new Account(Name = 'Test acc');
insert a;
Contact c = new Contact(LastName = 'Test Con', AccountId = a.Id, Email='Test@test.com');
insert c;

Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
//System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);
Test.stopTest();












share|improve this question



















  • 1





    Do you intend to set this -- contact.Never_Bounce_Result__c = (String)results.get('result'); instead? The reason being your mock response returns an attribute named result instead of results.

    – Jayant Das
    Apr 22 at 17:03

















4















Working on my first call out class. When a contact is created or has an email changed we need to make a call out to a third party service that verifies the email address.



Everything is working excep the final assertion. I expect a result of valid but the result is null. I have been reading through the documentation but not making sense of the rules around DML and mocks. I have included my call out class, test class and Mock. How can I get my assertion to pass and validate that the field I want updated by my callout has been updated?



Web-service



public with sharing class NeverBounceCallout 

@Future(callout=true)
public static void checkNeverBounce(Id id)
Contact contact = [SELECT Email, Never_Bounce_Result__c FROM Contact WHERE Id =: id LIMIT 1];
String email = contact.Email;
String url = 'https://api.neverbounce.com/v4/single/check?key=api_key&email=' + email;

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(url);
request.setMethod('GET');
HttpResponse response = http.send(request);
if(response.getStatusCode()==200)
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());

contact.Never_Bounce_Result__c = (String)results.get('result');
System.debug('json body = ' + results);
update contact;





My Mock



@IsTest
global class NeverBounceMock implements HttpCalloutMock{

global HttpResponse respond(HttpRequest request)
System.assertEquals('GET', request.getMethod());

HttpResponse response = new HttpResponse();
response.setHeader('Content-Type', 'application/json');
response.setStatusCode(200);
response.setBody('"status" : "success", "result" : "valid"');
return response;




Test



@IsTest
private class NeverBounceTest
@IsTest
static void NeverbounceEmailTest()
Account a = new Account(Name = 'Test acc');
insert a;
Contact c = new Contact(LastName = 'Test Con', AccountId = a.Id, Email='Test@test.com');
insert c;

Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
//System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);
Test.stopTest();












share|improve this question



















  • 1





    Do you intend to set this -- contact.Never_Bounce_Result__c = (String)results.get('result'); instead? The reason being your mock response returns an attribute named result instead of results.

    – Jayant Das
    Apr 22 at 17:03













4












4








4


1






Working on my first call out class. When a contact is created or has an email changed we need to make a call out to a third party service that verifies the email address.



Everything is working excep the final assertion. I expect a result of valid but the result is null. I have been reading through the documentation but not making sense of the rules around DML and mocks. I have included my call out class, test class and Mock. How can I get my assertion to pass and validate that the field I want updated by my callout has been updated?



Web-service



public with sharing class NeverBounceCallout 

@Future(callout=true)
public static void checkNeverBounce(Id id)
Contact contact = [SELECT Email, Never_Bounce_Result__c FROM Contact WHERE Id =: id LIMIT 1];
String email = contact.Email;
String url = 'https://api.neverbounce.com/v4/single/check?key=api_key&email=' + email;

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(url);
request.setMethod('GET');
HttpResponse response = http.send(request);
if(response.getStatusCode()==200)
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());

contact.Never_Bounce_Result__c = (String)results.get('result');
System.debug('json body = ' + results);
update contact;





My Mock



@IsTest
global class NeverBounceMock implements HttpCalloutMock{

global HttpResponse respond(HttpRequest request)
System.assertEquals('GET', request.getMethod());

HttpResponse response = new HttpResponse();
response.setHeader('Content-Type', 'application/json');
response.setStatusCode(200);
response.setBody('"status" : "success", "result" : "valid"');
return response;




Test



@IsTest
private class NeverBounceTest
@IsTest
static void NeverbounceEmailTest()
Account a = new Account(Name = 'Test acc');
insert a;
Contact c = new Contact(LastName = 'Test Con', AccountId = a.Id, Email='Test@test.com');
insert c;

Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
//System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);
Test.stopTest();












share|improve this question
















Working on my first call out class. When a contact is created or has an email changed we need to make a call out to a third party service that verifies the email address.



Everything is working excep the final assertion. I expect a result of valid but the result is null. I have been reading through the documentation but not making sense of the rules around DML and mocks. I have included my call out class, test class and Mock. How can I get my assertion to pass and validate that the field I want updated by my callout has been updated?



Web-service



public with sharing class NeverBounceCallout 

@Future(callout=true)
public static void checkNeverBounce(Id id)
Contact contact = [SELECT Email, Never_Bounce_Result__c FROM Contact WHERE Id =: id LIMIT 1];
String email = contact.Email;
String url = 'https://api.neverbounce.com/v4/single/check?key=api_key&email=' + email;

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(url);
request.setMethod('GET');
HttpResponse response = http.send(request);
if(response.getStatusCode()==200)
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());

contact.Never_Bounce_Result__c = (String)results.get('result');
System.debug('json body = ' + results);
update contact;





My Mock



@IsTest
global class NeverBounceMock implements HttpCalloutMock{

global HttpResponse respond(HttpRequest request)
System.assertEquals('GET', request.getMethod());

HttpResponse response = new HttpResponse();
response.setHeader('Content-Type', 'application/json');
response.setStatusCode(200);
response.setBody('"status" : "success", "result" : "valid"');
return response;




Test



@IsTest
private class NeverBounceTest
@IsTest
static void NeverbounceEmailTest()
Account a = new Account(Name = 'Test acc');
insert a;
Contact c = new Contact(LastName = 'Test Con', AccountId = a.Id, Email='Test@test.com');
insert c;

Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
//System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);
Test.stopTest();









apex rest-api






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 22 at 18:25









Jayant Das

19.5k21331




19.5k21331










asked Apr 22 at 16:24









Brooks JohnsonBrooks Johnson

1719




1719







  • 1





    Do you intend to set this -- contact.Never_Bounce_Result__c = (String)results.get('result'); instead? The reason being your mock response returns an attribute named result instead of results.

    – Jayant Das
    Apr 22 at 17:03












  • 1





    Do you intend to set this -- contact.Never_Bounce_Result__c = (String)results.get('result'); instead? The reason being your mock response returns an attribute named result instead of results.

    – Jayant Das
    Apr 22 at 17:03







1




1





Do you intend to set this -- contact.Never_Bounce_Result__c = (String)results.get('result'); instead? The reason being your mock response returns an attribute named result instead of results.

– Jayant Das
Apr 22 at 17:03





Do you intend to set this -- contact.Never_Bounce_Result__c = (String)results.get('result'); instead? The reason being your mock response returns an attribute named result instead of results.

– Jayant Das
Apr 22 at 17:03










2 Answers
2






active

oldest

votes


















2














The problem here is because of the way you are testing a future callout.



Because the updates are being carried out in a future method, thus while asserting, you don't get the value while you are asserting it between Test.startTest() and Test.stopTest(). Refer to this trailhead on how to test future methods, except below (emphasis mine).




The system collects all asynchronous calls made after the startTest. When stopTest is executed, all these collected asynchronous processes are then run synchronously. You can then assert that the asynchronous call operated properly.




So you will need to make the assertions in your test class, after Test.stopTest().



Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Test.stopTest();

// assertion now
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);


You will still need the below details to make sure your response returns correct value.




Your mock returns:



response.setBody('"status" : "success", "result" : "valid"');


and that you are trying to set the value of an attribute named results (notice the extra s here):



contact.Never_Bounce_Result__c = (String)results.get('results');


And thus your field Never_Bounce_Result__c would have never been set with the expected value here, thus failing your assertion.



For your assertion to work, you will need to set result as expected in the response and that it should be written as:



contact.Never_Bounce_Result__c = (String)results.get('result'); // no ending s here


Or, if you expect results, then that attribute needs to be set in the response accordingly.






share|improve this answer

























  • Hi Jayant and thank you. I did make that change you suggested. But forgot to edit my post. The assertion still fails. I will update now.

    – Brooks Johnson
    Apr 22 at 17:20











  • Have you put a debug to see what do you receive when you query it, no assertion, just a debug.

    – Jayant Das
    Apr 22 at 17:21






  • 1





    @BrooksJohnson I have updated my answer based on what I found while trying to replicate this issue.

    – Jayant Das
    Apr 22 at 18:14






  • 1





    @JayantDas Was JUST about to write a new answer with that information!

    – Thomas Taylor
    Apr 22 at 18:29






  • 1





    @ThomasTaylor I completely missed the future annotation at the first place and had in fact thought all wrong as how it was behaving here.

    – Jayant Das
    Apr 22 at 18:30


















5














Notice how you set the value in this field:



contact.Never_Bounce_Result__c = (String)results.get('results');


Does your mock ever set a results attribute? No. You need to add this attribute to your JSON map ('"status" : "success", ...').






share|improve this answer























  • Hi Adrian, I made that change and verified it in the debug log but the assertion is still failing. I updated the code above. And thank you for your help.

    – Brooks Johnson
    Apr 22 at 16:49











  • @BrooksJohnson Check your singular/plural. It's result in the mock's response and results in the class. BTW - you'd have been better off debugging the Contact field in the class, since that's what your assert is testing.

    – Thomas Taylor
    Apr 22 at 17:03











  • Yeah you need to use ..., "results": "value".

    – Adrian Larson
    Apr 22 at 18:18











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%2f258668%2fassertions-in-a-mock-callout-test%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









2














The problem here is because of the way you are testing a future callout.



Because the updates are being carried out in a future method, thus while asserting, you don't get the value while you are asserting it between Test.startTest() and Test.stopTest(). Refer to this trailhead on how to test future methods, except below (emphasis mine).




The system collects all asynchronous calls made after the startTest. When stopTest is executed, all these collected asynchronous processes are then run synchronously. You can then assert that the asynchronous call operated properly.




So you will need to make the assertions in your test class, after Test.stopTest().



Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Test.stopTest();

// assertion now
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);


You will still need the below details to make sure your response returns correct value.




Your mock returns:



response.setBody('"status" : "success", "result" : "valid"');


and that you are trying to set the value of an attribute named results (notice the extra s here):



contact.Never_Bounce_Result__c = (String)results.get('results');


And thus your field Never_Bounce_Result__c would have never been set with the expected value here, thus failing your assertion.



For your assertion to work, you will need to set result as expected in the response and that it should be written as:



contact.Never_Bounce_Result__c = (String)results.get('result'); // no ending s here


Or, if you expect results, then that attribute needs to be set in the response accordingly.






share|improve this answer

























  • Hi Jayant and thank you. I did make that change you suggested. But forgot to edit my post. The assertion still fails. I will update now.

    – Brooks Johnson
    Apr 22 at 17:20











  • Have you put a debug to see what do you receive when you query it, no assertion, just a debug.

    – Jayant Das
    Apr 22 at 17:21






  • 1





    @BrooksJohnson I have updated my answer based on what I found while trying to replicate this issue.

    – Jayant Das
    Apr 22 at 18:14






  • 1





    @JayantDas Was JUST about to write a new answer with that information!

    – Thomas Taylor
    Apr 22 at 18:29






  • 1





    @ThomasTaylor I completely missed the future annotation at the first place and had in fact thought all wrong as how it was behaving here.

    – Jayant Das
    Apr 22 at 18:30















2














The problem here is because of the way you are testing a future callout.



Because the updates are being carried out in a future method, thus while asserting, you don't get the value while you are asserting it between Test.startTest() and Test.stopTest(). Refer to this trailhead on how to test future methods, except below (emphasis mine).




The system collects all asynchronous calls made after the startTest. When stopTest is executed, all these collected asynchronous processes are then run synchronously. You can then assert that the asynchronous call operated properly.




So you will need to make the assertions in your test class, after Test.stopTest().



Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Test.stopTest();

// assertion now
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);


You will still need the below details to make sure your response returns correct value.




Your mock returns:



response.setBody('"status" : "success", "result" : "valid"');


and that you are trying to set the value of an attribute named results (notice the extra s here):



contact.Never_Bounce_Result__c = (String)results.get('results');


And thus your field Never_Bounce_Result__c would have never been set with the expected value here, thus failing your assertion.



For your assertion to work, you will need to set result as expected in the response and that it should be written as:



contact.Never_Bounce_Result__c = (String)results.get('result'); // no ending s here


Or, if you expect results, then that attribute needs to be set in the response accordingly.






share|improve this answer

























  • Hi Jayant and thank you. I did make that change you suggested. But forgot to edit my post. The assertion still fails. I will update now.

    – Brooks Johnson
    Apr 22 at 17:20











  • Have you put a debug to see what do you receive when you query it, no assertion, just a debug.

    – Jayant Das
    Apr 22 at 17:21






  • 1





    @BrooksJohnson I have updated my answer based on what I found while trying to replicate this issue.

    – Jayant Das
    Apr 22 at 18:14






  • 1





    @JayantDas Was JUST about to write a new answer with that information!

    – Thomas Taylor
    Apr 22 at 18:29






  • 1





    @ThomasTaylor I completely missed the future annotation at the first place and had in fact thought all wrong as how it was behaving here.

    – Jayant Das
    Apr 22 at 18:30













2












2








2







The problem here is because of the way you are testing a future callout.



Because the updates are being carried out in a future method, thus while asserting, you don't get the value while you are asserting it between Test.startTest() and Test.stopTest(). Refer to this trailhead on how to test future methods, except below (emphasis mine).




The system collects all asynchronous calls made after the startTest. When stopTest is executed, all these collected asynchronous processes are then run synchronously. You can then assert that the asynchronous call operated properly.




So you will need to make the assertions in your test class, after Test.stopTest().



Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Test.stopTest();

// assertion now
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);


You will still need the below details to make sure your response returns correct value.




Your mock returns:



response.setBody('"status" : "success", "result" : "valid"');


and that you are trying to set the value of an attribute named results (notice the extra s here):



contact.Never_Bounce_Result__c = (String)results.get('results');


And thus your field Never_Bounce_Result__c would have never been set with the expected value here, thus failing your assertion.



For your assertion to work, you will need to set result as expected in the response and that it should be written as:



contact.Never_Bounce_Result__c = (String)results.get('result'); // no ending s here


Or, if you expect results, then that attribute needs to be set in the response accordingly.






share|improve this answer















The problem here is because of the way you are testing a future callout.



Because the updates are being carried out in a future method, thus while asserting, you don't get the value while you are asserting it between Test.startTest() and Test.stopTest(). Refer to this trailhead on how to test future methods, except below (emphasis mine).




The system collects all asynchronous calls made after the startTest. When stopTest is executed, all these collected asynchronous processes are then run synchronously. You can then assert that the asynchronous call operated properly.




So you will need to make the assertions in your test class, after Test.stopTest().



Test.startTest();
Test.setMock(HttpCalloutMock.class, new NeverBounceMock());
NeverBounceCallout.checkNeverBounce(c.Id);
Test.stopTest();

// assertion now
Contact contactToCheck = [SELECT Never_Bounce_Result__c FROM Contact WHERE Id =: c.Id LIMIT 1];
System.assertEquals('valid', contactToCheck.Never_Bounce_Result__c);


You will still need the below details to make sure your response returns correct value.




Your mock returns:



response.setBody('"status" : "success", "result" : "valid"');


and that you are trying to set the value of an attribute named results (notice the extra s here):



contact.Never_Bounce_Result__c = (String)results.get('results');


And thus your field Never_Bounce_Result__c would have never been set with the expected value here, thus failing your assertion.



For your assertion to work, you will need to set result as expected in the response and that it should be written as:



contact.Never_Bounce_Result__c = (String)results.get('result'); // no ending s here


Or, if you expect results, then that attribute needs to be set in the response accordingly.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 22 at 18:27

























answered Apr 22 at 17:06









Jayant DasJayant Das

19.5k21331




19.5k21331












  • Hi Jayant and thank you. I did make that change you suggested. But forgot to edit my post. The assertion still fails. I will update now.

    – Brooks Johnson
    Apr 22 at 17:20











  • Have you put a debug to see what do you receive when you query it, no assertion, just a debug.

    – Jayant Das
    Apr 22 at 17:21






  • 1





    @BrooksJohnson I have updated my answer based on what I found while trying to replicate this issue.

    – Jayant Das
    Apr 22 at 18:14






  • 1





    @JayantDas Was JUST about to write a new answer with that information!

    – Thomas Taylor
    Apr 22 at 18:29






  • 1





    @ThomasTaylor I completely missed the future annotation at the first place and had in fact thought all wrong as how it was behaving here.

    – Jayant Das
    Apr 22 at 18:30

















  • Hi Jayant and thank you. I did make that change you suggested. But forgot to edit my post. The assertion still fails. I will update now.

    – Brooks Johnson
    Apr 22 at 17:20











  • Have you put a debug to see what do you receive when you query it, no assertion, just a debug.

    – Jayant Das
    Apr 22 at 17:21






  • 1





    @BrooksJohnson I have updated my answer based on what I found while trying to replicate this issue.

    – Jayant Das
    Apr 22 at 18:14






  • 1





    @JayantDas Was JUST about to write a new answer with that information!

    – Thomas Taylor
    Apr 22 at 18:29






  • 1





    @ThomasTaylor I completely missed the future annotation at the first place and had in fact thought all wrong as how it was behaving here.

    – Jayant Das
    Apr 22 at 18:30
















Hi Jayant and thank you. I did make that change you suggested. But forgot to edit my post. The assertion still fails. I will update now.

– Brooks Johnson
Apr 22 at 17:20





Hi Jayant and thank you. I did make that change you suggested. But forgot to edit my post. The assertion still fails. I will update now.

– Brooks Johnson
Apr 22 at 17:20













Have you put a debug to see what do you receive when you query it, no assertion, just a debug.

– Jayant Das
Apr 22 at 17:21





Have you put a debug to see what do you receive when you query it, no assertion, just a debug.

– Jayant Das
Apr 22 at 17:21




1




1





@BrooksJohnson I have updated my answer based on what I found while trying to replicate this issue.

– Jayant Das
Apr 22 at 18:14





@BrooksJohnson I have updated my answer based on what I found while trying to replicate this issue.

– Jayant Das
Apr 22 at 18:14




1




1





@JayantDas Was JUST about to write a new answer with that information!

– Thomas Taylor
Apr 22 at 18:29





@JayantDas Was JUST about to write a new answer with that information!

– Thomas Taylor
Apr 22 at 18:29




1




1





@ThomasTaylor I completely missed the future annotation at the first place and had in fact thought all wrong as how it was behaving here.

– Jayant Das
Apr 22 at 18:30





@ThomasTaylor I completely missed the future annotation at the first place and had in fact thought all wrong as how it was behaving here.

– Jayant Das
Apr 22 at 18:30













5














Notice how you set the value in this field:



contact.Never_Bounce_Result__c = (String)results.get('results');


Does your mock ever set a results attribute? No. You need to add this attribute to your JSON map ('"status" : "success", ...').






share|improve this answer























  • Hi Adrian, I made that change and verified it in the debug log but the assertion is still failing. I updated the code above. And thank you for your help.

    – Brooks Johnson
    Apr 22 at 16:49











  • @BrooksJohnson Check your singular/plural. It's result in the mock's response and results in the class. BTW - you'd have been better off debugging the Contact field in the class, since that's what your assert is testing.

    – Thomas Taylor
    Apr 22 at 17:03











  • Yeah you need to use ..., "results": "value".

    – Adrian Larson
    Apr 22 at 18:18















5














Notice how you set the value in this field:



contact.Never_Bounce_Result__c = (String)results.get('results');


Does your mock ever set a results attribute? No. You need to add this attribute to your JSON map ('"status" : "success", ...').






share|improve this answer























  • Hi Adrian, I made that change and verified it in the debug log but the assertion is still failing. I updated the code above. And thank you for your help.

    – Brooks Johnson
    Apr 22 at 16:49











  • @BrooksJohnson Check your singular/plural. It's result in the mock's response and results in the class. BTW - you'd have been better off debugging the Contact field in the class, since that's what your assert is testing.

    – Thomas Taylor
    Apr 22 at 17:03











  • Yeah you need to use ..., "results": "value".

    – Adrian Larson
    Apr 22 at 18:18













5












5








5







Notice how you set the value in this field:



contact.Never_Bounce_Result__c = (String)results.get('results');


Does your mock ever set a results attribute? No. You need to add this attribute to your JSON map ('"status" : "success", ...').






share|improve this answer













Notice how you set the value in this field:



contact.Never_Bounce_Result__c = (String)results.get('results');


Does your mock ever set a results attribute? No. You need to add this attribute to your JSON map ('"status" : "success", ...').







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 22 at 16:27









Adrian LarsonAdrian Larson

111k19122260




111k19122260












  • Hi Adrian, I made that change and verified it in the debug log but the assertion is still failing. I updated the code above. And thank you for your help.

    – Brooks Johnson
    Apr 22 at 16:49











  • @BrooksJohnson Check your singular/plural. It's result in the mock's response and results in the class. BTW - you'd have been better off debugging the Contact field in the class, since that's what your assert is testing.

    – Thomas Taylor
    Apr 22 at 17:03











  • Yeah you need to use ..., "results": "value".

    – Adrian Larson
    Apr 22 at 18:18

















  • Hi Adrian, I made that change and verified it in the debug log but the assertion is still failing. I updated the code above. And thank you for your help.

    – Brooks Johnson
    Apr 22 at 16:49











  • @BrooksJohnson Check your singular/plural. It's result in the mock's response and results in the class. BTW - you'd have been better off debugging the Contact field in the class, since that's what your assert is testing.

    – Thomas Taylor
    Apr 22 at 17:03











  • Yeah you need to use ..., "results": "value".

    – Adrian Larson
    Apr 22 at 18:18
















Hi Adrian, I made that change and verified it in the debug log but the assertion is still failing. I updated the code above. And thank you for your help.

– Brooks Johnson
Apr 22 at 16:49





Hi Adrian, I made that change and verified it in the debug log but the assertion is still failing. I updated the code above. And thank you for your help.

– Brooks Johnson
Apr 22 at 16:49













@BrooksJohnson Check your singular/plural. It's result in the mock's response and results in the class. BTW - you'd have been better off debugging the Contact field in the class, since that's what your assert is testing.

– Thomas Taylor
Apr 22 at 17:03





@BrooksJohnson Check your singular/plural. It's result in the mock's response and results in the class. BTW - you'd have been better off debugging the Contact field in the class, since that's what your assert is testing.

– Thomas Taylor
Apr 22 at 17:03













Yeah you need to use ..., "results": "value".

– Adrian Larson
Apr 22 at 18:18





Yeah you need to use ..., "results": "value".

– Adrian Larson
Apr 22 at 18:18

















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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f258668%2fassertions-in-a-mock-callout-test%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

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020