0

I got the below test class,

@isTest
public with sharing class CategoryHelperTest {

        private static boolean testDataCreated = false;
        private static Scheme__c ss;
        private static Scheme__c ss2;
        private static Scheme__c ss3;
        private static Scheme__c ss4;
        private static Scheme__c ss5;
        private static Scheme__c ss6;

public static void tester(){
        ss = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme');
        insert ss;
        ss2 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestgScheme2');
        insert ss2;
        ss3 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme3');
        insert ss3;
        ss4 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme4');
        insert ss4;
        ss5 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme5');
        insert ss5;
        ss6 = new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme6');
        insert ss6;

I want to use a list for schemes, instead inserting data one by one. How can I get this done using a List ?

1 Answer 1

3

Haven't you try populating a list and inserting?

public static void tester(){
  List<Scheme__c> insertList = new List<Scheme__c>();
  insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme'));
  insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme2'));
  insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme3'));
  insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme4'));
  insertList.add(new Scheme__c(Name = 'TestScheme', Description__c = 'TestScheme5'));

  insert insertList;

}
3
  • i'm using the five different scheme ids separately to setup some other master-detail data so if I use a list how can I use the Ids separately ?
    – Tinkerbell
    Commented Aug 1, 2014 at 9:42
  • Sorry, not much clear what you are asking. Better to post another question for this with relevant details.
    – highfive
    Commented Aug 1, 2014 at 9:59
  • I reposted the question with the title 'Inserting test data using a list or a map to reduce the number of DMLs and get different Ids for different tests' Please have a look and hope it's clear enough.
    – Tinkerbell
    Commented Aug 1, 2014 at 10:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .