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
ShawnaFisherShawnaFisher 

Trigger test class

I am very new to APEX code, and I have created a trigger:

 

trigger AddSRSplit on Opportunity (after insert) {

Sales_Rep_Split_Revenue__c[] splitList = new Sales_Rep_Split_Revenue__c[]{};


    for (Opportunity o : Trigger.new) {


    splitList.add(new Sales_Rep_Split_Revenue__c
    ( Name = 'No Split',
          opportunity__C = o.ID,
          Split__c = 100,
          Sales_Rep__c = o.OwnerId )); }

        insert splitList; }

 

that i need a test case for.  I have not a clue on what I need to do.  Any help would be appreciated!

Bhawani SharmaBhawani Sharma
Create a opportunity record. It should automatically create a Sales_Rep_Split_Revenue__c record. In your test class, you will only have to insert opportunity and then query database to fetch the Sales_Rep_Split_Revenue__c record where opportunity__C = newlyCreatedOpportunityid
Yoganand GadekarYoganand Gadekar

Since your trigger on Opportunity you will need to craete and insert Opportunity record programatically.

Plus you have to make sure you give all the required fields for your opportunity record. Now this mandatory fields could themself be some other records likwe for example it may have account look up, so u have to make sure you craete all such records in avance before u insert yourn opportunity record.

 

Thanks,

Salesforce Example at my blog.