• Akash Deokar
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 6
    Replies
Hello team,
 
I have stuck in Apex specialist superbadge(Challenge 5), Please help me with the resolution. I have written class WarehouseCalloutService, which is getting executed without error if i called it from debug log But getting runtime error while running test class written for that class.
 
Getting Error :- FATAL_ERROR System.TypeException: Invalid conversion from runtime type Map<String,ANY> to List<ANY>
 
 
class:-WarehouseCalloutService
global with sharing class WarehouseCalloutService {
    
private static final String WAREHOUSE_URL = 'https://th-superbadge-apex.herokuapp.com/equipment';    
    @future (callout=true)
    public static void runWarehouseEquipmentSync() {
        //ToDo: complete this method to make the callout (using @future) to the
        //      REST endpoint and update equipment on hand.
        Http http = new Http();
        HttpRequest req  = new HttpRequest();
        req.setEndpoint(WAREHOUSE_URL);
        req.setMethod('GET');
        HttpResponse res = http.send(req);
        
        if(res.getStatusCode()==200){
            List<object> results = (List<object>)JSON.deserializeUntyped(res.getBody());
            system.debug(results);
            List<Product2> productlist = new List<Product2>();
            for(Object o : results){
                Map<string,Object> eqp = (Map<String,Object>)o;
                system.debug(eqp);
                Product2 equipment = new Product2();                
                equipment.Replacement_Part__c = (Boolean)eqp.get('replacement');
                equipment.Current_Inventory__c = (Decimal)eqp.get('quantity');
                equipment.Lifespan_Months__c = (Integer)eqp.get('lifespan');
                equipment.Maintenance_Cycle__c = (Integer)eqp.get('maintenanceperiod');
                equipment.Name = (String)eqp.get('name');
                equipment.Cost__c = (Integer)eqp.get('cost');
                equipment.ProductCode = (String)eqp.get('_id');
                equipment.Warehouse_SKU__c = (String)eqp.get('sku');
                productlist.add(equipment);
            }
            system.debug(productlist);
            upsert productlist;
        }
    }
}

 
Error to complete challenge 3(Create reports for the Support team) of Lightning Experience Reports & Dashboards Specialist superbadge.

Error: Challenge Not yet complete... here's what's wrong:
We can’t find a report with name 'SolarBot Status Averages' in the correct folder, or it uses an incorrect report type.


I have created custom report with only primary object as SolarBot Status and stored in Status Report under SolarBot Support Reports.
 
can we call future method from batch apex?
Please explain in brief what needs to known to execute it.
 
I have written trigger on opportunity as below, if opportunity stage gets update to verbal agreement then SAP CODE and LEGAL ENTITY should be available or it will through error.

But output is not getting as i wanted, please check below logic from code and output. 

Apex Trigger:
trigger SAP_CODE on Opportunity (before Update) {
   for(Opportunity opp:trigger.new){
           
        if(opp.StageName=='Verbal Agreement'){
            System.debug('Stage is verbal');
            
            if(opp.Legal_Entity_Name__r.Name==null){
                System.debug('inside entity name');
                opp.addError('Oppotunity cannot move to 80% as LE is not present');
                
                 If(opp.Legal_Entity_Name__r.SAP_CODE__c==null){
                    opp.addError('Oppotunity cannot move to 80% as SAPE CODE is not present');
                    System.debug('SAP code not available');
                }
            }
            else{
            system.debug('SAP code is available');
            }
        }
    }
}

Code to run trigger:
Opportunity opp= new Opportunity(name='demo', stagename='Qualification', closedate=system.today());
Account demoacc=[Select id from Account where name='Demo Account'];
opp.accountid=demoacc.id;
insert opp;
System.debug('opp inserted');
opp.stagename='verbal agreement';
try{
update opp;
}catch(Exception e)
{e.getmessage();}
Legal_Entity__c LEDemo = new Legal_Entity__c();
insert LEDemo;
opp.Legal_Entity_Name__c=LEDemo.id;
System.debug('LE inserted');
try{
update opp;
}catch(Exception e)
{e.getmessage();}
LEDemo.SAP_CODE__c='0008';
system.debug('SAP CODE updated');
try{
update opp;
}catch(Exception e)
{e.getmessage();}

Output:
User-added image
I have written before update trigger on opportunity but it is not working for below code, not providing error when changing stage to verbal agreement.

Note: I have created one opportunity stage as verbal agreement(80%).

for(Opportunity opp:[Select id,name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:trigger.new)]){
        if(opp.Legal_Entity_Name__r.SAP_CODE__c==null && opp.Legal_Entity_Name__r.Name==null){
            opp.addError('Oppotunity cannot move to 80% as SAP CODE or LE is not present');


For below code there is error occured as mentioned in code but error is getting for all the stages instead of verbal agreement.

trigger SAP_CODE on Opportunity (before Update) {
    
    Set<Opportunity> updatedoppty = new Set<Opportunity>();
    for (Opportunity opp: trigger.new){
        updatedoppty.add(opp);
    }  
    
    Map<id,Opportunity> mapopty = new Map<id,Opportunity>();
    mapopty.putAll([Select id, name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:updatedoppty)]);
    
    For (Opportunity opp: trigger.new){
        
        if(null==mapopty.get(opp.Legal_Entity_Name__r.name)){
             opp.addError('Oppotunity cannot move to 80% as LE is not present');
        }
        if(null==mapopty.get(opp.Legal_Entity_Name__r.SAP_CODE__c))
        {
               opp.addError('Oppotunity cannot move to 80% as SAP CODE is not present');
        }
    } 


 
I have created one lookup field of custom object(Legal Entity) on opportunity object. Now i want records of opportunity where SAP code field is blank on Legal Entity Object.

I have written query as below but it is not getting executed.

Select id, name, Legal_Entity__r.SAP_CODE__c from opportunity

Error:Didn't understand relationship 'Legal_Entity__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
I have written trigger on opportunity as below, if opportunity stage gets update to verbal agreement then SAP CODE and LEGAL ENTITY should be available or it will through error.

But output is not getting as i wanted, please check below logic from code and output. 

Apex Trigger:
trigger SAP_CODE on Opportunity (before Update) {
   for(Opportunity opp:trigger.new){
           
        if(opp.StageName=='Verbal Agreement'){
            System.debug('Stage is verbal');
            
            if(opp.Legal_Entity_Name__r.Name==null){
                System.debug('inside entity name');
                opp.addError('Oppotunity cannot move to 80% as LE is not present');
                
                 If(opp.Legal_Entity_Name__r.SAP_CODE__c==null){
                    opp.addError('Oppotunity cannot move to 80% as SAPE CODE is not present');
                    System.debug('SAP code not available');
                }
            }
            else{
            system.debug('SAP code is available');
            }
        }
    }
}

Code to run trigger:
Opportunity opp= new Opportunity(name='demo', stagename='Qualification', closedate=system.today());
Account demoacc=[Select id from Account where name='Demo Account'];
opp.accountid=demoacc.id;
insert opp;
System.debug('opp inserted');
opp.stagename='verbal agreement';
try{
update opp;
}catch(Exception e)
{e.getmessage();}
Legal_Entity__c LEDemo = new Legal_Entity__c();
insert LEDemo;
opp.Legal_Entity_Name__c=LEDemo.id;
System.debug('LE inserted');
try{
update opp;
}catch(Exception e)
{e.getmessage();}
LEDemo.SAP_CODE__c='0008';
system.debug('SAP CODE updated');
try{
update opp;
}catch(Exception e)
{e.getmessage();}

Output:
User-added image
I have written before update trigger on opportunity but it is not working for below code, not providing error when changing stage to verbal agreement.

Note: I have created one opportunity stage as verbal agreement(80%).

for(Opportunity opp:[Select id,name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:trigger.new)]){
        if(opp.Legal_Entity_Name__r.SAP_CODE__c==null && opp.Legal_Entity_Name__r.Name==null){
            opp.addError('Oppotunity cannot move to 80% as SAP CODE or LE is not present');


For below code there is error occured as mentioned in code but error is getting for all the stages instead of verbal agreement.

trigger SAP_CODE on Opportunity (before Update) {
    
    Set<Opportunity> updatedoppty = new Set<Opportunity>();
    for (Opportunity opp: trigger.new){
        updatedoppty.add(opp);
    }  
    
    Map<id,Opportunity> mapopty = new Map<id,Opportunity>();
    mapopty.putAll([Select id, name, Legal_Entity_Name__r.SAP_CODE__c,StageName from opportunity where (StageName='Verbal Agreement' and id in:updatedoppty)]);
    
    For (Opportunity opp: trigger.new){
        
        if(null==mapopty.get(opp.Legal_Entity_Name__r.name)){
             opp.addError('Oppotunity cannot move to 80% as LE is not present');
        }
        if(null==mapopty.get(opp.Legal_Entity_Name__r.SAP_CODE__c))
        {
               opp.addError('Oppotunity cannot move to 80% as SAP CODE is not present');
        }
    } 


 
I have created one lookup field of custom object(Legal Entity) on opportunity object. Now i want records of opportunity where SAP code field is blank on Legal Entity Object.

I have written query as below but it is not getting executed.

Select id, name, Legal_Entity__r.SAP_CODE__c from opportunity

Error:Didn't understand relationship 'Legal_Entity__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.