• Srishti Gupta 8
  • NEWBIE
  • 5 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies

I need to put below validation in description field -
Allowed characters should be - a-z A-Z 0-9 Space and Special Characters are & ( ) - . and the description field  must start with a-z A-Z 

can anyone help me with regrex expression for this validation?

I need to put below validation in description field -
Allowed characters should be - a-z A-Z 0-9 Space and Special Characters are & ( ) - . and the description field  must start with a-z A-Z 

can anyone help me with regrex expression for this validation?

@isTest
public class MaintenanceRequestTest {
	@isTest
    static void testMaintenanceRequest(){
        
        List<Case> caseList = new List<Case>();

        Product2 prod = new Product2();
        prod.Cost__c = 50;
        prod.Name = 'Ball Valve 10 cm';
        prod.Lifespan_Months__c = 12;
        prod.Maintenance_Cycle__c = 365;
        prod.Current_Inventory__c = 50;
        prod.Replacement_Part__c = true;
        prod.Warehouse_SKU__c = '100009';
        insert prod;
        System.assertEquals(1, [SELECT count() FROM Product2 WHERE Name = 'Ball Valve 10 cm']);
            
         for(Integer i=1;i<=200;i++) {
            Case caseNew = new Case();
            caseNew.Subject = 'Maintenance';
            caseNew.Type = 'Other';
            caseNew.Status = 'New';
            caseNew.Equipment__c = caseNew.Id;
            caseList.add(caseNew);   
        }
        
        Test.startTest();
        
        insert caseList;
        System.assertEquals(200, [SELECT count() FROM Case WHERE Type = 'Other']);
        
        for(Case a : caseList){
            a.Type = 'Repair';
            a.Status = 'Closed';
        }
		update caseList;
        System.assertEquals(200, [SELECT count() FROM Case WHERE Type = 'Repair']);
        
        Test.stopTest();
        
    }
}




public class MaintenanceRequestHelper {
    
    public static void updateWorkOrders(Map<Id, Case> applicableCases){

	    Map<Id, Integer> mapProduct = new Map<Id, Integer>(); 
   		List<Case> newCases = new List<Case>();
        
        List<Product2> listProduct = [select Id, Maintenance_Cycle__c from Product2];       							
		for (Product2 p : listProduct) {
            if (p != null) {
                if(p.Maintenance_Cycle__c != null){
                    mapProduct.put(p.Id, Integer.valueOf(p.Maintenance_Cycle__c));
                }               
            }
        }

        for(Case a: applicableCases.values()){
            Case newCase = new Case();
            newCase.Vehicle__c = a.Vehicle__c;
            newCase.Equipment__c = a.Equipment__c;
            newCase.Type = 'Routine Maintenance';
            newCase.Subject = String.isBlank(a.Subject) ? 'Routine Maintenance Request' : a.Subject;
            newCase.Date_Reported__c = Date.today();
            newCase.Status = 'New';
            newCase.Product__c = a.Product__c;
            newCase.AccountId = a.AccountId;
            newCase.ContactId = a.ContactId;
            newCase.AssetId = a.AssetId;
            newCase.Origin = a.Origin;
            newCase.Reason = a.Reason;
            newCase.Date_Due__c =  (mapProduct.get(a.Id) != null) ? (Date.today().addDays(Integer.valueOf(mapProduct.get(a.Id)))) : (Date.today());
            newCases.add(newCase);
        }
        if(newCases.size() > 0){
            insert newCases;
        }
		        
        
    }        
    
}




trigger MaintenanceRequest on Case (before update, after update) {
    // call MaintenanceRequestHelper.updateWorkOrders  
    // 
    Map<Id,Case> applicableCases = new Map<Id,Case>();
    
    if(Trigger.isUpdate  && Trigger.isAfter){
        for(Case oCase: Trigger.new){
            if (oCase.IsClosed && (oCase.Type.equals('Repair') || oCase.Type.equals('Routine Maintenance'))){
                applicableCases.put(oCase.Id, oCase);
            }
        }
        if(!applicableCases.values().isEmpty()){
        	MaintenanceRequestHelper.updateWorkOrders(applicableCases);    
        }        
    } 
}

I got 100% code covergae. but i couldn't clear this challenge. the following is the error im getting when i check the challenge.
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: FIELD_INTEGRITY_EXCEPTION, Case: id value of incorrect type: 01t7F000003BjDmQAK: [Equipment__c].   

Can anyone please help me to fix this issue?
Performing the first Challenge of this Superbadge for APEX, I am receiving the below error. But it is not true because the Maintenance Request does indeed have all of the attributes cited when I try via the GUI and via a Test Class. Can someone please tell me what is wrong?

Challenge Not yet complete... here's what's wrong:
Inserting a new Maintenance Request of type 'Routine Maintenance' and then closing it did not create of a new Maintenance Request based upon the original record correctly. The challenge is expecting to find the closed Maintenance Request plus an 'New' Maintenance Request of type 'Routine Maintenance' with the same Vehicle as the closed one.

(Also, the challenge didn't specifically mention that the Case and Product2 objects should be relabeled)