• Sudhir Kumar 19
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 2
    Questions
  • 8
    Replies
Apex Superbadge challenge 4 error

Apex Superbadge Challenge 4 Error

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.

When I debug, I see this strange SOQL:

11:07:41.744 (4865812076)|SOQL_EXECUTE_BEGIN|[35]|Aggregations:0|SELECT COUNT() FROM Case WHERE subject LIKE '%AMC Spirit%'
11:07:41.744 (4868187164)|SOQL_EXECUTE_END|[35]|Rows:201
11:07:41.744 (4868199387)|HEAP_ALLOCATE|[35]|Bytes:4
11:07:41.744 (4868273203)|EXCEPTION_THROWN|[35]|System.AssertException: Assertion Failed: Expected: 402, Actual: 201
11:07:41.744 (4868404432)|HEAP_ALLOCATE|[35]|Bytes:48
11:07:41.744 (4868515907)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 402, Actual: 201

Debug log

I see many people passing this challenge. Kindly help!
LeX Superbadge Challenge 4 error

LeX superbadge challenge #4:

I followed this post https://developer.salesforce.com/forums/?id=906F0000000kEDkIAM however it doesn't seem working with me. Has anything changed lately in the requirement validation process. Appreciate your help!
Apex Superbadge challenge 4 error

Apex Superbadge Challenge 4 Error

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.

When I debug, I see this strange SOQL:

11:07:41.744 (4865812076)|SOQL_EXECUTE_BEGIN|[35]|Aggregations:0|SELECT COUNT() FROM Case WHERE subject LIKE '%AMC Spirit%'
11:07:41.744 (4868187164)|SOQL_EXECUTE_END|[35]|Rows:201
11:07:41.744 (4868199387)|HEAP_ALLOCATE|[35]|Bytes:4
11:07:41.744 (4868273203)|EXCEPTION_THROWN|[35]|System.AssertException: Assertion Failed: Expected: 402, Actual: 201
11:07:41.744 (4868404432)|HEAP_ALLOCATE|[35]|Bytes:48
11:07:41.744 (4868515907)|FATAL_ERROR|System.AssertException: Assertion Failed: Expected: 402, Actual: 201

Debug log

I see many people passing this challenge. Kindly help!
LeX Superbadge Challenge 4 error

LeX superbadge challenge #4:

I followed this post https://developer.salesforce.com/forums/?id=906F0000000kEDkIAM however it doesn't seem working with me. Has anything changed lately in the requirement validation process. Appreciate your help!
I've finally completed step 4. Test automation logic. 

It took me long, because of incorrect requirement in spec. 
The requirement is: 
When an existing maintenance request of type Repair or Routine Maintenance is Closed, you create a new maintenance request for a future routine checkup. [...] The Subject should not be null and [...]

Unfortunatelly test checks something completelly different. See below line from error log:  
Execute Anonymous: System.assertEquals(402, [select count() from Case where subject like '%AMC Spirit%']);
Moreover, the error information from within Trailhead page suggests, that this is a problem with bulk processing. 

<joke> So, if you want to finish step 4 of those badge you need to set the subject to AMC Spirit in case created by your trigger </joke>


 
Hi guys, I'm almost finished with the test to get tge Apex Specialist SuperBadge, I attempt to validate the "Test automation logic" but I can't really see what is my error or why is not passing. This is the message I get:

"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."

and here is my code:

Trigger:
 
trigger MaintenanceRequest on Case (after update) {
	
	//List<Case> casesToEvaluate = new List<Case>();
	Map<Id, Case> casesToEvaluate = new Map<Id, Case>();

	if(Trigger.isAfter && Trigger.isUpdate){
		for(Case maintenance:Trigger.new){
			if((maintenance.Type.contains('Repair') || maintenance.Type.contains('Routine Maintenance')) && maintenance.Status == 'Closed'){
				casesToEvaluate.put(maintenance.Id,maintenance);
			}
		}		
	}
	MaintenanceRequestHelper.updateWorkOrders(casesToEvaluate);
}

Here's the class:
 
public class MaintenanceRequestHelper {

	public static void updateWorkOrders(Map<Id, Case>  cases){
		List<Case> maintenance_routineList = new List<Case>();

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

		System.debug('### product: '+mapProduct);

		for(Case maintenance:cases.values()){
			Case maintenanceNew = new Case();
			maintenanceNew.Subject = 'Routine Maintenance';
			System.debug('### Second: '+mapProduct.get(maintenance.Equipment__c));
			if (mapProduct.get(maintenance.Equipment__c) != null) {
				
				 maintenanceNew.Date_Due__c = Date.today().addDays(Integer.valueOf(mapProduct.get(maintenance.Equipment__c)));
				     
            }
			maintenanceNew.Vehicle__c = maintenance.Vehicle__c;
			maintenanceNew.Product__c = maintenance.Product__c;
			maintenanceNew.ContactId  = maintenance.ContactId;
			maintenanceNew.AccountId  = maintenance.AccountId;
			maintenanceNew.AssetId    = maintenance.AssetId;
			maintenanceNew.Type 	  = 'Routine Maintenance';
			maintenanceNew.Status 	  = 'New';
			maintenanceNew.Equipment__c = maintenance.Equipment__c;
			maintenanceNew.Date_Reported__c = Date.today();


			maintenance_routineList.add(maintenanceNew);
		}

		insert maintenance_routineList;
	}
}

And my testmethod:
 
@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 contact = new Contact();
		contact.FirstName = 'test';
		contact.LastName = 'last';
		contact.Email = 'test@test.com';
		contact.AccountId = acc.Id;
		insert contact;

		Vehicle__c vehicle = new Vehicle__c();
		vehicle.Name = 'car';
		insert vehicle;

		Product2 product = new Product2();
		product.Name = 'test';
		product.isActive = true;
		product.Maintenance_Cycle__c = 2;
		product.Replacement_Part__c = true;
		insert product;

		for(Integer i=1;i<=1000;i++){
			Case maintenanceNew             = new Case();
			maintenanceNew.Subject          = 'Other';
			maintenanceNew.Vehicle__c       = vehicle.Id;
			maintenanceNew.Product__c       = product.Id;
			maintenanceNew.ContactId        = contact.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);	
		}

		insert caseList;
		System.assertEquals(1000,caseList.size());

		for(Case cas:caseList){
			//update information
			cas.Type = 'Repair';
			cas.Status = 'Closed';
			secondList.add(cas);
		}

		update secondList;
		List<Case> createdCases = [Select Id from Case where Type = 'Routine Maintenance'];
		System.assertEquals(1000,createdCases.size());
	
	}	
}

Can someone help me to undestand what I'm missing?.  Thanks in advance.

Edgar,
 
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)
Has anyone completed this trail? I am stomped on challenge number 3, regarding created the process for fulfillment. Any pointers or guidance would be appreciated.
 
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
Just 2 more days to go for the Bangalore edition of the Salesforce summer of hacks. We are working hard to bring you an exceptional platform to get your creative juices flowing.

While getting ready for the Hackathon, please go through Raja's post below to get your computer ready for the Hackathon. For those who are new to Salesforce1, check out the Salesforce1 guide: http://www.salesforce.com/us/developer/docs/salesforce1/salesforce1_guide.pdf. 

Please post any queries around the Hackathon here. We have experts monitoring this topic. 
Hi guys, I'm almost finished with the test to get tge Apex Specialist SuperBadge, I attempt to validate the "Test automation logic" but I can't really see what is my error or why is not passing. This is the message I get:

"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."

and here is my code:

Trigger:
 
trigger MaintenanceRequest on Case (after update) {
	
	//List<Case> casesToEvaluate = new List<Case>();
	Map<Id, Case> casesToEvaluate = new Map<Id, Case>();

	if(Trigger.isAfter && Trigger.isUpdate){
		for(Case maintenance:Trigger.new){
			if((maintenance.Type.contains('Repair') || maintenance.Type.contains('Routine Maintenance')) && maintenance.Status == 'Closed'){
				casesToEvaluate.put(maintenance.Id,maintenance);
			}
		}		
	}
	MaintenanceRequestHelper.updateWorkOrders(casesToEvaluate);
}

Here's the class:
 
public class MaintenanceRequestHelper {

	public static void updateWorkOrders(Map<Id, Case>  cases){
		List<Case> maintenance_routineList = new List<Case>();

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

		System.debug('### product: '+mapProduct);

		for(Case maintenance:cases.values()){
			Case maintenanceNew = new Case();
			maintenanceNew.Subject = 'Routine Maintenance';
			System.debug('### Second: '+mapProduct.get(maintenance.Equipment__c));
			if (mapProduct.get(maintenance.Equipment__c) != null) {
				
				 maintenanceNew.Date_Due__c = Date.today().addDays(Integer.valueOf(mapProduct.get(maintenance.Equipment__c)));
				     
            }
			maintenanceNew.Vehicle__c = maintenance.Vehicle__c;
			maintenanceNew.Product__c = maintenance.Product__c;
			maintenanceNew.ContactId  = maintenance.ContactId;
			maintenanceNew.AccountId  = maintenance.AccountId;
			maintenanceNew.AssetId    = maintenance.AssetId;
			maintenanceNew.Type 	  = 'Routine Maintenance';
			maintenanceNew.Status 	  = 'New';
			maintenanceNew.Equipment__c = maintenance.Equipment__c;
			maintenanceNew.Date_Reported__c = Date.today();


			maintenance_routineList.add(maintenanceNew);
		}

		insert maintenance_routineList;
	}
}

And my testmethod:
 
@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 contact = new Contact();
		contact.FirstName = 'test';
		contact.LastName = 'last';
		contact.Email = 'test@test.com';
		contact.AccountId = acc.Id;
		insert contact;

		Vehicle__c vehicle = new Vehicle__c();
		vehicle.Name = 'car';
		insert vehicle;

		Product2 product = new Product2();
		product.Name = 'test';
		product.isActive = true;
		product.Maintenance_Cycle__c = 2;
		product.Replacement_Part__c = true;
		insert product;

		for(Integer i=1;i<=1000;i++){
			Case maintenanceNew             = new Case();
			maintenanceNew.Subject          = 'Other';
			maintenanceNew.Vehicle__c       = vehicle.Id;
			maintenanceNew.Product__c       = product.Id;
			maintenanceNew.ContactId        = contact.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);	
		}

		insert caseList;
		System.assertEquals(1000,caseList.size());

		for(Case cas:caseList){
			//update information
			cas.Type = 'Repair';
			cas.Status = 'Closed';
			secondList.add(cas);
		}

		update secondList;
		List<Case> createdCases = [Select Id from Case where Type = 'Routine Maintenance'];
		System.assertEquals(1000,createdCases.size());
	
	}	
}

Can someone help me to undestand what I'm missing?.  Thanks in advance.

Edgar,