0

I'm having issues with setting the dummy data as there are a lot of required fields on the system. I'm getting this error when attempting to create a dummy Marketing Source. And I apologize on the amount of questions on this one particular trigger.

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, The Start Date is required: [i360__Start__c]

I get this error when trying to insert my i360__Marketing_Source__c record.

Here is the Test code

@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__Marketing_Source__c source = new i360__Marketing_Source__c();
       source.i360__Type__c = 'Amazon Services';
       source.i360__Start__c = Date.today();
       source.i360__End__c = Date.today().addYears(1); 
       insert source;

       i360__Lead_Source__c leadsource = new i360__Lead_Source__c();
       leadsource.i360__Source__c = source.Id;
       leadsource.i360__Prospect__c = Pros.Id;
       leadsource.i360__Taken_On__c = Date.today();
       insert leadsource;   

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

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

    }
}

Also, a side question. Is there a faster way to input this dummy data in order to get the trigger code coverage above the minimum?

  • 1
    Which object is throwing the error (highlight line as well from this class). Also will want to check your validation rule to make sure it is correct. – Eric Aug 25 '17 at 21:53
  • Please take a moment to visit the help center, scroll through the tour, and read How to Ask. The more specific you are in your question, the better help you will receive (and more quickly, in general). Any time you have an error, you should include its message verbatim (which you did) and make it explicitly clear which line threw it. – Adrian Larson Aug 25 '17 at 21:56
  • 1
    Verifying that your code works as you expect it to work is the most important part of unit testing. It’s also one of the things that Force.com developers commonly neglect. Unit tests that do not verify the results of the code aren’t true unit tests. They are commonly referred to as smoke tests, which aren’t nearly as effective or informative as true unit tests. - How to Write Good Unit Tests – Adrian Larson Aug 25 '17 at 21:59
  • Regardless of the quality of your testing paradigm, we can't really answer this without seeing your trigger(s) on the affected object. – Adrian Larson Aug 25 '17 at 22:00
  • @Eric The changes should have been made. – Nathan White Aug 25 '17 at 22:06
0

I was able to fix my issue by hunting through the triggers that had been made before I started. I finally found it and all I needed was a start time on the staff object.

The fix for this was to add

       staff.i360__Start__c = Date.today();

to the staff test object.

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.