• Prashant Kumar 455
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
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:
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
Hi all,

I'm stuck in the Apex Integration Services - Apex SOAP Callouts challenge with the following message "The Apex class 'ParkLocator' does not appear to be calling the SOAP endpoint.".

Could you please advise ?
Hi,

The main question is: How do we add custom article fields to the article detail page of the mobile version of Public Knowledge Base 3?

We are setting up a Public Knowledge Base at a client, which is the official Public Knowledge Base 3 (PKB3) from the AppExchange. We have enabled the mobile setup for PKB as well, which is working fine, except that it doesn't show custom article fields.

We have created a few Article types (FAQ, Guideline, etc.), which all have the Rich Text field called 'Cotent' (content__c). We want to display this field on the article detail page of the mobile layout, so we go to PKB 2 Settings | PKB Knowledge Article Layouts | Add Knowledge Article. We then choose one of the knowledge articles (i.e. Guideline__kav) and see the possible fields to add to the layout. All of the fields look like system information (i.e. Id, IsDeleted, CreatedById, etc.), which are pretty useless to an external customer reading the article. See screenshot below.

We looked at the code which loads the available fields which is quoted below. We have tried running the code as an administrator to rule out field level security of the article, which revealed the same fields as explained above.

A Public Knowledge Base, with a build-in mobile site which can only display system information on mobile article detail page seems a bit weird, so we are hoping we missed something, and that it is in fact possible to display custom article fields on a the mobile layout?
public static Object getKnowledgeTypesAndFields(String d){
          pkb_SecurityHandler.canAccess( new Schema.SObjectType[] {KnowledgeArticleVersion.sObjectType} );

            map<String,Object> ret = new map<String,Object>();
            String thisType = '';
            Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
            Set<String> keySet = gd.keySet();
            Schema.DescribeSObjectResult descRes;
            Map<String, Schema.SObjectField> fieldMap;
            for (String key : keySet) {
                Schema.SObjectType objectType = gd.get(key);
                if (key.endsWith('ka') || key.endsWith('kb')) {
                    descRes = objectType.getDescribe();
                    thisType = descRes.getName().replace('ka','kav');
                    fieldMap = descRes.fields.getMap();
                    ret.put(thisType,fieldMap.keySet());
                }
            }
          return ret;
    }
PKB Mobile Knowledge Articles Layouts

Thank you
Kristian