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
Ram S 49Ram S 49 

Test Case for Trigger

Hi All,
Need help with below test case

@isTest

private class TestTimecardManager{

@testSetup static void setup()
{
Contact conct = new contact(FirstName='Test', LastName='TestLastName', Phone='4565465789');

insert conct;

Project__c prj = new Project__c(Name ='MyProject');

insert prj;
}

@isTest static void TestInserMethodValid()
{

//code to access contact and project objects

Assignment__c assign = new Assignment__c(Contact__c=conct.Title,Project__c='MyProject',Start_Date__c=Date.parse('01/01/2019'),End_Date__c=Date.parse('10/01/2019'));

}
}


As you see I need to access the contact and project object in TestInserMethodValid() method.

Need your help!.
pranav_sanvatsarkarpranav_sanvatsarkar
Hi Ram S 49,

The data created in @testSetup annotatted method acts as data available in the org. So, in order to access this data you will need to query the records in your TestInserMethodValid() method where you have written the comment - //code to access contact and project objects.

Hope this helps!

Thanks,
Pranav Sanvatsarkar.
Oleg IshchukOleg Ishchuk
Hi, Ram S 49!
Create 2 SOQL inside TestInserMethodValid method. One is for Contact, another - for Project. And then use it.