Created
April 12, 2018 19:23
-
-
Save olgaloza/906a5ff3b5697dffccc4a1e4e584f3c5 to your computer and use it in GitHub Desktop.
Create Test Data for Apex Tests Challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@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; | |
} | |
} |
//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;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//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);
}
}