1

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.

@isTest
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;
    }
}
5

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. – Nathan White Aug 25 '17 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 Aug 25 '17 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.