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
SFDC coderSFDC coder 

Test records are not inserted

Hi all,

I have a test class where in i am trying to insert the test record but i doubt on they are being inserted properly

below is my code

public class VisitHandler_Test
 //create test data
    static testMethod void createTestData()
        Account acc=new Account(Name='Test Account',Channel__c='On-trade',
                                                   Premise_Type__c='Brown Café');
       	insert acc; 
        List<POSItemAccountLink__c> posLst=new List<POSItemAccountLink__c>();
        POSItem__c posItem=new POSItem__c(name='test item',type__c='Killer Item');
        insert posItem;
        for(Integer i=0;i<2;i++)
            POSItemAccountLink__c pos=new POSItemAccountLink__c();
        insert posLst;
        System.assertEquals(posItem.Name,'test item');

Also i have mentioned an asset statement to check if the record is inserted successfully or no
but i dont know how do i check whether that asset statement is executed successfully or no as it does not appear in the logs

Any help would be appreciated

John WestenhaverJohn Westenhaver
Why do you think your test data is not being inserted?

Also, if a system.assert() fails, the transaction stops immediately - that's how you know it was successful, because it doesn't stop.
SFDC Coder,
If an assert statement doesnt execute succesfully in test class, it will throw an error.

If you are not getting an error in the debug log, it means the assert executed successfully.

In your code, if you want to check if the record has been inserted successfully, you can use the statement like below. This will insure that posItem has ID in it, which means it inserted fine.


David JorjaniDavid Jorjani
Test data only exists during the test. The data will not be accessible afterwards. So you won't see it after tests are done.

If assert passes without an error, your data is entered properly. You can do a system.debug(posLst) to make sure that the items have ids associated with them.
SFDC coderSFDC coder
hi all,

Thankyou for stopping by and replying to my query..
well the actual problem was that the lst which was suppose to invoke the trigger was written before the insert posLst; statement due to which the posLst was not covering the code in my Handler class.So i had to write it after all the insert statements like this

insert acc;
insert posItem;

        insert tempLst;
        insert posLst;
        insert visLst; 
This solved my query
According to the above code,the two inserts prior to test.start method when mentioned inside test.startTest() throws an error stating they are not inserted.Also they are the master object records.Can this may be teh reason?