+ Start a Discussion
Darshit Pathak 3Darshit Pathak 3 

How to generate bulk test data in apex test class without numeric value?

I have a validation which does not accepts only alphabetic characters for contact first and last name. No numerics are allowed.
So how can I generate bulk data with unique names for my test class without using numeric value in first last name.
Ajay K DubediAjay K Dubedi
Hi Darshit,

Try following code:
 
List<Contact> conlist = new List<Contact>();
//For 500 records
String r ='a';
for(integer i=0; i<50; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'a';
    conlist.add(c);
}
r ='b';
for(integer i=50; i<100; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'b';
    conlist.add(c);
}
r = 'c';
for(integer i=100; i<150; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'c';
    conlist.add(c);
}
r = 'd';
for(integer i=150; i<200; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'd';
    conlist.add(c);
}
r = 'e';
for(integer i=200; i<250; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'e';
    conlist.add(c);
}
r = 'f';
for(integer i=250; i<300; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'f';
    conlist.add(c);
}
r = 'g';
for(integer i=300; i<350; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'g';
    conlist.add(c);
}
r = 'h';
for(integer i=350; i<400; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'h';
    conlist.add(c);
}
r = 'i';
for(integer i=400; i<450; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'i';
    conlist.add(c);
}
r = 'j';
for(integer i=450; i<500; i++) {
    Contact c = new Contact();
    c.FirstName = 'Fname' + r;
    c.LastName = 'Lname' + r;
    r = r + 'j';
    conlist.add(c);
}
System.debug('size-->'+conlist.size()+'conlist-->'+conlist);

Extend this for more records.        
              
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi