Loading
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Capture Scores and Score Categories in the Action Log

          Capture Scores and Score Categories in the Action Log

          The action history logged in Health Score Action Log doesn’t include score information by default. Use this custom Apex code with our Apex interface to capture score information in your logs.

          Required Editions

          Available in: Enterprise and Unlimited Editions with Health Cloud

          Custom Code

          global class ApexClassForCustomLogs implements healthcloudext.IUnifiedHealthScore{//IMPORTANT: replace CustomActionLog with the name the Apex class 
              public Boolean saveActionDetail(Map<String, String> request){
                  try {
                      String aSubject = request.get('subjectId');
                      List<HealthScore> aHealthScore = [select CurrentScore from HealthScore where SubjectId=:aSubject and ScoreCategoryId='0gzRN00000001drYAA'];
                      //IMPORTANT: Replace 0gzRN00000001drYAA with the Id of your score category.
                      List<HealthScoreActionLog> acctList = new List<HealthScoreActionLog>();
                  HealthScoreActionLog aHealthScoreActionLog = new HealthScoreActionLog(
                       ActionDescription=request.get('actionDescription'),
                       ActionIconUrl=request.get('actionIconUrl'),
                       ActionLabel=request.get('actionLabel'),
                       ActionName=request.get('actionName'),
                       ActionStatus=request.get('actionStatus'),
                       PerformedById=request.get('performedById'),
                       SubjectId=request.get('subjectId'),
                       ActionDate=datetime.now(),
                      Score=aHealthScore[0].CurrentScore,
                      ScoreCategoryId='0gzRN00000001drYAA'//IMPORTANT: Replace 0gzRN00000001drYAA with the Id of your score category.
                  );
                      acctList.add(aHealthScoreActionLog);
                      Database.SaveResult[] srList = Database.insert(acctList, false);
                      for (Database.SaveResult sr : srList) {
              if (sr.isSuccess()) {
                  // Operation was successful, so get the ID of the record that was processed
                  System.debug('Successfully inserted account. HealthScoreActionLog ID: ' + sr.getId());
              }
              else {
                  // Operation failed, so get all errors
                  for(Database.Error err : sr.getErrors()) {
                      System.debug('The following error has occurred.');
                      System.debug(err.getStatusCode() + ': ' + err.getMessage());
                      System.debug('Account fields that affected this error: ' + err.getFields());
                  }
              }
          }
                      //insert aHealthScoreActionLog;
                      return true;
                  }catch(DmlException e) {
                    System.debug('An unexpected error has occurred: ' + e.getMessage());
                    return false;
                  }
              }
          }
          Important
          Important Ensure that you replace the category ID in this sample code with the ID of the category that you want to log score information for. You can find the IDs of your score categories by either inspecting a category page’s URL, or you can run this query in the Developer Console Query Editor: Select Id,CategoryName from ScoreCategory.

          And that’s it! Using this sample code, your action logs now also mention the specified score category and its score value at the time the action was triggered.

           
          Loading
          Salesforce Help | Article