Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

#Trailhead Challenges2,399 discussing

Hands-on challenges are the “secret sauce” of Trailhead. Before searching for solutions to superbadge challenges, review the Salesforce Certification Program Agreement and Policies.

When copying the AccountWrapperTests code, getting compilation error for TestFactory 

 

#Trailhead Challenges

3 answers
  1. Feb 10, 4:47 AM

    Hello @Nishkam Agrawal

    TestFactory is a custom class which was created into this step - 

    https://trailhead.salesforce.com/content/learn/modules/unit-testing-on-the-lightning-platform/generate-data-for-tests

    Or just follow this Solution - 

    1. Create a Apex class TestFactory

    2. Copy this code 

    @isTest

    public class TestFactory {

    public static Account getAccount(String name, Boolean doInsert){

    Account a = new Account(name = name);

    if(doInsert){

    insert a;

    }

    return a;

    }

    public static Contact getContact(Id accountId, String fname, String lname, Boolean doInsert){

    Contact c = new Contact(firstName = fname, lastName = lname, accountId = accountId);

    if(doInsert){

    insert c;

    }

    return c;

    }

    public static void generateAccountWithContacts(Integer numContacts){

    Account a = getAccount('default account ltd', true);

    List<Contact> contacts = new List<Contact>();

    for(Integer i = 0; i < numContacts; i++){

    String contactName = 'contact' + i;

    contacts.add(getContact(a.id, contactName, contactName, false));

    }

    insert contacts;

    }

    public static Opportunity[] generateOppsForAccount(id accountId, Decimal amount, Integer numOpps){

    List<Opportunity> opps = new List<Opportunity>();

    for(Integer i = 0; i < numOpps; i++){

    Opportunity o = new Opportunity();

    o.name = 'Account ' + i;

    o.accountId = accountid;

    o.amount = amount;

    o.closeDate = Date.today().addDays(5);

    o.stageName = 'Prospecting';

    opps.add(o);

    }

    return opps;

    }

    public static User generateUser(String profileName){

    UserRole userRole = new UserRole(DeveloperName = 'TestingTeam', Name = 'Testing Team');

    insert userRole;

    User u = new User(

    ProfileId = [SELECT Id FROM Profile WHERE Name = :profileName].Id,

    LastName = 'last',

    Email = 'Cpt.Awesome@awesomesauce.com',

    Username = 'Cpt.Awesome@awesomesauce.com',

    CompanyName = 'Testing Co',

    Title = 'Captian',

    Alias = 'alias',

    TimeZoneSidKey = 'America/Los_Angeles',

    EmailEncodingKey = 'UTF-8',

    LanguageLocaleKey = 'en_US',

    LocaleSidKey = 'en_US',

    UserRoleId = userRole.Id

    );

    insert u;

    return u;

    }

    }

     

    https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T46SOSAZ

0/9000

Executing the method 'getAccount' from the Apex class 'AccountManager' failed. Either the service isn't configured with the correct urlMapping, is not global, does not have the proper method name or does not return the requested account and all of its contacts.

 

#Trailhead Challenges

3 answers
  1. Nov 1, 2024, 10:20 AM

    Hi @THRUPTHI K N,

    Thank you for reaching out to the community.

    May I recommend you to please follow the below steps & verify?

     

    Potential Causes and Fixes:

    • Incorrect Method Name or Annotation:
      • Check method name: Make sure the method in your "AccountManager" class is literally called "getAccount".
      • Check annotations: Ensure the "getAccount" method is annotated with "@HttpGet" to specify it as a web service method that can be accessed via a GET request.
    • Access Issues:
      • Global Keyword: Double-check that the "AccountManager" class is declared as "global" to allow external access.
      • URL Mapping: Verify that your Salesforce org is configured with a proper URL mapping that points to the "AccountManager" class.
    • Data Return Issues:
      • Return Type: Ensure the "getAccount" method is returning an "Account" object (or the appropriate data structure depending on your requirement).
      • Query Logic: If you're trying to retrieve related contacts, make sure your query is correctly fetching the account record with its associated contacts. 
      •  
      •  

    How to Troubleshoot:

    • Review your Apex Code:
    • Open the "AccountManager" class in your Salesforce developer console and carefully examine the "getAccount" method, verifying the method name, annotations, and return type.
    • Check Global Access:
    • Make sure the "AccountManager" class has the "global" keyword.
    • Verify URL Mapping:
    • Go to your Salesforce setup and check the "Apex Web Services" settings to confirm the correct URL mapping.
    • Test your Apex Class:
    • Create a test class to execute the "getAccount" method and verify if it returns the expected data. 

     

    I hope this will helps you to resolve the issue.

    Please feel free to reach out if there are any other issues on this.

     

    Please mark this as best answer as this can help other trailblazers resolving  the issue instead of raising duplicate question.

     

    Have a great day ahead!

     

    Thanks & regards

    Nagarjuna 

0/9000