Skip to main content
Pam Vandekerkhove (xx) が「#Apex」で質問
I am new to Apex trigger/class coding.  I was able to create a simple trigger that works, but I am having trouble with code coverage and can't roll it to the production environment.  I would appreciate any help with Apex Class coding.  (or could you point me toward a tutorial?) Thank you in advance.

My trigger is as follows:

trigger WorkstreamStamp on Project__c (before insert) {

    For(Project__c p : Trigger.New)

    {

         If(p.Workstream__c == null)

         {

           List<Account> incomingprojinfo = [Select Workstream__c FROM  Account WHERE Id =:p.Sponsor_Account_Ultimate_Parent__c LIMIT 1];

                               {

               p.Workstream__c = incomingprojinfo[0].Workstream__c;

           }                                                      

          

         }

       

    }                           

}
4 件の回答
  1. 2018年1月19日 2:40

    You can try to build some test class like this:

    @isTest

    private class TestTriggerWorkstreamStamp {

    static testmethod void sendemail(){

    Account acc = new Account();

    acc.Name = 'Test Account';

    insert acc;

    Project__c projects = new Project__c();

    projects.Name = 'Test Project';

    projects.Sponsor_Account_Ultimate_Parent__c = acc.Id;

    insert projects;

    }

    }

    It should cover all your lines code.