• Mark Z Dean
  • NEWBIE
  • 25 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 18
    Replies
I have setup a connected app and I am using Postman to query some data but I keep getting the following message:
 
[
    {
        "message": "Session expired or invalid",
        "errorCode": "INVALID_SESSION_ID"
    }
]
I can successfully get the session id in Postman and using it in the request but have tried other settings in Postman and it still doesn't work. Need some help please.
 
I have completed the challenge below but I am not able to show my component on a page:

https://trailhead.salesforce.com/content/learn/modules/platform-developer-i-certification-maintenance-winter-19/work-with-the-lightning-map-component-and-apex-inherited-sharing

I keep getting the error below:
User-added image
Folks - I really need some help. I have run out of brain power solving this for 2 days and can't figure out what's happening. Test class passes with 100% coverage but challenge fails with message:
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.

Here is my main helper class which is called from the trigger:
public class MaintenanceRequestHelper {
    
    public static void processRequest(Map<Id, Case> OldMap, Map<Id, Case> NewMap){
        
       // Id PartsListId;
        Map<Id, Case> MinMaintDaysMap = NewMap;
        Map<Id, Integer> DaystoAdd;
        List<Case> ListofCases = new List<Case>();

   		DaystoAdd = minMaintenanceDays(NewMap);


		for(Id o : NewMap.keySet()){
			if((NewMap.get(o).Type == 'Repair' || NewMap.get(o).Type == 'Routine Maintenance') && NewMap.get(o).status == 'Closed'){
				for(Id i : DaystoAdd.keyset()){		
					if(NewMap.get(o).id == i){
				Case newCase = new Case(Vehicle__c = NewMap.get(o).Vehicle__c,
										Subject = NewMap.get(o).subject,
										Equipment__c = NewMap.get(o).Equipment__c,
										Date_Reported__c = 	System.today(),
										Type = 'Routine Maintenance',
										Status = 'New',
										Origin = 'Web',
										Date_Due__c =System.today() + DaystoAdd.get(i),
										Account = NewMap.get(o).account,
										ContactId = NewMap.get(o).contactId);
				ListofCases.add(newCase);

											}		
									}
							}	
					}
	insert ListofCases;
}        
    


    public static Map<Id, Integer> minMaintenanceDays(Map<Id, Case> Parts){

    	List<Decimal> ListofDays 	= new List<Decimal>();
    	Map<Id, Integer> SortedMap 	= new Map<Id, Integer>();

    	Map<Id, Case> PartsList = new Map<Id, Case>([select id, 
    												(select id, Maintenance_Request__c, Equipment__r.Maintenance_Cycle__c  
    												from Work_Parts__r)
													from Case 
													where id IN :Parts.keyset()]);

		for(Case c  : PartsList.values())			
			for(Work_Part__c wp : c.Work_Parts__r){
				if(c.id == wp.Maintenance_Request__c){				
				//System.debug(wp);
				ListofDays.add(wp.Equipment__r.Maintenance_Cycle__c);
				ListofDays.sort();
				SortedMap.put(c.id, (Integer)ListofDays.get(0));
				}
					}


	return SortedMap;				
    }

}

Please forgive the bad naming conventions and help with the message. Done Googling, StackExchange etc. but for the life of me can't figure out what's wrong. Also Debug log shows the message that assertion fails when challenge is run. Message is "Assestion Failed, Expected: 402, Actual: 201".
 
Folks, 
I am doing step 2 in Apex Specialist superbadge. I passed the challenge but when I run the class from Anonymous Apex, it works fine and it creates the records. When I re-run it, instead of just updating existing records, it creates tens of duplicates. Please help as I am losing sleep over this and its already past midnight :)
public with sharing class WarehouseCalloutService {
	
	 private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
    
    // complete this method to make the callout (using @future) to the
    // REST endpoint and update equipment on hand.
    @future(callout=true)
    public static void runWarehouseEquipmentSync(){
        
    	List<Object> m;
    	List<Product2> ListtoUpdate = new List<Product2>();

    	List<Product2> prod = [select id, Name, Maintenance_Cycle__c, Lifespan_Months__c,	Current_Inventory__c, 
    								Replacement_Part__c, Warehouse_SKU__c, Cost__c
    							from Product2
								where isActive = true
								and Warehouse_SKU__c != null];
								
		System.debug('Size of query is ' + prod.size());
		Http http = new Http();
    	HttpRequest request = new HttpRequest();
    	request.setEndpoint(WAREHOUSE_URL);
    	request.setMethod('GET');
    	HttpResponse response = Http.send(request);

    	if(response.getStatusCode() == 200)
    		m = (List<Object>) JSON.deserializeUntyped(response.getBody());
    	
		for(Object i : m){
    		Map<String, Object> l 	=  (Map<String, Object>) i;
    		String ExID 			= (String) l.get('_id');
    		Boolean Replacement 	= (Boolean) l.get('replacement');
    		Integer Quantity 		= (Integer) l.get('quantity');
    		String NameofProd		= (String) l.get('name');
    		Decimal MaintPeriod 	= (Decimal) l.get('maintenanceperiod');
    		Integer Lifespan		= (Integer) l.get('lifespan'); 
    		Integer Cost 			= (Integer) l.get('cost');
    		String Sku 				= (String) l.get('sku');
    		System.debug(ExID);			
				
    		for(Product2 p : prod){
    			if(Sku == p.Warehouse_SKU__c){
    				p.Lifespan_Months__c 		= Lifespan;
    				p.Current_Inventory__c 		= Quantity;
    				p.Cost__c					= Cost;
    				p.Maintenance_Cycle__c 		= MaintPeriod;
    			//	p.Warehouse_SKU__c			= Sku;
    				p.Replacement_Part__c       = Replacement;
    				System.debug(prod);
    				ListtoUpdate.add(p);  				 
    						}
    			else {

    				Product2 newPr = new Product2(Name=NameofProd, Warehouse_SKU__c= Sku, Lifespan_Months__c=Lifespan,
    											  Current_Inventory__c = Quantity, Cost__c = Cost,
    											  Maintenance_Cycle__c = MaintPeriod, Replacement_Part__c=Replacement, isActive = TRUE);
    				ListtoUpdate.add(newPr);
    			}
    				
					}
    			}
    		upsert ListtoUpdate;
    		}

   }

This is how the JSON looks like:
[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"},{"_id":"55d66226726b611100aaf742","replacement":true,"quantity":183,"name":"Cooling Fan","maintenanceperiod":0,"lifespan":0,"cost":300,"sku":"100004"},{"_id":"55d66226726b611100aaf743","replacement":true,"quantity":143,"name":"Fuse 20A","maintenanceperiod":0,"lifespan":0,"cost":22,"sku":"100005"},{"_id":"55d66226726b611100aaf744","replacement":false,"quantity":5,"name":"Generator 2000 kw","maintenanceperiod":365,"lifespan":120,"cost":6000,"sku":"100006"},{"_id":"55d66226726b611100aaf745","replacement":true,"quantity":142,"name":"Fuse 25A","maintenanceperiod":0,"lifespan":0,"cost":28,"sku":"100007"},{"_id":"55d66226726b611100aaf746","replacement":true,"quantity":122,"name":"Fuse 13A","maintenanceperiod":0,"lifespan":0,"cost":10,"sku":"100008"},{"_id":"55d66226726b611100aaf747","replacement":true,"quantity":90,"name":"Ball Valve 10 cm","maintenanceperiod":0,"lifespan":0,"cost":50,"sku":"100009"},{"_id":"55d66226726b611100aaf748","replacement":false,"quantity":2,"name":"Converter","maintenanceperiod":180,"lifespan":120,"cost":3000,"sku":"100010"},{"_id":"55d66226726b611100aaf749","replacement":true,"quantity":75,"name":"Ball Valve 8 cm","maintenanceperiod":0,"lifespan":0,"cost":42,"sku":"100011"},{"_id":"55d66226726b611100aaf74a","replacement":true,"quantity":100,"name":"Breaker 25A","maintenanceperiod":0,"lifespan":0,"cost":30,"sku":"100012"},{"_id":"55d66226726b611100aaf74b","replacement":true,"quantity":150,"name":"Switch","maintenanceperiod":0,"lifespan":0,"cost":100,"sku":"100013"},{"_id":"55d66226726b611100aaf74c","replacement":true,"quantity":200,"name":"Ball Valve 5 cm","maintenanceperiod":0,"lifespan":0,"cost":30,"sku":"100014"},{"_id":"55d66226726b611100aaf74d","replacement":false,"quantity":8,"name":"UPS 3000 VA","maintenanceperiod":180,"lifespan":60,"cost":1600,"sku":"100015"},{"_id":"55d66226726b611100aaf74e","replacement":false,"quantity":10,"name":"UPS 1000 VA","maintenanceperiod":180,"lifespan":48,"cost":1000,"sku":"100016"},{"_id":"55d66226726b611100aaf74f","replacement":true,"quantity":180,"name":"Breaker 8A","maintenanceperiod":0,"lifespan":0,"cost":10,"sku":"100017"},{"_id":"55d66226726b611100aaf750","replacement":false,"quantity":2,"name":"Cooling Tower","maintenanceperiod":365,"lifespan":120,"cost":10000,"sku":"100018"},{"_id":"55d66226726b611100aaf751","replacement":true,"quantity":165,"name":"Motor","maintenanceperiod":0,"lifespan":0,"cost":150,"sku":"100019"},{"_id":"55d66226726b611100aaf752","replacement":true,"quantity":210,"name":"Breaker 13A","maintenanceperiod":0,"lifespan":0,"cost":20,"sku":"100020"},{"_id":"55d66226726b611100aaf753","replacement":true,"quantity":100,"name":"Radiator Pump","maintenanceperiod":0,"lifespan":0,"cost":500,"sku":"100021"},{"_id":"55d66226726b611100aaf754","replacement":true,"quantity":129,"name":"Breaker 20A","maintenanceperiod":0,"lifespan":0,"cost":25,"sku":"100022"},{"_id":"55d66226726b611100aaf73f","replacement":false,"quantity":10,"name":"UPS 2000 VA","maintenanceperiod":180,"lifespan":60,"cost":1350,"sku":"100001"},{"_id":"55d66226726b611100aaf740","replacement":true,"quantity":194,"name":"Fuse 8A","maintenanceperiod":0,"lifespan":0,"cost":5,"sku":"100002"}]

Many thanks...


 
I have been doing this Trailhead challenge related to SOAP calls. My webservice mock class has the following code:
@isTest
public class ParkServiceMock implements WebServiceMock {
   public void doInvoke(
           Object stub,
           Object request,
           Map<String, Object> response,
           String endpoint,
           String soapAction,
           String requestName,
           String responseNS,
           String responseName,
           String responseType) {
        //  String byCountry;

        ParkService.byCountryResponse   l = new ParkService.byCountryResponse (); 
        l.return_x  = new List<String>{'Hamburg Wadden Sea National Park','Hainich National Park', 'Bavarian Forest National Park'}; 
        response.put('response_x', l);

        // Create response element from the autogenerated class.
        // Populate response element.
        // Add response element to the response parameter, as follows:
        //response.put('response_x', responseElement); 
   }
}
The class generated from the WSDL is below:
//Generated by wsdl2apex

public class ParkService {
    public class byCountryResponse {
        public String[] return_x;
        private String[] return_x_type_info = new String[]{'return','http://parks.services/',null,'0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
    public class byCountry {
        public String arg0;
        private String[] arg0_type_info = new String[]{'arg0','http://parks.services/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://parks.services/','false','false'};
        private String[] field_order_type_info = new String[]{'arg0'};
    }
    public class ParksImplPort {
        public String endpoint_x = 'https://th-apex-soap-service.herokuapp.com/service/parks';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://parks.services/', 'ParkService'};
        public String[] byCountry(String arg0) {
            ParkService.byCountry request_x = new ParkService.byCountry();
            request_x.arg0 = arg0;
            ParkService.byCountryResponse response_x;
            Map<String, ParkService.byCountryResponse> response_map_x = new Map<String, ParkService.byCountryResponse>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://parks.services/',
              'byCountry',
              'http://parks.services/',
              'byCountryResponse',
              'ParkService.byCountryResponse'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
        }
    }
}

As you may notice, the byCountryResponse is an inner class but in the earlier code snippet, I can call an inner class like:
ParkService.byCountryResponse l = new ParkService.byCountryResponse();
This is confusing because byCountryReponse also has brackets next to it which is used for a method. How does it allow this for an inner class in Apex?




 
I did this Trailhead challenge successfully but had a question. When I used List and casted the collection of maps into it, it kept giving me run time exception. 
public with sharing class AnimalLocator {
	public static  String  getAnimalById(Integer id) {
		String s;
		Http http = new Http();
		
		HttpRequest request = new HttpRequest();

		request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + id);
		request.setMethod('GET');
		HttpResponse response = http.send(request);
		if(response.getStatusCode() == 200){

			Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
			List<Object> animals = (List<Object>) results.get('animal');
			//System.debug('Animal is ' + animal.get(0));
			s = (String) animals.get(id);									}
	return s;
	}
}

But when I converted it to use a map, it worked fine. I need some help to understand what could be the cause of this. Cheers!
I ran simple query below and it gave me results:
select Id, name, userrole.name  from user
The child relationship name is called 'Users' on the User object so I was initially the query below but it kept erroring out:
select Id, name, users__r.name  from user
I thought every call to a parent must have '__r' appended but not in this case plus it doesn't even use the relationship name i.e. users. Can someone explain why the first query worked and the second one didn't...Many thanks...





 
I am trying to write a trigger on Case object that will detect specific confidential terms in the Description field and create a new CHILD case with the the detected terms in the Description field of the child record. I wrote the code below but having difficulty figuring out how to get the description of the new child record updated (line 34) with the confidential terms from the parent record. 
trigger ConfidentialTerms on Case (after insert, before insert) {
	//insert all terms in list
	List<String> terms;
    Set<Case> NewChildCase = new Set<Case>();
    List<Case> NewCases;
	String t;
    List<String> LString = new List<String>();
    
    terms.add('Credit Card');
    terms.add('Passport');
    terms.add('License');
    
    
	//iterate through terms list and check each record's description
        for(Case c : trigger.new){
          	 for(String s : terms){
        		    if(c.description.Contains(s) && c.Description != null){
          		      t =+ s;
                      NewChildCase.add(c);  

        			    }				
             
        		}
         LString.add(t);      
   		}
    
    //create child record
    	for(Case cc : NewChildCase){
	
            Case childCase = new Case();
            childCase.parentid = cc.id;
            childCase.Subject = 'High Priority Case';
            
            childCase.Description = '';
            NewCases.add(childCase); 
        	}  
    
    insert NewCases;
}
I don't need the code but just hints on how this can be done. Much appreciated...
I am trying to do an exercise from a Pluralsight course. Requirement is to get the lowest competitor price and populate the name of the competitor and the price:
User-added image

My code:
trigger CompetitorPrice5 on Opportunity (before insert, before update) {

    Map<id, Opportunity> BestPriceM = new Map<id, Opportunity>();

    //select all records into a map
    Map<id, Opportunity> m = new Map<id, Opportunity>([select id, competitor1__c, competitor_2__c, 
                                                       competitor_3__c, Competitor_Price_1__c,
                                                       Competitor_Price_2__c, Competitor_Price_3__c,
                                                       Best_Competitor_Price__c,Best_Competitor__c 
                                                       from opportunity 
                                                       where id in :trigger.Newmap.keySet()]);

    //process the record one by one and assign to the new list
    Decimal LowestPrice;    
    Decimal CurrentPrice;
    String CompName;

    for(Id i : m.keySet()){
     List<Decimal> AllPrices = new List<Decimal>();
	// System.debug('Values of AllPrices ' + AllPrices);
     List<String> AllComps = new List<String>();

     AllPrices.add(m.get(i).Competitor_Price_1__c);
	 AllPrices.add(m.get(i).Competitor_Price_2__c);
     AllPrices.add(m.get(i).Competitor_Price_3__c);

     AllComps.add(m.get(i).Competitor1__c);
     AllComps.add(m.get(i).Competitor_2__c);
     AllComps.add(m.get(i).Competitor_3__c);
	
    //compare each competitor's price with the LowestPrice and update if competitor's price is less
    for(Integer l; l < AllPrices.size(); l++)
        {
           CurrentPrice = AllPrices.get(l);
	            if(CurrentPrice < LowestPrice)
		            {
		                LowestPrice = CurrentPrice;
		                CompName = AllComps.get(l);
		            }

        }
    //update Best Competitor and Best Competitor Price fields    
    m.get(i).Best_Competitor_Price__c = LowestPrice;
    m.get(i).Best_Competitor__c = CompName;
	}
}
The problem is I keep getting a null values in AllPrices and AllComps lists and the update doesn't happen. The code compiles fine though. Please help...
 
I have setup a connected app and I am using Postman to query some data but I keep getting the following message:
 
[
    {
        "message": "Session expired or invalid",
        "errorCode": "INVALID_SESSION_ID"
    }
]
I can successfully get the session id in Postman and using it in the request but have tried other settings in Postman and it still doesn't work. Need some help please.
 
I have completed the challenge below but I am not able to show my component on a page:

https://trailhead.salesforce.com/content/learn/modules/platform-developer-i-certification-maintenance-winter-19/work-with-the-lightning-map-component-and-apex-inherited-sharing

I keep getting the error below:
User-added image
Folks, 
I am doing step 2 in Apex Specialist superbadge. I passed the challenge but when I run the class from Anonymous Apex, it works fine and it creates the records. When I re-run it, instead of just updating existing records, it creates tens of duplicates. Please help as I am losing sleep over this and its already past midnight :)
public with sharing class WarehouseCalloutService {
	
	 private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';
    
    // complete this method to make the callout (using @future) to the
    // REST endpoint and update equipment on hand.
    @future(callout=true)
    public static void runWarehouseEquipmentSync(){
        
    	List<Object> m;
    	List<Product2> ListtoUpdate = new List<Product2>();

    	List<Product2> prod = [select id, Name, Maintenance_Cycle__c, Lifespan_Months__c,	Current_Inventory__c, 
    								Replacement_Part__c, Warehouse_SKU__c, Cost__c
    							from Product2
								where isActive = true
								and Warehouse_SKU__c != null];
								
		System.debug('Size of query is ' + prod.size());
		Http http = new Http();
    	HttpRequest request = new HttpRequest();
    	request.setEndpoint(WAREHOUSE_URL);
    	request.setMethod('GET');
    	HttpResponse response = Http.send(request);

    	if(response.getStatusCode() == 200)
    		m = (List<Object>) JSON.deserializeUntyped(response.getBody());
    	
		for(Object i : m){
    		Map<String, Object> l 	=  (Map<String, Object>) i;
    		String ExID 			= (String) l.get('_id');
    		Boolean Replacement 	= (Boolean) l.get('replacement');
    		Integer Quantity 		= (Integer) l.get('quantity');
    		String NameofProd		= (String) l.get('name');
    		Decimal MaintPeriod 	= (Decimal) l.get('maintenanceperiod');
    		Integer Lifespan		= (Integer) l.get('lifespan'); 
    		Integer Cost 			= (Integer) l.get('cost');
    		String Sku 				= (String) l.get('sku');
    		System.debug(ExID);			
				
    		for(Product2 p : prod){
    			if(Sku == p.Warehouse_SKU__c){
    				p.Lifespan_Months__c 		= Lifespan;
    				p.Current_Inventory__c 		= Quantity;
    				p.Cost__c					= Cost;
    				p.Maintenance_Cycle__c 		= MaintPeriod;
    			//	p.Warehouse_SKU__c			= Sku;
    				p.Replacement_Part__c       = Replacement;
    				System.debug(prod);
    				ListtoUpdate.add(p);  				 
    						}
    			else {

    				Product2 newPr = new Product2(Name=NameofProd, Warehouse_SKU__c= Sku, Lifespan_Months__c=Lifespan,
    											  Current_Inventory__c = Quantity, Cost__c = Cost,
    											  Maintenance_Cycle__c = MaintPeriod, Replacement_Part__c=Replacement, isActive = TRUE);
    				ListtoUpdate.add(newPr);
    			}
    				
					}
    			}
    		upsert ListtoUpdate;
    		}

   }

This is how the JSON looks like:
[{"_id":"55d66226726b611100aaf741","replacement":false,"quantity":5,"name":"Generator 1000 kW","maintenanceperiod":365,"lifespan":120,"cost":5000,"sku":"100003"},{"_id":"55d66226726b611100aaf742","replacement":true,"quantity":183,"name":"Cooling Fan","maintenanceperiod":0,"lifespan":0,"cost":300,"sku":"100004"},{"_id":"55d66226726b611100aaf743","replacement":true,"quantity":143,"name":"Fuse 20A","maintenanceperiod":0,"lifespan":0,"cost":22,"sku":"100005"},{"_id":"55d66226726b611100aaf744","replacement":false,"quantity":5,"name":"Generator 2000 kw","maintenanceperiod":365,"lifespan":120,"cost":6000,"sku":"100006"},{"_id":"55d66226726b611100aaf745","replacement":true,"quantity":142,"name":"Fuse 25A","maintenanceperiod":0,"lifespan":0,"cost":28,"sku":"100007"},{"_id":"55d66226726b611100aaf746","replacement":true,"quantity":122,"name":"Fuse 13A","maintenanceperiod":0,"lifespan":0,"cost":10,"sku":"100008"},{"_id":"55d66226726b611100aaf747","replacement":true,"quantity":90,"name":"Ball Valve 10 cm","maintenanceperiod":0,"lifespan":0,"cost":50,"sku":"100009"},{"_id":"55d66226726b611100aaf748","replacement":false,"quantity":2,"name":"Converter","maintenanceperiod":180,"lifespan":120,"cost":3000,"sku":"100010"},{"_id":"55d66226726b611100aaf749","replacement":true,"quantity":75,"name":"Ball Valve 8 cm","maintenanceperiod":0,"lifespan":0,"cost":42,"sku":"100011"},{"_id":"55d66226726b611100aaf74a","replacement":true,"quantity":100,"name":"Breaker 25A","maintenanceperiod":0,"lifespan":0,"cost":30,"sku":"100012"},{"_id":"55d66226726b611100aaf74b","replacement":true,"quantity":150,"name":"Switch","maintenanceperiod":0,"lifespan":0,"cost":100,"sku":"100013"},{"_id":"55d66226726b611100aaf74c","replacement":true,"quantity":200,"name":"Ball Valve 5 cm","maintenanceperiod":0,"lifespan":0,"cost":30,"sku":"100014"},{"_id":"55d66226726b611100aaf74d","replacement":false,"quantity":8,"name":"UPS 3000 VA","maintenanceperiod":180,"lifespan":60,"cost":1600,"sku":"100015"},{"_id":"55d66226726b611100aaf74e","replacement":false,"quantity":10,"name":"UPS 1000 VA","maintenanceperiod":180,"lifespan":48,"cost":1000,"sku":"100016"},{"_id":"55d66226726b611100aaf74f","replacement":true,"quantity":180,"name":"Breaker 8A","maintenanceperiod":0,"lifespan":0,"cost":10,"sku":"100017"},{"_id":"55d66226726b611100aaf750","replacement":false,"quantity":2,"name":"Cooling Tower","maintenanceperiod":365,"lifespan":120,"cost":10000,"sku":"100018"},{"_id":"55d66226726b611100aaf751","replacement":true,"quantity":165,"name":"Motor","maintenanceperiod":0,"lifespan":0,"cost":150,"sku":"100019"},{"_id":"55d66226726b611100aaf752","replacement":true,"quantity":210,"name":"Breaker 13A","maintenanceperiod":0,"lifespan":0,"cost":20,"sku":"100020"},{"_id":"55d66226726b611100aaf753","replacement":true,"quantity":100,"name":"Radiator Pump","maintenanceperiod":0,"lifespan":0,"cost":500,"sku":"100021"},{"_id":"55d66226726b611100aaf754","replacement":true,"quantity":129,"name":"Breaker 20A","maintenanceperiod":0,"lifespan":0,"cost":25,"sku":"100022"},{"_id":"55d66226726b611100aaf73f","replacement":false,"quantity":10,"name":"UPS 2000 VA","maintenanceperiod":180,"lifespan":60,"cost":1350,"sku":"100001"},{"_id":"55d66226726b611100aaf740","replacement":true,"quantity":194,"name":"Fuse 8A","maintenanceperiod":0,"lifespan":0,"cost":5,"sku":"100002"}]

Many thanks...


 
I did this Trailhead challenge successfully but had a question. When I used List and casted the collection of maps into it, it kept giving me run time exception. 
public with sharing class AnimalLocator {
	public static  String  getAnimalById(Integer id) {
		String s;
		Http http = new Http();
		
		HttpRequest request = new HttpRequest();

		request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals/' + id);
		request.setMethod('GET');
		HttpResponse response = http.send(request);
		if(response.getStatusCode() == 200){

			Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
			List<Object> animals = (List<Object>) results.get('animal');
			//System.debug('Animal is ' + animal.get(0));
			s = (String) animals.get(id);									}
	return s;
	}
}

But when I converted it to use a map, it worked fine. I need some help to understand what could be the cause of this. Cheers!
I ran simple query below and it gave me results:
select Id, name, userrole.name  from user
The child relationship name is called 'Users' on the User object so I was initially the query below but it kept erroring out:
select Id, name, users__r.name  from user
I thought every call to a parent must have '__r' appended but not in this case plus it doesn't even use the relationship name i.e. users. Can someone explain why the first query worked and the second one didn't...Many thanks...





 
I am trying to write a trigger on Case object that will detect specific confidential terms in the Description field and create a new CHILD case with the the detected terms in the Description field of the child record. I wrote the code below but having difficulty figuring out how to get the description of the new child record updated (line 34) with the confidential terms from the parent record. 
trigger ConfidentialTerms on Case (after insert, before insert) {
	//insert all terms in list
	List<String> terms;
    Set<Case> NewChildCase = new Set<Case>();
    List<Case> NewCases;
	String t;
    List<String> LString = new List<String>();
    
    terms.add('Credit Card');
    terms.add('Passport');
    terms.add('License');
    
    
	//iterate through terms list and check each record's description
        for(Case c : trigger.new){
          	 for(String s : terms){
        		    if(c.description.Contains(s) && c.Description != null){
          		      t =+ s;
                      NewChildCase.add(c);  

        			    }				
             
        		}
         LString.add(t);      
   		}
    
    //create child record
    	for(Case cc : NewChildCase){
	
            Case childCase = new Case();
            childCase.parentid = cc.id;
            childCase.Subject = 'High Priority Case';
            
            childCase.Description = '';
            NewCases.add(childCase); 
        	}  
    
    insert NewCases;
}
I don't need the code but just hints on how this can be done. Much appreciated...
I am trying to do an exercise from a Pluralsight course. Requirement is to get the lowest competitor price and populate the name of the competitor and the price:
User-added image

My code:
trigger CompetitorPrice5 on Opportunity (before insert, before update) {

    Map<id, Opportunity> BestPriceM = new Map<id, Opportunity>();

    //select all records into a map
    Map<id, Opportunity> m = new Map<id, Opportunity>([select id, competitor1__c, competitor_2__c, 
                                                       competitor_3__c, Competitor_Price_1__c,
                                                       Competitor_Price_2__c, Competitor_Price_3__c,
                                                       Best_Competitor_Price__c,Best_Competitor__c 
                                                       from opportunity 
                                                       where id in :trigger.Newmap.keySet()]);

    //process the record one by one and assign to the new list
    Decimal LowestPrice;    
    Decimal CurrentPrice;
    String CompName;

    for(Id i : m.keySet()){
     List<Decimal> AllPrices = new List<Decimal>();
	// System.debug('Values of AllPrices ' + AllPrices);
     List<String> AllComps = new List<String>();

     AllPrices.add(m.get(i).Competitor_Price_1__c);
	 AllPrices.add(m.get(i).Competitor_Price_2__c);
     AllPrices.add(m.get(i).Competitor_Price_3__c);

     AllComps.add(m.get(i).Competitor1__c);
     AllComps.add(m.get(i).Competitor_2__c);
     AllComps.add(m.get(i).Competitor_3__c);
	
    //compare each competitor's price with the LowestPrice and update if competitor's price is less
    for(Integer l; l < AllPrices.size(); l++)
        {
           CurrentPrice = AllPrices.get(l);
	            if(CurrentPrice < LowestPrice)
		            {
		                LowestPrice = CurrentPrice;
		                CompName = AllComps.get(l);
		            }

        }
    //update Best Competitor and Best Competitor Price fields    
    m.get(i).Best_Competitor_Price__c = LowestPrice;
    m.get(i).Best_Competitor__c = CompName;
	}
}
The problem is I keep getting a null values in AllPrices and AllComps lists and the update doesn't happen. The code compiles fine though. Please help...
 
I've completed the challenge, it has 100% coverage. I've checked all the method names. The URL is valid. I've used Work Bench and curl to test and even tested with multiple Accounts with and without contacts.

I know on other challenges, punctionation was important.  What about the defination of the return? Are there expected names?

I built a class to hold Account ID & Name along with a List of Contact names and IDs. Is this my issue?  Anyone else have a challenge with this challenge?


Any help or hints will be appreciated.

Here are snippets of my code:

@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {

....

global class APIAccount {
        public ID Id;
        public String Name;
        List<APIContact> Contacts;

...

@HttpGet
    global static APIAccount getAccount() {
        RestRequest request = RestContext.request;
...