• Punit Choudhary
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Salesforce Developer
  • KVP Business Solution Bangalore

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

Hello Community, 

Having an issue with a Bulk Apex Trigger challenge here, hope you guys can assist. 

Here is the critieria:
To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'
With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
This challenge specifically tests 200 records in one operation.

Here is the Error Received:
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 My Code:

trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {
 
    List<Task> taskList = new List<Task>();
         
    for(Opportunity opp : Trigger.new) {
         
        //Only create Follow Up Task only once when Opp StageName is to 'Closed Won' on Create
        if(Trigger.isInsert) {
            if(Opp.StageName == 'Closed Won') {
                taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
                }
            }
             
            //Only create Follow Up Task only once when Opp StageName changed to 'Closed Won' on Update
            if(Trigger.isUpdate) {
                if(Opp.StageName == 'Closed Won'
                && Opp.StageName != Trigger.oldMap.get(opp.Id).StageName) {
                    taskList.add(new Task(Subject = 'Follow Up Test Task', WhatId = opp.Id));
                }
        }      
    }
     
        if(taskList.size()>0) {       
            insert taskList;       
    }   
}


Please Note: I appended the code from SumitKumar from another post which worked for others as I changed my code to suit the suggested code.above. It seems I may have an insert dml exception issue maybe caused by an earlier code insertion. PLEASE ADVISE

I have this very simple class..  
trigger RestrictContactByName on Contact (before insert, before update) {
    //check contacts prior to insert or update for invalid data
    For (Contact c : Trigger.New) {
        if(c.LastName == 'INVALIDNAME') {   //invalidname is invalid
            c.AddError('The Last Name "'+c.LastName+'" is not allowed for DML');
        }
    }
}
.. and the corresponding Test Class:  
@isTest
private class TestRestrictContactByName {

	@isTest static void metodoTest() {
		
		List listaContatti = new List();
		Contact c1 = new Contact(FirstName='Francesco', LastName='Riggio');
		Contact c2 = new Contact(LastName = 'INVALIDNAME');
		listaContatti.add(c1);
		listaContatti.add(c2);
		
		//insert listaContatti;
		
		// Perform test
        Test.startTest();
        Database.SaveResult [] result = Database.insert(listaContatti, false);
        Test.stopTest(); 
		
		c1.LastName = 'INVALIDNAME';
		update c1;
       		
	}
	
}

When I run the Test class from the Developer Console I get 100% of coverage on the RestrictContactByName class but, when I check the challenge on the trailhead it returns the error:

Challenge not yet complete... here's what's wrong: The 'RestrictContactByName' class did not achieve 100% code coverage via your test methods

Has someone had my same issue?
Hi there, I 'm trying to complete the "Automating Processes with the Lightning Process Builder" challenge in TrailHead but I get the following error :
Encountered unhandled fault when running process Update_contact_adress/
301240000004FXO exception by user/organization: 00D24000000JsNt/{4}

The flow failed to access the value for myVariable_current.Account.ShippingCountry because it hasn't been set or assigned.
caused by element : FlowRecordUpdate.myRule_1_A1
caused by: The flow failed to access the value for myVariable_current.Account.ShippingCountry because it hasn't been set or assigned.
Salesforce Error ID: 490660201-42718 (736882147)

Any idea what could be could wrong ?