You need to sign in to do that
Don't have an account?
Ryan Adams 173
Generate an Apex class using WSDL2Apex and write a test class.
Please help me resolve this challenge:
https://trailhead.salesforce.com/modules/apex_integration_services/units/apex_integration_soap_callouts
The Challenge is as follows:
Generate an Apex class using WSDL2Apex and write a test class.
Generate an Apex class using WSDL2Apex for a SOAP web service, write unit tests that achieve 100% code coverage for the class using a mock response, and run your Apex tests.
Use WSDL2Apex to generate a class called 'ParkService' in public scope using this WSDL file. After you click the 'Parse WSDL' button don't forget to change the name of the Apex Class Name from 'parksServices' to 'ParkService'.
Create a class called 'ParkLocator' that has a 'country' method that uses the 'ParkService' class and returns an array of available park names for a particular country passed to the web service. Possible country names that can be passed to the web service include Germany, India, Japan and United States.
Create a test class named ParkLocatorTest that uses a mock class called ParkServiceMock to mock the callout response.
The unit tests must cover all lines of code included in the ParkLocator class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.
The error I receive when checking the challencge is:
Challenge Not yet complete... here's what's wrong:
Executing the 'country' method on 'ParkLocator' failed. Make sure the method exists with the name 'country', is public and static, accepts a String and returns an array of Strings from the web service.
Here is the code I am using:
and
and
Any help which can be provided is greatly appreciated. If you could advise me at raadams173@gmail.com if you reply with a solution, I can log in to check it.
Thanks.
Ryan
https://trailhead.salesforce.com/modules/apex_integration_services/units/apex_integration_soap_callouts
The Challenge is as follows:
Generate an Apex class using WSDL2Apex and write a test class.
Generate an Apex class using WSDL2Apex for a SOAP web service, write unit tests that achieve 100% code coverage for the class using a mock response, and run your Apex tests.
Use WSDL2Apex to generate a class called 'ParkService' in public scope using this WSDL file. After you click the 'Parse WSDL' button don't forget to change the name of the Apex Class Name from 'parksServices' to 'ParkService'.
Create a class called 'ParkLocator' that has a 'country' method that uses the 'ParkService' class and returns an array of available park names for a particular country passed to the web service. Possible country names that can be passed to the web service include Germany, India, Japan and United States.
Create a test class named ParkLocatorTest that uses a mock class called ParkServiceMock to mock the callout response.
The unit tests must cover all lines of code included in the ParkLocator class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.
The error I receive when checking the challencge is:
Challenge Not yet complete... here's what's wrong:
Executing the 'country' method on 'ParkLocator' failed. Make sure the method exists with the name 'country', is public and static, accepts a String and returns an array of Strings from the web service.
Here is the code I am using:
public class ParkLocator { public static String[] country(String ctry) { ParkService.ParksImplPort prk = new ParkService.ParksImplPort(); return prk.byCountry(ctry); } }
and
@isTest global class ParkServiceMock implements WebServiceMock { global void doInvoke( Object stub, Object request, Map<String, Object> response, String endpoint, String soapAction, String requestName, String responseNS, String responseName, String responseType) { // start - specify the response you want to send ParkService.byCountryResponse response_x = new ParkService.byCountryResponse(); List<String> myStrings = new List<String> {'Park1','Park2','Park3'}; response_x.return_x = myStrings; // end response.put('response_x', response_x); } }
and
@isTest private class ParkLocatorTest { @isTest static void testCallout() { // This causes a fake response to be generated Test.setMock(WebServiceMock.class, new ParkServiceMock()); // Call the method that invokes a callout List<String> result = new List<String>(); List<String> expectedvalue = new List<String>{'Park1','Park2','Park3'}; result = ParkLocator.country('India'); // Verify that a fake result is returned System.assertEquals(expectedvalue, result); } }
Any help which can be provided is greatly appreciated. If you could advise me at raadams173@gmail.com if you reply with a solution, I can log in to check it.
Thanks.
Ryan
Use below code for ParkLocator class. If this not resolves the problem then use a new Developer Org for completing the Challenge.
Let me know if this helps :)
All Answers
I believe that you have changed the proxy class name from parksServices to ParkService and run the tests once before checking the challenge (because those are the only things not visible to me in the question above).
Can you Check the challenge once again and look for the log file in Developer Console?
This log file may show some path.
Use below code for ParkLocator class. If this not resolves the problem then use a new Developer Org for completing the Challenge.
Let me know if this helps :)
I kept trying offered solutions in other threads and eventually came across this one:
James Loghry
Joe, as others have seen, try removing the spaces between ParkLocator and the curly brace and the country method and curly brace, and change String[] to List<String> to see if that helps.
1public class ParkLocator{
2 public static List<String> country(String countryName){
3 ParkService.ParksImplPort park = new ParkService.ParksImplPort();
4 return (List<String>)park.byCountry(countryName);
5 }
6}
I changed my ParkLocater class making these corrections, reran the Challenge and was successful.
After completing the challenge, I went back and replaced the ParkLocater code with that provided by Amit above, and once again the challenge check ran correctly. Kudos to Amit!
Once again, thanks.
Ryan
I am facing the following error while trying to complete the challenge
Challenge not yet complete... here's what's wrong:
There was an unexpected error in your org which is preventing this assessment check from completing: System.CalloutException: Web service callout failed: Unable to find Apex package for :parksServices
Can someone help?
Thanks,
Navin
i am getting following error after saveing the below classs.
invalid api version 0.0.
public class ParkLocator {
public static String[] country(String country){
ParkService.ParksImplPort parks = new ParkService.ParksImplPort();
String[] parksname = parks.byCountry(country);
return parksname;
}
}
public static String[] country(String country){
ParkService.ParksImplPort parks = new ParkService.ParksImplPort();
String[] parksname = parks.byCountry(country);
return parksname;
}
}
=====================================================================================================
1. Invalid type: ParkService.ParksImplPort
2. Variable does not exist: parks
i am getting following error ????
Because you have not created ParkService class and therefore you cannot create its object
public class ParkService {
public class byCountryResponse {
public String[] return_x;
private String[] return_x_type_info = new String[]{'return','http://parks.services/',null,'0','-1','false'};
private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
private String[] field_order_type_info = new String[]{'return_x'};
}
public class byCountry {
public String arg0;
private String[] arg0_type_info = new String[]{'arg0','http://parks.services/',null,'0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
private String[] field_order_type_info = new String[]{'arg0'};
}
public class ParksImplPort {
public String endpoint_x = 'https://th-apex-soap-service.herokuapp.com/service/parks';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://parks.services/', 'ParkService'};
public String[] byCountry(String arg0) {
ParkService.byCountry request_x = new ParkService.byCountry();
request_x.arg0 = arg0;
ParkService.byCountryResponse response_x;
Map<String, ParkService.byCountryResponse> response_map_x = new Map<String, ParkService.byCountryResponse>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'http://parks.services/',
'byCountry',
'http://parks.services/',
'byCountryResponse',
'ParkService.byCountryResponse'}
);
response_x = response_map_x.get('response_x');
return response_x.return_x;
}
}
}
Invalid type: ParkService.ParksImplPort is coming may be because that class created from wsdl is not visible to the ParkLocator class. can you pls paste all the code like the wsdl class, and test classes?!
contact me (https://bestprimevideo.com/contact-us/)
Universe Tale (https://www.universetale.com/)
Learn Forget (https://learnforget.com/)
I am gettig below error. Can someonce guide.
Executing the 'country' method on 'ParkLocator' failed. Make sure the method exists with the name 'country', is public and static, accepts a String, and returns an array of Strings from the web service.
Affiliate Marketing (https://www.dakshadoer.com/blog/why-you-should-use-affiliate-marketing/)
Sukanya Samriddhi Yojana
https://soochnaportal.com/sukanya-samriddhi-yojana/
Manav Sampada Portal
https://soochnaportal.com/manav-sampada-portal/
i have tried everything but only your solution gave me help thankyou so much
public class ParkLocator {
public static List<String> Country(String name) {
List<String> countries = new List<String>();
ParkService.ParksImplPort park = new ParkService.ParksImplPort();
countries = park.byCountry(name);
return countries;
}
}
@isTest
private class ParkLocatorTest {
@isTest static void testCallout() {
// This causes a fake response to be generated
Test.setMock(WebServiceMock.class, new ParkServiceMock());
// Call the method that invokes a callout
String[] parks = ParkLocator.Country('Japan');
// Verify that a fake result is returned
system.assert(parks.size() > 0);
}
}
@isTest
global class ParkServiceMock implements WebServiceMock {
global void doInvoke(
Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
// start - specify the response you want to send
ParkService.byCountryResponse response_x = new ParkService.byCountryResponse();
response_x.return_x = new List<String>{'Germany', 'India', 'Japan', 'United States'};
response.put('response_x', response_x);
}
}