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
JoeyLenJoeyLen 

Apex test class

I have 2 triggers, one creates a case once an opportunity reaches Closed Won and a services drop down is Yes.  The other comes back and checks a Services Completed check box once the case is closed.  Both triggers work fine in my sandbox and I have tested the Opportunity trigger out to 100%.  I am struggling getting the second trigger to test out to 100%, stuck @ 66%.
The first trigger was easy, just needed the system to create an opportunity with certain settings and viola.  To create the second trigger (which in hindsight I could have created one class to test both triggers but that is another discussion) I copied first trigger test class and then added some additional instructions but cannot get it to compile.

The trigger is below and I am getting the compile error:

"Error: Compile Error: Variable does not exist: c.Status at line 27 column 9"

I know I have made some simple mistake but being new to this I am at a loss.

public class Installed_Services_Opp_Test {

    static testmethod void insertOpportunity() {
   
        Opportunity o = new opportunity();
       
        o.Name = 'Test';
        o.Opportunity_Profile__c = 'Existing Customer';
        o.LeadSource = 'VAR';
        o.Are_Installed_Services_Required__c = 'Yes';
        o.StageName = 'Closed Won';
        o.Type = 'EMC - Mobius';
        o.Amount = 100000;
        o.TotalOpportunityQuantity = 20;
        o.CloseDate = System.today();
        o.Promised_Delivery_Date__c = System.today();
        o.Go_live_date__c = System.today();
       
       
        insert o;
{
   
        list<Case> cc= new list<Case>();
       
        c.Status = 'Closed';
        c.Quantity__c = 1;
        c.Origin = 'Installed Services';
      
       
       
        insert c;
       
       
}

}
}
ShashForceShashForce
In this code, you did not initialize a case object. Please try adding this line after you initialized the case list:

case c = new case();
JoeyLenJoeyLen
Shashank, Thanks for the update and I added the line of code but it is still throwing an error, albeit a different one. The new code is below and now the system is telling me: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] public class Installed_Services_Opp_Test { static testmethod void updateOpportunity() { Opportunity o = new opportunity(); list oo= new list(); o.Name = 'Test'; o.Opportunity_Profile__c = 'Existing Customer'; o.LeadSource = 'VAR'; o.Are_Installed_Services_Required__c = 'Yes'; o.StageName = 'Closed Won'; o.Type = 'EMC - Mobius'; o.Amount = 100000; o.TotalOpportunityQuantity = 20; o.CloseDate = System.today(); o.Promised_Delivery_Date__c = System.today(); o.Go_live_date__c = System.today(); update o; { Case c = new case(); list cc= new list(); c.Status = 'Closed'; c.Quantity__c = 1; c.Origin = 'Installed Services'; insert c; } } } Thanks in advance for your assistance, Joey Len Salesforce Administrator www.enovatemedical.com | 888.909.8906 x 225