• Arya9029
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
TRIGGER:
trigger FNR on Fortnightly_Update__c (before insert,before update)
{
    List<Public_Holiday_List__c> FNR =[select id from Public_Holiday_List__c];
    system.debug('FNR Trigger holiday List Count >>> '+FNR.size());
}

TEST CLASS:
@isTest public static void Insert_fortnightly_Already_Exist()
{
        try
    {
         Fortnightly_Update__c f=new Fortnightly_Update__c();
            f.Account__c=[select id from Account where id='0016F00003uavZd'].id;
            insert f;
            
        }catch(DMLException e)
        {
            System.debug('Insert_fortnightly_Already_Exist_Error >>> '+e.getMessage());
        }
}


When the following code is executed in Anonymous Window, it give output 19
List<Public_Holiday_List__c> FNR =[select id from Public_Holiday_List__c];
system.debug('FNR Trigger holiday List Count >>> '+FNR.size());

However, when the same is executed within a trigger as shown above, the output is 0.

I would like to know what is wrong, why the SOQL is not returning the record when excuted within the trigger.
TRIGGER:
trigger FNR on Fortnightly_Update__c (before insert,before update)
{
    List<Public_Holiday_List__c> FNR =[select id from Public_Holiday_List__c];
    system.debug('FNR Trigger holiday List Count >>> '+FNR.size());
}

TEST CLASS:
@isTest public static void Insert_fortnightly_Already_Exist()
{
        try
    {
         Fortnightly_Update__c f=new Fortnightly_Update__c();
            f.Account__c=[select id from Account where id='0016F00003uavZd'].id;
            insert f;
            
        }catch(DMLException e)
        {
            System.debug('Insert_fortnightly_Already_Exist_Error >>> '+e.getMessage());
        }
}


When the following code is executed in Anonymous Window, it give output 19
List<Public_Holiday_List__c> FNR =[select id from Public_Holiday_List__c];
system.debug('FNR Trigger holiday List Count >>> '+FNR.size());

However, when the same is executed within a trigger as shown above, the output is 0.

I would like to know what is wrong, why the SOQL is not returning the record when excuted within the trigger.