+ Start a Discussion
Somasundaram S 1Somasundaram S 1 

test class for trigger for oldmap

how to write test class for below trigger for oldmap please advise me

trigger cus on Sample_Transaction__c(before update) {
    Call2__c Objopp;
    Map<Id,Sample_Transaction__c> o = new Map<Id,Sample_Transaction__c>();
    o = trigger.oldMap;
     ApexPages.StandardController controller = new ApexPages.standardController(Objopp);
     UnlockRecordDuringApprovalCon ObjUnlock= new UnlockRecordDuringApprovalCon(controller);
        for (Sample_Transaction__c objCustomer: Trigger.new) {
       if (objCustomer.Status__c== 'Active') {
       if(objCustomer.Status__c!= o.get(objCustomer.Id).Status__c) {
       List<String> s = new List<String>{objCustomer.Call_ID__c};
                      for(Call2__c c: [SELECT id FROM Call2__c WHERE Name IN :s]){
                                     ObjUnlock.processRecord(c.id );
Apoorv Saxena 4Apoorv Saxena 4

Are you abe to achieve the desired functionality through the Apex trigger code you have written?

Try this code for you Test Class :
private class Testcus {
	static testMethod void testingCus(){
		// Insert a test record for Call2__c with all the required fields.
		Sample_Transaction__c st = new Sample_Transaction__c();
		st.name = 'Test ST';
		st.Status__c = 'Any Other Value';
		 and set values for all the required fields.
		insert st;

		// Now update the Status__c value to 'Active'
		st.Status__c = 'Active';
		update st;

Please let me kknow if this helps!