Skip to main content
Martin Larizzate ha fatto una domanda in #Trailhead Challenges
Hi Guys!

 

I'm working on the Trailhead "Create Test Data for Apex Tests (https://trailhead.salesforce.com/content/learn/modules/apex_testing/apex_testing_data)".

 

Just when i'm trying to check the result of my own code, it throws an error but i think im doing all on the right way.

 

My Code:

public class RandomContactFactory {

public static List<Contact> generateRandomContacts(Integer numContacts, String lastName){

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

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

Contact c = new Contact(LastName=lastName);

contacts.add(c);

}

return contacts;

}

}

Error Message:

Executing the 'generateRandomContacts' method failed. Either the method does not exist, is not static, or did not return the correct set of Contact records.

 

Did someone received the same message?

 

 
2 risposte
  1. 2 set 2019, 14:35
    Please use below code: 

     

    public class RandomContactFactory {

     

        public static List<Contact> generateRandomContacts(integer param1, string param2){

     

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

     

            for(integer i=1; i<=param1;i++){

     

                contact con = new contact();

     

                con.firstName = param2+i;

     

                con.LastName = param2+i;

     

               conlist.add(con); 

     

            }

     

            return conlist;

     

        }

     

    }