-
-
Save olgaloza/906a5ff3b5697dffccc4a1e4e584f3c5 to your computer and use it in GitHub Desktop.
//@isTest | |
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); | |
} | |
//insert contactList; | |
System.debug(contactList.size()); | |
return contactList; | |
} | |
} |
tq
//This will work
public class RandomContactFactory{
public static List generateRandomContacts(Integer noOfContacts, String conList){
List ContactList = new List();
for(Integer i = 1; i <= noOfContacts; i++){
Contact con = new Contact(firstName = ''+i, LastName = 'Test');
ContactList.add(con);
}
return ContactList;
}
}
//correct answer should be
//@istest
public class RandomContactFactory{
//@istest
public static List generateRandomContacts(Integer noOfContacts, String LName){
List ContactList = new List();
for(Integer i = 1; i <= noOfContacts; i++){
Contact con = new Contact(FirstName = 'Test'+i, LastName = LName);
ContactList.add(con);
}
System.debug(contactList.size());
return ContactList;
}
}
The below passes the test:
public class RandomContactFactory{
public static List generateRandomContacts(Integer numCtts, String LastName){
List ctts = new List();
for(Integer i = 0; i <numCtts; i++){
Contact con = new Contact(firstName = 'Test'+i, LastName = 'Test');
ctts.add(con);
}
insert ctts;
return ctts;
}
}
This is nice to give an idea of what to do, but it will not complete the challenge. It needs a random FirstName and a provided LastName.