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
JosephTJosephT 

Isse with (After Update) and Test

I created the following Trigger to update/associate a child record to an existing parent record.  These updates take place on an 'upsert' import.  The initial trigger worked on individual record updates but failed on the upsert due to 'too many SOQL quiries'.  So, I updated my trigger but now my test is passing but not relating to the trigger so I can't even test it yet as it looks like I have 0% code coverage.

TRIGGER:
trigger VAS_InsertProjectionIdsOnServices on VAS_Services__c (after update) {
List <VAS_Sales_Projections__c> sales_projections = [Select Id, Package_Name__c, Month__c FROM VAS_Sales_Projections__c];
for (VAS_Services__c S: Trigger.new)
{
for (VAS_Sales_Projections__c P: sales_projections)
{
if (P.Package_Name__c == S.Service_Name__c && P.Month__c.month() == S.Purchase_Date__c.month()&& P.Month__c.year() == S.Purchase_Date__c.year())
{

//Do logic here


S.VAS_Sales_Projections__c = P.Id;
S  = [SELECT Id From VAS_Services__c LIMIT 1];
    Update S;
}
}
}
}

TEST CLASS


@isTest(SeeAllData=true)

private class VAS_InsertProjectionIdsOnServicesTest{

  public static testmethod void test() {

    //Create VAS Sales Projection

    VAS_Sales_Projections__c P = new VAS_Sales_Projections__c (Package_Name__c = 'Complimentary Copies', Month__c=Date.today());
   
   
    //Create VAS Services

    VAS_Services__c S = new VAS_Services__c(Service_Name__c='Complimentary Copies', Purchase_Date__c= DateTime.Now());
   
    //Relate Records

    S.VAS_Sales_Projections__c = P.Id;
   
    S  = [SELECT Id From VAS_Services__c LIMIT 1];

}
}

So, the Test passes BUT, is not relating to the Trigger...  The trigger won;t even show up in the Develoepr Console when I open it????



PrasanntaPrasannta (Salesforce Developers) 
Hi,

In your trigger you are performing an update DML operation. In test class as well you need to do that DML operation, that is why is it showing  0% code coverage.

Hope this information helps.