function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
thecrmninjathecrmninja 

Test Method for HTTP Post Asynchronous Callout

I am generating the following error in my Asynch Test Method:

 

Error: Compile Error: Method does not exist or incorrect signature: UpdBOPCallout.UpdBOPCalloutPOST() at line 26 column 8

 

 

 

the documentation that I have found doesn't make it clear why I am generating this error.  I am pretty sure I'm not passing through the right value or need to construct a method within the test but I am a bit lost at this point.  Any input that I could get would be very helpful.

 

//////////////////////////////////Controller//////////////////////////////////////////////////////// public class UpdBOPCallout { @future (callout=true) public static void UpdBOPCalloutPOST(Set <Id> LeadIDs) { Map<ID,Lead> leadMap = new Map<ID,Lead>( [select Lead.ID, Lead.DemoUserID__c, LastModifiedBy.User_Demo_Group__c from Lead where id IN :leadIDs] ) ; for( ID i : leadIDs ){ Lead BOPLead = leadMap.get(i); HttpRequest req = new HttpRequest(); req.setEndpoint('END POINT URL - REMOVED FOR FORUM POST'); req.setMethod('POST'); //System.debug('before soap body: ' + soapBody); //System.debug('after soap body: ' + soapBody); //(old non-variable approach)req.setBody('request_type=modify&login=BOPLead.customstring__c&groups=BOPLead.LastModifiedBy.customstring__c'); req.setBody('request_type=modify&login=' + BOPLead.customstring__c + '&groups=' + BOPLead.LastModifiedBy.customstring__c); //HttpResponse res = http.send(req); //System.debug(res.getBody()); } } } //////////////////////////////////Trigger/////////////////////////////////////////////////////////// trigger UpdateBOP on Lead (after Update) { Set<Id> leadIDs = new Set<Id>(); for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.new[i].OwnerID != Trigger.old[i].OwnerID && Trigger.old[i].ELPlead__c > 0) { //leadStatus.put(Trigger.new[i].OwnerId leadIDs.add( Trigger.new[i].Id ) ; } } UpdBOPCallout.UpdBOPCalloutPOST(leadIDs) ; } //////////////////////////////////Test Method/////////////////////////////////////////////////////// Global Class TestBOP{ static testMethod void BOPtest() { String QuB = [select Queue.id from QueueSobject where Queue.name='ELPLeadsUS'][0].Queue.id; Profile p = [select id from profile where name='Standard User']; User BOPae = new User(username='testBOPae@test.com', lastname='BOPae', email='testBOPae@test.com', alias='test', communitynickname='tBOP', User_Demo_Group__c='demo_default', LanguageLocaleKey = 'en_US', Localesidkey = 'en_US', TimeZoneSidKey = 'America/Los_Angeles', emailencodingkey = 'ISO-8859-1', profileid = p.id); insert BOPae; Lead leadBOP1 = new Lead(LastName='Test1', Company='Test1 Inc.', Email='test1@duptest.com', DemoUserID__c = 'demo123456', OwnerId=QuB); //Lead leadBOP2 = new Lead(LastName='Test2', Company='Test2 Inc.', Email='test4@duptest.com', DemoUserID__c = 'demo123456'); //Lead leadBOP3 = new Lead(LastName='Test3', Company='Test3 Inc.', Email='test5@duptest.com', DemoUserID__c = 'demo123456'); //Lead[] BOPleads = new Lead[] {leadBOP1, leadBOP2, leadBOP3}; //insert BOPleads; insert leadBOP1; leadBOP1.ownerid=BOPae.id; Update leadBOP1; Test.startTest(); //UpdBOPCallout.UpdBOPCalloutPOST(); System.debug('running myTest..'); Test.stopTest(); }}

 

 

soofsoof

thecrmninja wrote:

I am generating the following error in my Asynch Test Method:

 

Error: Compile Error: Method does not exist or incorrect signature: UpdBOPCallout.UpdBOPCalloutPOST() at line 26 column 8


 


 

 

The only Line 26 that I can find is in your testmethod, which you have commented out.  And that call does NOT pass the parameter of type Set<ID>, which the called method requires.  Can you please check again if the line number that you're seeing this error on is 26?

 

Also, I don't think that you can do callouts from test methods.  (This might've changed, but last time I checked, this is how it was)

 

-soof 

thecrmninjathecrmninja

That is the correct line (commented out to compile).

Adding (Set <Id>) generates an error messasge of :

Error: Compile Error: unexpected token: ')' at line 26 column 46 

 

Supposedly, you can test callouts but using start.test and stop.test but this is not formally documented (as far as I have seen).

testing callouts

 

I have tried several approaches to passing the set through but haven't had luck.  Admittedly, I'm not a programmer by trade, just by necessity.  ;)

soofsoof

You're saying that if you do 

 

.

Set<ID> leadIds = new Set<ID>();

leadIds.add(leadBOP1.Id);

UpdBOPCallout.UpdBOPCalloutPOST(leadIds);

 

you get an error?

 

-soof 

 

thecrmninjathecrmninja

Soof, many thanks!!!

 

I was not consctructing the set and adding (I merely added the "Set <Id>" inb/w the parenthesis), I was assuming my trigger would do that for me. 

 

For anybody working with Callouts, this approach got me 100% coverage on my Controller and 83% on my Trigger.  When/if I get higher coverage on the trigger, I will return and post my code. 

 

Again, thank you for your help Soof.  I suppose it's karma for the help I've lent others. 

thecrmninjathecrmninja

For anybody researching this in the future, here was the successful test method.  Thanks again soof.

 

 

Global Class TestBOP{ static testMethod void BOPtest() { String QuB = [select Queue.id from QueueSobject where Queue.name='ELPLeadsUS'][0].Queue.id; Profile p = [select id from profile where name='Standard User']; User BOPae = new User(username='testBOPae@test.com', lastname='BOPae', email='testBOPae@test.com', alias='test', communitynickname='tBOP', LanguageLocaleKey = 'en_US', Localesidkey = 'en_US', TimeZoneSidKey = 'America/Los_Angeles', emailencodingkey = 'ISO-8859-1', profileid = p.id, User_Demo_Group__c='Demo_default'); insert BOPae; Lead leadBOP1 = new Lead(LastName='Test1', Company='Test1 Inc.', Email='test1@duptest.com', DemoUserID__c = 'demo', OwnerId=QuB); /*Use the following if you want to test high volume triggers. Not an issue for me because of how I designed the system this is built inside of*/ //Lead leadBOP2 = new Lead(LastName='Test2', Company='Test2 Inc.', Email='test4@duptest.com', DemoUserID__c = 'demo'); //Lead leadBOP3 = new Lead(LastName='Test3', Company='Test3 Inc.', Email='test5@duptest.com', DemoUserID__c = 'demo'); //Lead[] BOPleads = new Lead[] {leadBOP1, leadBOP2, leadBOP3}; //insert BOPleads; insert leadBOP1; leadBOP1.ownerid=BOPae.id; Update leadBOP1; Test.startTest(); Set<ID> leadIds = new Set<ID>(); leadIds.add(leadBOP1.Id); UpdBOPCallout.UpdBOPCalloutPOST(leadIds); System.debug('running myTest..'); Test.stopTest(); }}