I have an apex test class that is not working due to not having an appointment tied to it. I'm not sure how I've messed up. I know this is a beyond easy fix but I've been looking at it for too long and I'd like an outside perspective.

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Cannot add a sale with a missing appointment: [i360__Appointment__c]

Here is the apex test class.

private class HomeDepotStoreTest {
    static testMethod void TestHomeDepotStores()
       i360__Staff__c staff = new i360__Staff__c();
       staff.Name = '2036';
       insert staff;

       i360__Prospect__c Pros = new i360__Prospect__c();
       Pros.Name ='Bob Joe';
       Pros.Referral_Store__c = '2036';
       Pros.i360__Phone_1__c = '(123) 123-1234';
       Pros.i360__Primary_Last_Name__c = 'TESTMCTEST';
       insert Pros;

       i360__Appointment__c App = new i360__Appointment__c();
       App.Name = '2036';
       App.i360__Prospect__c = Pros.Id;   

       i360__Sale__c a = new i360__Sale__c();
       a.Name ='2036';
       a.i360__Appointment__c = App.Id;
       insert a;

1 Answer 1


add insert App; as the fifth line from the bottom. You never insert the i360__Appointment__c record.

  • Haha. Thank you so much, that took me a lot longer than I care to admit. Commented Aug 25, 2017 at 16:22
  • 1
    @NathanWhite If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.
    – Adrian Larson
    Commented Aug 25, 2017 at 16:42

You must log in to answer this question.

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