function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Surabhi AgrawalSurabhi Agrawal 

test class insert records with delay

Hi,

I have written a trigger in which fields are updated based on previous record.  In the test class thus i need to insert 2 records with a delay in between them. So that the 1st record is created and based on that the next record should be updated.

Thanks in advance!
Best Answer chosen by Surabhi Agrawal
AshlekhAshlekh
Hi,

Below codes help you but you have mentioned wrong function i supposed
@isTest
public class TestRoundRobin2Inc {
    public static void insertOneNewIncident() {
       BMCServiceDesk__Incident__c inc1 = new BMCServiceDesk__Incident__c();
         inc1.BMCServiceDesk__FKClient__c='005o0000000FprNAAS';
         inc1.BMCServiceDesk__FKCategory__c='a17o0000000QvkOAAS';
         inc1.OwnerId='00Go0000000o2dfEAA';
		insert inc1;
    }

  static testMethod void insertTwoNewIncident() {
     
       BMCServiceDesk__Incident__c inc2 = new BMCServiceDesk__Incident__c();
         
         inc2.BMCServiceDesk__FKClient__c='005o0000000FprNAAS';
         inc2.BMCServiceDesk__FKCategory__c='a17o0000000QvkOAAS';
         inc2.OwnerId='00Go0000000o2dfEAA';
		 insert inc2;
		 if(inc2.id !=null)//now if record is inserted than id is assigned to record than next line will execute
         TestRoundRobin.insertNewIncident();
    }
}

IF it helps you than please mark it as a solution and ENJOY APEX

All Answers

Rajendra ORajendra O
We don't have delay method in Apex/trigger, but test case can be developed for mentioned case, please post your code.
AshlekhAshlekh
 
Hi,

Rajendra said correct we don't any delay method in APEX langauge. If you mentioned your code here and condation what actually wants then we can help you.

Thanks
Surabhi AgrawalSurabhi Agrawal
Here is my test class. I have a before trigger that updates record on incident object based on the previous incident record.


@isTest
public class TestRoundRobin2Inc {
    public static void insertOneNewIncident() {
     
       BMCServiceDesk__Incident__c inc1 = new BMCServiceDesk__Incident__c();
         
         inc1.BMCServiceDesk__FKClient__c='005o0000000FprNAAS';
         inc1.BMCServiceDesk__FKCategory__c='a17o0000000QvkOAAS';
         inc1.OwnerId='00Go0000000o2dfEAA';
        

    insert inc1;
    }

//*******inserting 2nd incident record which should be inserted after the 1st recod has been inserted, but both of them are getting inserted simultaneuously.

  static testMethod void insertTwoNewIncident() {
     
       BMCServiceDesk__Incident__c inc2 = new BMCServiceDesk__Incident__c();
         
         inc2.BMCServiceDesk__FKClient__c='005o0000000FprNAAS';
         inc2.BMCServiceDesk__FKCategory__c='a17o0000000QvkOAAS';
         inc2.OwnerId='00Go0000000o2dfEAA';

    insert inc2;
     TestRoundRobin.insertNewIncident();
    }




}
AshlekhAshlekh
Hi,

Below codes help you but you have mentioned wrong function i supposed
@isTest
public class TestRoundRobin2Inc {
    public static void insertOneNewIncident() {
       BMCServiceDesk__Incident__c inc1 = new BMCServiceDesk__Incident__c();
         inc1.BMCServiceDesk__FKClient__c='005o0000000FprNAAS';
         inc1.BMCServiceDesk__FKCategory__c='a17o0000000QvkOAAS';
         inc1.OwnerId='00Go0000000o2dfEAA';
		insert inc1;
    }

  static testMethod void insertTwoNewIncident() {
     
       BMCServiceDesk__Incident__c inc2 = new BMCServiceDesk__Incident__c();
         
         inc2.BMCServiceDesk__FKClient__c='005o0000000FprNAAS';
         inc2.BMCServiceDesk__FKCategory__c='a17o0000000QvkOAAS';
         inc2.OwnerId='00Go0000000o2dfEAA';
		 insert inc2;
		 if(inc2.id !=null)//now if record is inserted than id is assigned to record than next line will execute
         TestRoundRobin.insertNewIncident();
    }
}

IF it helps you than please mark it as a solution and ENJOY APEX
This was selected as the best answer
Surabhi AgrawalSurabhi Agrawal
Thank you for looking into it.
But i am getting only 36% code coverage and the code lines where the secord record is being update based on the first one are in Red showing they were not covered.
AshlekhAshlekh
Hi can you mention your class code or trigger code here  
Surabhi AgrawalSurabhi Agrawal
Thank you Ashlekh it works!