Skip to main content
Hello! 

I am working on the challenge for the BulkApexTriggers section and I keep receiving the following error. I am not sure what is wrong with my system. I have a Discount Percentage field under Accounts and Opportunities and that field is not required for the challenge. I received this error message for a lot of triggers I have tried to imput, and I'm not really sure what is going on. 

Challenge Not yet complete... here's what's wrong: 

There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Discount_Percent__c]: [Discount_Percent__c]

Here is the Trigger I have entered into my Developer Console. 

trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {

List<Task> taskList = new List<Task>();

for (Opportunity opp : [SELECT Id, StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :Trigger.new]){

taskList.add(new Task(Subject = 'Follow Up Test Task',

WhatId = opp.Id));

}

if(taskList.size()>0){

insert taskList;

}

}

Thanks for your help! 
2 个回答
  1. 2016年10月13日 15:46
    Hi Alexis,

    It looks like you have a field (Discount_Percent__c) on the Task object that is required, so you need to add that when creating a new Task record.  So change line 7 of your code to this...

    taskList.add(new Task(Subject = 'Follow Up Test Task',

                                         Discount_Percent__c = 0,

                                         WhatId = opp.Id));

    If you have an actual Discount Percentage you can use that, but in my example I'm just setting it to 0.

    I hope this helps.

    Jason
0/9000