• Sharu Priya
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
Hi I have created a OB messaging to send a Field from salesforce Object to the external System. the condition is whenever the record is created it should send the field to the external system using the endpoint url. But when we tested by creating new record it throwing the following error please advise.

User-added image
Hi,

I m new to coding , Please help me on how to write Test class for code coverage for the below Rest api class
 
global class ZyncAPI {
    public CarePlanWrapper getZyncData() {
        // Instantiate a new http object        
        Http h = new Http();        
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint        
        HttpRequest req = new HttpRequest(); 
        String endUrl = 'http://carrotcube-esb-zynx.cloudhub.io/zynx/PlanDefinition';
        req.setEndpoint(endUrl);
        system.debug(endUrl);   
        req.setMethod('GET');        
        // Send the request, and return a response        
        HttpResponse res = h.send(req);
        system.debug(res.getBody());
        //List<HealthCloudGA__EhrCondition__c> patientCondition = new List<HealthCloudGA__EhrCondition__c>();
        //HealthCloudGA__EhrCondition__c Ehrpatientcondition;                               
        
        //ZyncJSONWrapper zyncresponse = new ZyncJSONWrapper();
        //List<ZyncJSONWrapper> zyncresponseData = new List<ZyncJSONWrapper>();
        //I tried the below one and zyncresponse.Action also still the same. 
        CarePlanWrapper PlanWrapper = new CarePlanWrapper();
        PlanWrapper = CarePlanWrapper.parse(res.getbody());
        system.debug(PlanWrapper);
        
        Map<string,List<HealthCloudGA__CarePlanGoal__c>> ProblemGoalMap = new Map<string,List<HealthCloudGA__CarePlanGoal__c>>();
        Map<string,List<Interventions__c>> GoalIntervensionMap = new Map<string,List<Interventions__c>>();
        Map<string,List<Task>> IntervensionTaskMap = new Map<string,List<Task>>();
        
        
        List<HealthCloudGA__CarePlanProblem__c> patientProblem = new List<HealthCloudGA__CarePlanProblem__c>();
        
        
        
        for(CarePlanWrapper.cls_entry entry : PlanWrapper.entry){
            List<HealthCloudGA__CarePlanGoal__c> GoalsList = new List<HealthCloudGA__CarePlanGoal__c>();
            for(CarePlanWrapper.cls_action actionRec : entry.resource.action){
                HealthCloudGA__CarePlanGoal__c cpgoal = new HealthCloudGA__CarePlanGoal__c();
                cpgoal.Name = actionRec.Title;
                GoalsList.add(cpGoal);
                List<Interventions__c> intervensionList = new List<Interventions__c>();
                for(CarePlanWrapper.cls_action goal : actionRec.action){
                    Interventions__c intervension = new Interventions__c();
                    if(goal.title != Null && goal.title.length() > 80)
                        intervension.Name = goal.Title.substring(0,80);
                    else
                        intervension.Name = goal.Title;
                    intervension.Title__c = goal.Title;
                    intervensionList.add(Intervension);
                    if(goal.action != Null){
                        List<task> taskList = new List<Task>();
                        for(CarePlanWrapper.Cls_Action task : goal.action){
                            task tsk = new Task();
                            tsk.Subject = task.title;
                            tsk.priority = 'Medium';
                            tsk.status = 'Not started';
                            taskList.add(tsk);
                        }
                        IntervensionTaskMap.put(entry.Resource.Title+actionRec.Title+goal.Title,TaskList);
                    }
                }                
                GoalIntervensionMap.put(entry.Resource.Title+actionRec.Title,intervensionList);
            }
            HealthCloudGA__CarePlanProblem__c cpproblem = new HealthCloudGA__CarePlanProblem__c();
            cpproblem.Name = entry.Resource.Title;
            patientProblem.add(cpproblem);
            ProblemGoalMap.put(entry.Resource.Title,GoalsList);
        }
        system.debug(ProblemGoalMap);
        system.debug(GoalIntervensionMap);
        System.debug(IntervensionTaskMap);
        
        system.debug(ProblemGoalMap.KeySet().size());
        system.debug(GoalIntervensionMap.Keyset().size());
        system.debug(IntervensionTaskMap.keyset().size());
        
        
        
        Map<string,string> ProblemIdMap = new Map<string,string>();
        Map<string,string> GoalIdMap = new Map<string,string>();
        List<HealthCloudGA__CarePlanGoal__c> GoalUpdateList = new List<HealthCloudGA__CarePlanGoal__c>();
        
        if(patientProblem.size() > 0)
            upsert patientProblem;
        
        for(HealthCloudGA__CarePlanProblem__c Problem : patientProblem){
            ProblemIdMap.put(problem.Name,Problem.id);
        }    
            
        for(string Plan : ProblemGoalMap.Keyset()){
            for(HealthCloudGA__CarePlanGoal__c goal : ProblemGoalMap.get(plan)){
                goal.HealthCloudGA__CarePlanProblem__c = ProblemIdMap.get(plan);
                GoalUpdateList.add(goal);
            }
        }
        
        if(GoalUpdateList.size() > 0)
            upsert GoalUpdateList;
        
        for(HealthCloudGA__CarePlanGoal__c goal : [select id,name,HealthCloudGA__CarePlanProblem__r.Name from HealthCloudGA__CarePlanGoal__c where id IN: GoalUpdateList]){
            GoalIdMap.put(goal.HealthCloudGA__CarePlanProblem__r.Name+goal.Name,goal.id);
        }
        
        List<Interventions__c> InterventionUpdateList = new List<Interventions__c>();
        for(string intervension : GoalIntervensionMap.Keyset()){
            for(Interventions__c inter : GoalIntervensionMap.get(intervension)){
                inter.Goal__c = GoalIdMap.get(intervension);
                InterventionUpdateList.add(inter);
            }
        }
        
        if(InterventionUpdateList.size() > 0)
            upsert InterventionUpdateList;
        Map<string,string> IntervesionIdMap = new Map<string,string>();
        for(Interventions__c inter : [select id,Title__c,Goal__r.Name,Goal__r.HealthCloudGA__CarePlanProblem__r.Name from Interventions__c where id in: InterventionUpdateList]){
            IntervesionIdMap.put(inter.Goal__r.HealthCloudGA__CarePlanProblem__r.Name+inter.goal__r.name+inter.Title__c,inter.id);
        }  
        
        system.debug(IntervesionIdMap.Keyset());
        system.debug(IntervensionTaskMap.keySet());
        
        for(string s : IntervesionIdMap.Keyset()){
            system.debug(s);
        }
        
        List<task> TaskUpdateList = new List<task>();
        for(string taskString : IntervensionTaskMap.keySet()){
            for(Task tsk : IntervensionTaskMap.get(taskString)){
                tsk.whatId = IntervesionIdMap.get(taskString);
                TaskUpdateList.add(tsk);
            }
        }  
        
        system.debug(TaskUpdateList[0]);

        if(TaskUpdateList.size() > 0)
            Upsert TaskUpdateList;

       try{
            if(res.getStatusCode() == 200)
            {
              
            }
        }
        catch(exception e){}
        return PlanWrapper;
  }
}

Thank You,
Sharu​
I have a requirement to create a report and dashboard . the Requirement is "need a report that shows the % of the email cases that we respond to within 24 hours. That time clock would stop when an agent accepts the case and begins work on it."
This is when a email case comes in , if the Case owner changes from automated Username to a Particular user than it will be consider as Responded.

I have created a workflow and Formula field that will calculate the hours between the Created datetime and First response Date time.

Now in Reports how I should bring the % of email cases that were responded within 24 dours. 

Please advise.