Assertions In A Mock Callout Test Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Community Moderator Election ResultsSystem.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

Does using the inspiration rules for character defects tend to encourage players to display MGS?

Does the Pact of the Blade warlock feature allow me to customize the properties of the pact weapon I create?

Import keychain to clean macOS install?

Why do people think Winterfell crypts is the safest place for women, children & old people?

What documents does someone with a long-term visa need to travel to another Schengen country?

Alternative to "rest in peace" (RIP)

Coin Game with infinite paradox

Are Flameskulls resistant to magical piercing damage?

Why does my GNOME settings mention "Moto C Plus"?

Unix AIX passing variable and arguments to expect and spawn

Has a Nobel Peace laureate ever been accused of war crimes?

What's the connection between Mr. Nancy and fried chicken?

How to create a command for the "strange m" symbol in latex?

How to mute a string and play another at the same time

Can 'non' with gerundive mean both lack of obligation and negative obligation?

How do I deal with an erroneously large refund?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

lm and glm function in R

tabularx column has extra padding at right?

Lemmatization Vs Stemming

Assertions In A Mock Callout Test

Weaponising the Grasp-at-a-Distance spell

Why do C and C++ allow the expression (int) + 4*5?

What could prevent concentrated local exploration?



Assertions In A Mock Callout Test



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Community Moderator Election ResultsSystem.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
    4 hours ago

















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
    4 hours ago













4












4








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
















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 3 hours ago









Jayant Das

18.8k21331




18.8k21331










asked 5 hours ago









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
    4 hours ago












  • 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
    4 hours ago







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
4 hours ago





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
4 hours ago










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
    4 hours ago











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

    – Jayant Das
    4 hours ago






  • 1





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

    – Jayant Das
    3 hours ago






  • 1





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

    – Thomas Taylor
    3 hours ago






  • 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
    3 hours ago


















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
    4 hours ago











  • @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
    4 hours ago











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

    – Adrian Larson
    3 hours ago











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
    4 hours ago











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

    – Jayant Das
    4 hours ago






  • 1





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

    – Jayant Das
    3 hours ago






  • 1





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

    – Thomas Taylor
    3 hours ago






  • 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
    3 hours ago















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
    4 hours ago











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

    – Jayant Das
    4 hours ago






  • 1





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

    – Jayant Das
    3 hours ago






  • 1





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

    – Thomas Taylor
    3 hours ago






  • 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
    3 hours ago













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 3 hours ago

























answered 4 hours ago









Jayant DasJayant Das

18.8k21331




18.8k21331












  • 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
    4 hours ago











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

    – Jayant Das
    4 hours ago






  • 1





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

    – Jayant Das
    3 hours ago






  • 1





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

    – Thomas Taylor
    3 hours ago






  • 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
    3 hours ago

















  • 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
    4 hours ago











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

    – Jayant Das
    4 hours ago






  • 1





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

    – Jayant Das
    3 hours ago






  • 1





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

    – Thomas Taylor
    3 hours ago






  • 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
    3 hours ago
















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
4 hours ago





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
4 hours ago













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

– Jayant Das
4 hours ago





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

– Jayant Das
4 hours ago




1




1





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

– Jayant Das
3 hours ago





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

– Jayant Das
3 hours ago




1




1





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

– Thomas Taylor
3 hours ago





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

– Thomas Taylor
3 hours ago




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
3 hours ago





@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
3 hours ago













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
    4 hours ago











  • @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
    4 hours ago











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

    – Adrian Larson
    3 hours ago















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
    4 hours ago











  • @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
    4 hours ago











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

    – Adrian Larson
    3 hours ago













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 5 hours ago









Adrian LarsonAdrian Larson

110k19121259




110k19121259












  • 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
    4 hours ago











  • @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
    4 hours ago











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

    – Adrian Larson
    3 hours ago

















  • 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
    4 hours ago











  • @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
    4 hours ago











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

    – Adrian Larson
    3 hours ago
















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
4 hours ago





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
4 hours ago













@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
4 hours ago





@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
4 hours ago













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

– Adrian Larson
3 hours ago





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

– Adrian Larson
3 hours ago

















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

How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

Category:Tremithousa Media in category "Tremithousa"Navigation menuUpload media34° 49′ 02.7″ N, 32° 26′ 37.32″ EOpenStreetMapGoogle EarthProximityramaReasonatorScholiaStatisticsWikiShootMe

Dokschytsy (Steed) Kwelen | NawigatsjuunBelarus: Vitebsk Region, citypopulation.de