I have a trigger that changes a date field based on activity on related object. The trigger works fine but the test class that I created didn't work and has 0 coverage.

So basically, if there is a change/update to any record in TOpp__c, then the parent record related to it (on object Part__c) should be updated on field Last_Updated__c.

Can anyone please help?

The trigger.

trigger Trigger1 on TOpp__c (after insert) {

Map<String, TRAcctOpp__c> traMap = new Map<String, TOpp__c>();
for (TOpp__c t : Trigger.new){
    traMap.put(t.Opportunity__c, t);

Set<String> traId = new Set<String>();    
for (TOpp__c t : Trigger.new) {

List<Part__c> partc = [SELECT Id, Last_Updated__c FROM Part__c WHERE Stage__c IN ('Design Opportunity', 'Design In', 'Design Win Pending', 'Design Win Reviewing') AND Opportunity__c =: traId];

for (Part__c c : partc) {
    c.Last_Updated__c = system.today();
update partc;


And below is the test class I created.

private class TestClassLastUpdateonAccountTrip{

    public static Datetime partcLastUpdated;
    public static String partcOpp;

    static testMethod void TestMethod1() {

        // Get the current date of last update field.
        Part__c partc       = [SELECT Id, Last_Updated__c, Opportunity__c FROM Part__c WHERE Stage__c IN ('Design Opportunity', 'Design In', 'Design Win Pending', 'Design Win Reviewing') LIMIT 1];
        partcLastUpdated    = partc.Last_Updated__c;
        partcOpp            = partc.Opportunity__c;

        //Now make changes to the accounts trip
        TOpp__c accTrip = [SELECT Opportunity__c FROM TOpp__c WHERE Opportunity__c =:partcOpp ];
        accTrip.Opportunity__c = '006E0000099X883fIAI'; 
        update accTrip;



1 Answer 1


Your trigger is after insert and I am not seeing an insert statement in your test class. You probably are aware you should ideally create test data and especially not hardcode Ids in the test.

  • Thank you !! that worked. It was missing insertion code.
    – Gops
    Commented May 20, 2016 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .