• Shaiff
  • NEWBIE
  • 30 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
In apex specialist superbadge challenge 1, i am not able to get the Equipment__c field in Case Object. Can anyone help with that?

Hi,

Can Any one suggest  me the reason for error. Here is my below code.

Apex Class:

public with sharing class MaintenanceRequestHelper {
    
    public static void updateWorkOrders(List<Case> caseList) {
        List<case> newCases = new List<Case>();
        Map<String,Integer> result=getDueDate(caseList);
        for(Case c : caseList){
            if(c.status=='closed')
                if(c.type=='Repair' || c.type=='Routine Maintenance'){
                    Case newCase = new Case();
                    newCase.Status='New';
                    newCase.Origin='web';
                    newCase.Type='Routine Maintenance';
                    newCase.Subject='Routine Maintenance of Vehicle';
                    newCase.Vehicle__c=c.Vehicle__c;
                    newCase.ProductId=c.ProductId;
                    newCase.Date_Reported__c=Date.today();
                    if(result.get(c.Id)!=null)
                     newCase.Date_Due__c=Date.today()+result.get(c.Id);
                    else
                        newCase.Date_Due__c=Date.today();
                    newCases.add(newCase);
                }
        }        
        insert newCases;   
    }
    
    public static  Map<String,Integer> getDueDate(List<case> CaseIDs){       
       Map<String,Integer> result = new Map<String,Integer>();
        Map<Id, case> caseKeys = new Map<Id, case> (CaseIDs);        
       List<AggregateResult> wpc=[select Maintenance_Request__r.ID cID,min(Equipment__r.Maintenance_Cycle__c)cycle
                      from Equipment_Maintenance_Item__c where  Maintenance_Request__r.ID in :caseKeys.keySet() group by             Maintenance_Request__r.ID ];
        for(AggregateResult res :wpc){
            Integer addDays=0;
            if(res.get('cycle')!=null)
                addDays+=Integer.valueOf(res.get('cycle'));
            result.put((String)res.get('cID'),addDays);
        }
        return result;
}

}

Apex Trigger;
trigger MaintenanceRequest on Case (after update) {
    // ToDo: Call MaintenanceRequestHelper.updateWorkOrders
                 MaintenanceRequestHelper.updateWorkOrders(Trigger.New);
}
 

User-added image

  • April 05, 2021
  • Like
  • 0
getting error on -Variable does not exist: Equipment__c for the below code.. please help me out to this challenge 1 


public class MaintenanceRequestHelper {
    
    public static void updateWorkOrders(){
        Map<Id, Case> mantnceReqToEvaluate = new Map<Id, Case>();
        for(Case mantnceReq : (List<Case>)Trigger.new){
            if((mantnceReq.Type.contains('Repair') || mantnceReq.Type.contains('Routine Maintenance')) && mantnceReq.Status == 'Closed'){
                mantnceReqToEvaluate.put(mantnceReq.Id,mantnceReq);
            }
        }
        
        Map<Id, decimal> mapOfProdIdWithMaintenanceCycle = getMapOfProdIdWithMaintenanceCycle();
        
        List<Case> lstOfMaintenanceRoutines = getListOfMaintenanceRoutineList(mantnceReqToEvaluate, mapOfProdIdWithMaintenanceCycle);

        System.debug('lstOfMaintenanceRoutines :::::::: '+lstOfMaintenanceRoutines);
        if(lstOfMaintenanceRoutines != null && lstOfMaintenanceRoutines.size() > 0)
            INSERT lstOfMaintenanceRoutines;
    }
    
    private static Map<Id, decimal> getMapOfProdIdWithMaintenanceCycle(){
        Map<Id,decimal> mapOfProdIdWithMaintenanceCycle = new Map<Id, decimal>();
        for(Product2 prod : [SELECT Id, Maintenance_Cycle__c from Product2]){
            mapOfProdIdWithMaintenanceCycle.put(prod.Id, prod.Maintenance_Cycle__c);
        }
        
        return mapOfProdIdWithMaintenanceCycle;
    }
    
    private static List<Case> getListOfMaintenanceRoutineList(Map<Id, Case> mantnceReqToEvaluate, Map<Id, decimal> mapOfProdIdWithMaintenanceCycle){
        List<Case> lstOfMaintenanceRoutines = new List<Case>();
        
        for(Case maintenance : mantnceReqToEvaluate.values()){
            Case maintenanceNewIns = new Case();
            maintenanceNewIns.Vehicle__c = maintenance.Vehicle__c;
            maintenanceNewIns.Equipment__c = maintenance.Equipment__c;
            maintenanceNewIns.Type = 'Routine Maintenance';
            maintenanceNewIns.Subject = 'Your Routine Maintenance Schedule';
            maintenanceNewIns.Date_Reported__c = Date.today();
            maintenanceNewIns.Date_Due__c = getDueDate(maintenance, mapOfProdIdWithMaintenanceCycle);
            
            maintenanceNewIns.Status = 'New';
            maintenanceNewIns.Origin = 'Phone';
        
            lstOfMaintenanceRoutines.add(maintenanceNewIns);
        }
        return lstOfMaintenanceRoutines;    
    }
    
    private static Date getDueDate(Case maintenance, Map<Id, decimal> mapOfProdIdWithMaintenanceCycle){
        Date dt = null;
        if (mapOfProdIdWithMaintenanceCycle.get(maintenance.Equipment__c) != null) {
            dt = Date.today().addDays(Integer.valueOf(mapOfProdIdWithMaintenanceCycle.get(maintenance.Equipment__c)));
        }
        
        return dt;
    }
}



trigger MaintenanceRequest on Case (before update, after update) {
    // ToDo: Call MaintenanceRequestHelper.updateWorkOrders
    if(Trigger.isAfter)
    {MaintenanceRequestHelper.updateWorkOrders(Trigger.New);}
            
}
Hi,

Challenge Not yet complete... here's what's wrong: 
An Opportunity with the Stage 'Negotiation/Review' and the Amount greater than $100,000 was not successfully submitted for approval upon creation.

I have the above error while check challenge the 5th stage of process automation specialist.

Thanks in advance.

Best Regards
Kamala.
Hi,
I am stuck in Step 2 (Automate Accounts) . I am getting below error message.
Challenge Not yet complete... here's what's wrong:
Please check the configuration of the custom fields on the Account object. The formulas, rollup summaries, etc. did not produce the expected outcome.

I have Created Custom Fields as below
Number of deals, Number_of_deals__c --> Roll-Up Summary (COUNT Opportunity)     
Number of won deals, Number_of_won_deals__c --> Roll-Up Summary (COUNT Opportunity) with filter criteria of Closed Won
Amount of won deals, Amount_of_Won_Deals__c --> Roll-Up Summary (SUM Opportunity) with filter criteria of Closed Won
Last won deal date, Last_won_deal_date__c --> Roll-Up Summary (MAX Opportunity)
Deal win percent, Deal_win_percent__c - Formula --> IF ( Number_of_deals__c > 0, (Number_of_deals__c / Number_of_won_deals__c ), 0))
Call for Service, Call_for_Service__c - Formula --> IF(OR(TODAY() - 730 > Last_won_deal_date__c , TODAY() + 730 < Last_won_deal_date__c ), 'Yes','No')

Also my Validation Rules are configured as :
For Account Name Edit Validation - Created 2 Validation Rules
ISCHANGED( Name ) && ISPICKVAL(Type, "Customer - Channel")
ISCHANGED( Name ) && ISPICKVAL(Type, "Customer - Direct" )

For Billing State/Province Validation Rule is
NOT(
CONTAINS("AL:AK:AZ:AR:CA:CO:CT:DE:DC:FL:GA:HI:ID:" &
"IL:IN:IA:KS:KY:LA:ME:MD:MA:MI:MN:MS:MO:MT:NE:NV:NH:" &
"NJ:NM:NY:NC:ND:OH:OK:OR:PA:RI:SC:SD:TN:TX:UT:VT:VA:" &
"WA:WV:WI:WY", BillingState))

For Billing Country Validation Rule is
BillingCountry <> "US" && BillingCountry <> "USA" && BillingCountry <> "United States" &&  NOT( ISBLANK(BillingCountry ) )

Same Validation rule are set for Shipping State/Province and Shipping Country (with correct field name).

Can anyone help me with this????
Has anyone tried to merge two different trailhead accounts before? If so, can you let me know how.