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
Snehal Gaware 15Snehal Gaware 15 

test class for before update trigger on custom object

Hi, i need help to write test class for following trigger.
trigger UpdateProblemTaskOwner on SC_Problem_Task__c  (after insert, after update, after delete,before update) {
    if (Trigger.isBefore && Trigger.isUpdate)
    {
        for(SC_Problem_Task__c  pt : Trigger.new)
            {
                List<Group> qid = [select Id from Group where Name = : pt.Assignment_Group__c and Type = 'Queue'];
                for(Group g : qid)
                {
                    pt.OwnerId = g.id;
                    System.debug('updated');
                }
        }
    }
}

Thanks in advance.
Marcin Trofiniak 9Marcin Trofiniak 9

@isTest
private class testUpdateProblemTaskOwner
{

@isTest
public void theTriggerTest()
{

List<SC_Problem_Task__c> testData = new List<SC_Problem_Task__c>();

// Now create some data and put them in the list
// Do fake instert of them and then fake update make sure that the fields you check in your SOQL have proper values
// and done...

}

}

 

 

By the way yout trigger will reach governer limit very fast ... you shouldn't have SOQL in for loop. Get all of the group records and work with them instead of querrying for them in for loop.