• Apurv Saxena
  • NEWBIE
  • 14 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
I am stuck with this challenge for more than 2 days and getting this error. Please have a look at my code and let me know where i need to make a change.
Challenge Not yet complete... here's what's wrong: 
The 'MaintenanceRequest' trigger does not appear to be handling bulk operations correctly. For the positive use case of inserting and updating more than 200 records, it did not produce the expected outcome.

My helper Class : 
public class MaintenanceRequestHelper {
    
    public static void updateWorkOrders(List<Case> ClosedCaseList){
		
        List <Case> insertCaseList = new List<Case>();
        for(Case c : ClosedCaseList){
            Case newCase = new Case();
            newCase.Type = 'Routine Maintenance';
            //newCase.Subject = c.Subject;
            newCase.Status = 'New';
            newCase.Vehicle__c = c.Vehicle__c;
            newCase.Date_Reported__c = Date.today();
            newCase.Date_Due__c = date.today();
            newCase.Equipment__c = c.Equipment__c;
            insertCaseList.add(newCase);
        }
        if(insertCaseList.size()>0){
            insert insertCaseList;
        }
    }        
    
}

My Trigger : 
trigger MaintenanceRequest on Case (after update) {
    List<Case> caseList = [Select Id, Vehicle__c, Vehicle__r.Name, type, Equipment__c from Case where status = 'Closed' Limit 10];
    
    for(Case c : caseList){
        if((c.Type == 'Repair') || (c.Type == 'Routine Maintenance')){
            MaintenanceRequestHelper.updateWorkOrders(caseList);
        }    
    }
}

MaintenanceHelper Test class:
@isTest
private class MaintenanceRequestHelperTest {
	
    @isTest
    static void test_Method_one(){
        
        List<case> caseList = new List<case>();
        List<case> secondList = new List<case>();
        
        Account acc = new Account();
        acc.Name = 'Test';
        insert acc;
        
        Contact con = new Contact();
        con.FirstName = 'test';
        con.LastName = 'last';
        con.AccountId = acc.Id;
        con.Email = 'test@abc.com';
        insert con;
        
        Vehicle__c vehicle = new Vehicle__c();
        vehicle.Name = 'Ford Figo';
        insert vehicle;
        
        Product2 product = new Product2();
        product.Name = 'test';
        product.Maintenance_Cycle__c = 2;
        product.IsActive = true;
        product.Replacement_Part__c = true;
        insert product;
        
        for(Integer i = 0; i<1000; i++){
            Case maintenanceNew             = new Case();
           // maintenanceNew.Subject          = 'Other';
            maintenanceNew.Vehicle__c       = vehicle.Id;
            maintenanceNew.Product__c       = product.Id;
            maintenanceNew.ContactId        = con.Id;
            maintenanceNew.AccountId        = acc.Id;
            maintenanceNew.Type             = 'Other';
            maintenanceNew.Status           = 'New';
            maintenanceNew.Equipment__c     = product.Id;
            maintenanceNew.Date_Reported__c = Date.today();
            maintenanceNew.Date_Due__c      = Date.today();

            caseList.add(maintenanceNew); 
        }
        if(caseList.size()>0){
       		 insert caseList;
            
        }
        
        for(case cas : caseList){
            cas.Type = 'Repair';
            cas.status = 'Closed';
            secondList.add(cas);
        }
        test.startTest();
        update secondList;
        test.stopTest();
    }
}

Thanks in advance. :)
@isTest
public class MaintenanceRequesTest {
    @isTest
    static void testMaintenanceRequest(){
        
        List<case> caseList1 = new List<case>();
        List<case> caseList2 = new List<case>();
        
        for(Integer i=0;i<200;i++){
            Case c = new Case();
            c.Status = 'Closed';
            c.Type = 'Repair';
            c.Vehicle__c = c.Id;
            caseList1.add(c);
        }
        for(Integer j=0;j<200;j++){
            Case c = new Case();
            c.Status = 'Closed';
            c.Type = 'Routine Maintenance';
            c.Vehicle__c = c.Id;
            caseList2.add(c);
        }
        caseList1.addAll(caseList2);
        if(caseList1.size()>0){
        	insert caseList1;    
        }
        
    }
}
This is my test class for Maintenance Request but I am unable to increase my code coverage. Please help me in clearing this challenge.

Thanks in advance
 
Here is my email manager class
public class EmailManager {
    
    public static void sendMail(String Address,string subject, string body)
    {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        string [] toaddress = new string[]{address};
            
        email.setToAddresses(toaddress);
            
            //Avoid to hit the max number of emails
        //email.saveAsActivity = false;
        //email.setTargetObjectId(userId);
        
        email.setSubject(subject);
        email.setPlainTextBody(body);
        
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { email } );
    }
}

If I uncomment 'email.saveAsActivity = false' then also its working as expected then why do we use it? Thanks in advance.
Here is my email manager class
public class EmailManager {
    
    public static void sendMail(String Address,string subject, string body)
    {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        string [] toaddress = new string[]{address};
            
        email.setToAddresses(toaddress);
            
            //Avoid to hit the max number of emails
        //email.saveAsActivity = false;
        //email.setTargetObjectId(userId);
        
        email.setSubject(subject);
        email.setPlainTextBody(body);
        
        Messaging.sendEmail( new Messaging.SingleEmailMessage[] { email } );
    }
}

If I uncomment 'email.saveAsActivity = false' then also its working as expected then why do we use it? Thanks in advance.
Give your users a customized view of their accounts by creating a custom account record page.
  • The new record page must use the 'Header and Two Columns' template, be called 'New Account Page', and be assigned to the Account object.
  • The page must have the Highlights Panel and Twitter components, and a Tabs component with these tabs containing these components:
  1. Activity Tab contains the Activities Component
  2. Collaborate Tab contains the Feed Component
  3. Related Tab contains the Related Lists Component
  4. Details Tab contains the Record Detail Component
  • The page must be activated.
So I made the record page as required which looks as follows :
record page

but i m getting following error
Challenge Not yet complete... here's what's wrong: 
Lightning Page named 'New Account Page' does not appear to have the correct components on it.
please guide me
Thanx
I keep getting the "Challenge Not yet Complete......... Here's whats wrong"
Lightning page named 'New Account Page' does not appear to have the correct components on it.

The new record page must use the 'Header and Two Columns' template, be called 'New Account Page', and be assigned to the Account object. (Check this is done)
The page must have the Highlights Panel and Twitter components, and a Tabs component with these tabs containing these components: (Check this is done)
Activity Tab contains the Activities Component - Complete
Collaborate Tab contains the Feed Component - Complete
Related Tab contains the Related Lists Component - Complete
Details Tab contains the Record Detail Component - Compelte

Here is a screen shot, I believe I have all the items I am supposed to as well as what goes inside the components.
User-added image