You need to sign in to do that
Don't have an account?
Chaitra GV
Executing the 'generateRandomContacts' method failed
I've written the below code which looks fine as per the instructions given in the challenge.
But I'm facing an error when trying to resolve the challenge. Please help.
Error: Executing the 'generateRandomContacts' method failed. Either the method does not exist, is not static, or did not return the correct set of Contact records.
Code:
public class RandomContactFactory {
public static List<Contact> generateRandomContacts(Integer n, String Lastname)
{
List<Contact> ct = new List<Contact>();
Contact c = new Contact();
for(Integer i=0; i<n; i++)
{
c.FirstName = 'Test '+i;
c.LastName = Lastname;
ct.add(c);
}
return ct;
}
}
But I'm facing an error when trying to resolve the challenge. Please help.
Error: Executing the 'generateRandomContacts' method failed. Either the method does not exist, is not static, or did not return the correct set of Contact records.
Code:
public class RandomContactFactory {
public static List<Contact> generateRandomContacts(Integer n, String Lastname)
{
List<Contact> ct = new List<Contact>();
Contact c = new Contact();
for(Integer i=0; i<n; i++)
{
c.FirstName = 'Test '+i;
c.LastName = Lastname;
ct.add(c);
}
return ct;
}
}
public class RandomContactFactory {
public static List<Contact> generateRandomContacts(Integer numContactsToGenerate, String FName) {
List<Contact> contactList = new List<Contact>();
for(Integer i=0;i<numContactsToGenerate;i++) {
Contact c = new Contact(FirstName=FName + ' ' + i, LastName = 'Contact '+i);
contactList.add(c);
System.debug(c);
}
System.debug(contactList.size());
return contactList;
}
}
required
It will work.
public class RandomContactFactory {
public static List <Contact> generateRandomContacts (Integer numAccts, String nombre) {
// system.debug('paso 1');
List <Contact> accts = new List <Contact>();
// system.debug('paso 2');
for(Integer i=0;i<numAccts;i++) {
// system.debug('paso 3');
Contact a = new Contact(LastName=nombre + ' ' + i, FirstName =nombre + ' ' + i);
// system.debug('paso 4');
accts.add(a);
// system.debug('paso 5');
}
// system.debug('paso 6');
insert accts;
// system.debug('paso 7');
return accts;
}
}