• Andrew Kennedy 6
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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!
 
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!