Multiple record insertion at a time (without for) in Apex #inSalesforce
The Class:
public class insertTestRecordsatOnce{
public void multipleTestRecords(){
List<Candidate__c> cnd = new List<Candidate__c>();
Candidate__c candidateRec;
candidateRec = new Candidate__c(Name='candidateSample1',Country__c='CountrySample1');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample2',Country__c='CountrySample2');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample3',Country__c='CountrySample3');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample4',Country__c='CountrySample4');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample5',Country__c='CountrySample5');
cnd.add(candidateRec);
insert cnd;
}
}
public void multipleTestRecords(){
List<Candidate__c> cnd = new List<Candidate__c>();
Candidate__c candidateRec;
candidateRec = new Candidate__c(Name='candidateSample1',Country__c='CountrySample1');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample2',Country__c='CountrySample2');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample3',Country__c='CountrySample3');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample4',Country__c='CountrySample4');
cnd.add(candidateRec);
candidateRec = new Candidate__c(Name='candidateSample5',Country__c='CountrySample5');
cnd.add(candidateRec);
insert cnd;
}
}
Test it:
To run the script individually from Anonymous Window in Developer Console
insertTestRecordsatOnce x = new insertTestRecordsatOnce();
x.multipleTestRecords();
x.multipleTestRecords();
Comments
Post a Comment