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
Andrew Kennedy 6Andrew Kennedy 6 

Method does not exist or incorrect signature: void makeZipCallout(Id) from the type AccountClass

I am trying to build a test class for accounts that populate the city and state based on the zip code when they are created. I am getting the error however on line 25 "Method does not exist or incorrect signature: void makeZipCallout(Id) from the type AccountClass" I have tried multiple ways of correcting it but cannot for the life of me to figure out whats wrong.

Here is the test class:
@IsTest
public class TestAccountClass {
Static testMethod void AccountClassTest(){
Account a = new Account(Name = 'Test Class');

a.BillingCity = 'SAINT PAUL';
a.BillingState = 'MN';
a.BillingPostalCode = '55113';
a.BillingCountry = 'US';
insert a;   
Test.startTest();
HttpRequest request = new HttpRequest();
StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
mock.setStaticResource('GoogleMapsAPI');
mock.setStatusCode(200);
mock.setHeader('Content-Type', 'application/json');
mock.respond(request);
HttpResponse response = new HttpResponse();
JSONParser responseParser = JSON.createParser(response.getBody());

// Set the mock callout mode
Test.setMock(HttpCalloutMock.class, mock);

// Call the method that performs the callout
AccountClass.makeZipCallout(a.Id);

}
}

Here is the code used to call the city and state based on the zip if that helps :
// Use a name besides "Account" otherwise you'll get compilation problems due to symbol collision
public with sharing class AccountClass {
	
	private static boolean isTrigger = false;		// Pitfall #4: Used to prevent infinite loops
    public class accountException extends Exception {}

	/* format from ziptasticapi.com:  
	    {"country":"US","state":"CA","city":"SAN JOSE"}
	*/
	// Format returned by ziptastic API
	public class ziptasticReturn {
    	string country;
	    string state;
	    string city;
	}	
	 
	// Trigger Handler to do zipCodeLookup when new records are created
	//  Do this after the record is created so we have an ID we can reference
	public static void onAfterInsert( List<Account> triggerNew)
	{
		// Pitfall #4 - Prevent infinite loops
		if (isTrigger == true) {
			return;				// Just return if this is called as a result of our DML operation
		} else
		   isTrigger = true;	// Set this so we know we caused ourselves to be called again
		
		// Must pass IDs & not SObjects to @future because the SObject may change by the time @future executes
		List<Id> accountsId = new List<Id>();
		for (Account a : triggerNew) {
			accountsId.add(a.Id);
		}	
		system.debug(LoggingLevel.Info, 'onAfterInsert called with '+triggerNew+'; sending IDs='+accountsId);
		makeZipCallout(accountsId);
	}
	
	// Pitfall #1 & #2 - Triggers must do callouts from an '@future' and (callout = true) anotated function
	@future (callout = true) 
	private static void makeZipCallout(List<Id>acct)
	{
		system.debug(LoggingLevel.Info, 'makeZipCallout with '+acct);
		string resp;
		
		// Pitfall #3 - Fetch records of the IDs for updating
		List<Account> accountSet = [SELECT Id, BillingPostalCode, BillingCity, BillingState, BillingCountry
									FROM account 
									WHERE Id = :acct];
		
		for (Account a : accountSet) {
			
			// Note this version of the API is only for the US
		    string endpoint ='http://ziptasticapi.com/';
		    endpoint = endpoint + a.BillingPostalCode;
		    system.debug(LoggingLevel.Info,'zipCode.clslling endpoint='+endpoint);
	 
		    HttpRequest req = new HttpRequest();
		    HttpResponse res = new HttpResponse();
		    Http http = new Http();
		    req.setMethod('GET');
		    req.setEndpoint(endpoint);
	 
		    try {
		      res = http.send(req);
		      if (res.getStatusCode() != 200) {
		        throw new accountException(res.getStatus());
		      }
		    } catch (accountException e) {
		      system.debug(LoggingLevel.Error, 'Error HTTP response code = '+res.getStatusCode()+'; calling '+endpoint );
		      return;
		    }
	  
	    	resp = res.getBody();
	    	JSONParser parser = JSON.createParser(resp);
	    	parser.nextToken(); // Start object "{"
        
        	ziptasticReturn zipInfo = new ziptasticReturn();
		    // This convenient method reads the JSON stream into a class in one go
		    zipInfo = (ziptasticReturn) parser.readValueAs(ziptasticReturn.class);
		    a.BillingState = zipInfo.state;
		    a.BillingCity = zipInfo.city;
		    a.BillingCountry = zipInfo.country;
	    	
		}    
		update accountSet;		// Call DML operation to update
		isTrigger = false;		// Pitfall #4 - Trigger is done so reset this
	}		 //makeZipCallout()
}

Any help is appreciate!
 
Best Answer chosen by Andrew Kennedy 6
Niraj Kr SinghNiraj Kr Singh
And you should pass List of Account Id as parameter from Test class as well.
Like :
Replace your this line:
AccountClass.makeZipCallout(a.Id);

By:

List<Id> lstAccIds = new List<Id>();
lstAccIds.add(a.Id);
AccountClass.makeZipCallout(lstAccIds);

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

From you code I can see that below method has input as List where as in test class you are passing only one value not the List

private static void makeZipCallout(List<Id>acct)

AccountClass.makeZipCallout(a.Id);

a.Id will have only one value not list that is why the error says invalid method signature.

Try something like below 


List<Id> accountsIdlist = new List<Id>(); 

accountsIdlist.add(a.Id);

​AccountClass.makeZipCallout(a.Id);

Please mark it as solved if my reply was helpful, it will make it available
for others as a proper solution.

Best Regards,
​Sandhya
 
Niraj Kr SinghNiraj Kr Singh
Hi Andrew Kennedy,

Your this method is AccountClass.makeZipCallout(a.Id) is private in your AccountClass class that way it not accessible in test class TestAccountClass.
Make this method makeZipCallout - public OR use this anotation before this method it @TestVisible.

Refference : https://developer.salesforce.com/forums/?id=906F0000000BJQJIA4


If it solves your problem, mark your Ans.

Thanks
Niraj

 
Niraj Kr SinghNiraj Kr Singh
And you should pass List of Account Id as parameter from Test class as well.
Like :
Replace your this line:
AccountClass.makeZipCallout(a.Id);

By:

List<Id> lstAccIds = new List<Id>();
lstAccIds.add(a.Id);
AccountClass.makeZipCallout(lstAccIds);
This was selected as the best answer
Andrew Kennedy 6Andrew Kennedy 6
Thanks Niraj Kr Singh your code to pass the list of Account Id worked the best
Niraj Kr SinghNiraj Kr Singh
Thanks Andrew,

I want to know that, What you have used with your class method: makeZipCallout(), Either Public or @TestVisible.

If you have used @TestVisible, Make sure your Org  version should be at least 30 (@testvisible is released before winter 15) or greater.

Cheers !!