1

I am using a WebService callout, returning a string, and testing it; I am quite new to it. The problem is in the Mock class. When I am debugging it, the response element is created, the string is associated and the response_element is inserted correctly in this way:

tO.AOResponse_element a_element = new tO.AOResponse_element();    
a_element.AOResult = 'http://www.google.com/archive';
System.debug('MOCK Set response: '+ a_element.AOResult);
response.put('response__x', a_element);
System.debug('MOCK Set response: '+ a_element); 

But after this, the flows goes to the original class (not the mock) and when it returns from it, it gives an error attempting to de-reference a line object, and that line references to the original string to be returned in the non-mock class.

How can I solve it?

3

The problem is with this line:

response.put('response__x', a_element);

The correct key value is response_x, not response__x.

|improve this answer|||||
  • Many thanks. So if the program doesn't recognize that field, it goes in the original webservice class and fails, I guess. – Franktrt Mar 14 '17 at 15:22
  • @Franktrt Yes, if the response value doesn't match exactly, this would cause the problem. – sfdcfox Mar 14 '17 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.