• Oliver Westlake-Simm
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
I'm trying to create a lightning component that updates a boolean field on the case object, I've been playing around with it for a few days and can't work it out. I'm getting an error : Uncaught Action failed: c:UnEscalate$controller$unescalate [FALSE is not defined]
Using the following to trying and achieve the desired outcome. 

Component
<aura:component controller="UnescalateController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
	  <aura:at>tribute name="CaseObj" type="Case" default="{ 'sobjectType' : 'case'}"/>
      <lightning:button label="Unescalate" onclick="{! c.unescalate}"/>
</aura:component
JS Controller
({
  unescalate : function(component, event, helper) {
      
      var caseObject = component.get("v.CaseObj");
        caseObject.Admin_Escalation__c = FALSE;
       
       
      var action = component.get("c.updateAdmin_Escalation__c");
          action.setParams({
            obj: caseObject,
            oId : component.get("v.recordId")  
        });
      // set call back 
        action.setCallback(this, function(response) {
            
            var state = response.getState();
            if (state === "SUCCESS") {
                alert('This case has been unescalated!');
                $A.get('e.force:refreshView').fire();
            }
             else if (state === "INCOMPLETE") {
                alert("From server: " + response.getReturnValue());
            } else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });
        // enqueue the action
        $A.enqueueAction(action);
   }
})
Apex Controller
 
public class UnescalateController {
 @AuraEnabled 
    public static void updateStatus(case obj,String oId){
        system.debug('obj' + obj);
        case cc = obj;
        cc.Id = oId;
        update cc;
    }
}


 
I've created an Invocable Apex Class that allow us to search articles and return the resolution to the bot. The Apex class works as expected in the sandbox. However, I'm struggling to create a test class with more then 68% code coverage. Could anyone help, please?

APEX CLASS
public with sharing class Bot_SearchFAQ {
    public class FAQSearchInput{
        @InvocableVariable(required=true)
        public String sKeyword;
    }
    public class FAQSearchOutput{
        @InvocableVariable(required=true)
        public String sFAQSearchResult;
    }
    @InvocableMethod(label='Search FAQ')
    public static List<FAQSearchOutput> searchFAQ(List<FAQSearchInput> faqSearchInput) {
        String sArticleBaseUrl = getCommunityArticleBaseUrl();
        String sKeyword = faqSearchInput[0].sKeyword;
        String sQuery = 'FIND \'' + String.escapeSingleQuotes(sKeyword) + '\' IN NAME FIELDS RETURNING Knowledge_Article__kav(Id, Title, Chatbot_URL__c, Chatbot_Resolution__c WHERE PublishStatus = \'Online\' AND Language = \'en_US\' AND IsVisibleInPkb = true) WITH SNIPPET (target_length=255) LIMIT 1';
        System.debug(sQuery);
        Search.SearchResults searchResults = Search.find(sQuery);
        List<Search.SearchResult> articlelist = searchResults.get('Knowledge_Article__kav');
        System.debug('articlelist: ' + articlelist);
        String sFAQSearchResult = '';
        for (Search.SearchResult searchResult : articlelist)        {
            Knowledge_Article__kav article = (Knowledge_Article__kav)searchResult.getSObject();
            String sArticleSummary;
            //String sSnippet = searchResult.getSnippet('Knowledge_Article__kav.Resolution__c');
            String sSnippet = article.Chatbot_Resolution__c;
            sArticleSummary = summarizeArticleForBot(sArticleBaseUrl, article, sSnippet);
            System.debug('sArticleSummary: ' + sArticleSummary);
            sFAQSearchResult = sFAQSearchResult + sArticleSummary;
        }
        if (sFAQSearchResult == '') sFAQSearchResult = 'No result found.';
        List<FAQSearchOutput> faqSearchOutputs = new List<FAQSearchOutput>();
        FAQSearchOutput faqSearchOutput = new FAQSearchOutput();
        faqSearchOutput.sFAQSearchResult = sFAQSearchResult;
        faqSearchOutputs.add(faqSearchOutput);
        system.debug(faqSearchOutput);
        return faqSearchOutputs;
    }

    public static String summarizeArticleForBot(String sArticleBaseUrl, Knowledge_Article__kav article, String sSnippet){
        String sSummary, sURL;
        sURL = article.Chatbot_URL__c;
        //remove highlight HTML tag <mark>
        sSummary = 'Here is what I found: ' + sSnippet.replaceAll('<[^>]+>',' ') + '\n' + 'To read more click here:\n' + sURL + '\n';
        return sSummary;
    }
    public static string getCommunityArticleBaseUrl()
    {
        List<Network> communityNetworks = [SELECT Id FROM Network WHERE Name='Community Support'];
        String sArticleBaseUrl = '';
        if (communityNetworks.size()>0)
        {
            Network communityNetwork = communityNetworks[0];
            String sLoginUrl = Network.getLoginUrl(communityNetwork.id);
            sArticleBaseUrl = sLoginUrl.replace('/login', '/article/');
            System.debug('MyDebug - Community Login URL: ' + sLoginUrl);
            System.debug('MyDebug - Article Base URL: ' + sArticleBaseUrl);
        }
        return sArticleBaseUrl;
    }
}

TEST CLASS
@isTest
private class Bot_SearchFAQ_Test{
  @testSetup
  static void setupTestData(){   
    Knowledge_Article__kav knowledge_article_kav_Obj = new Knowledge_Article__kav(IsVisibleInPkb = true, Language = 'en_US', Title = 'Test Text?', Details__c='Test Text.', UrlName = 'UrlName760', Chatbot_Resolution__c = 'Test Text', Chatbot_URL__c = 'http://test71.com');
    Insert knowledge_article_kav_Obj;
    Knowledge_Article__kav newArticle = [SELECT Id, KnowledgeArticleId FROM Knowledge_Article__kav WHERE id=:knowledge_article_kav_Obj.Id];
    String articleId = newArticle.KnowledgeArticleId;
    KbManagement.PublishingService.publishArticle(articleId, true);
  }
  static TestMethod void test_searchFAQ_UseCase1(){
    test.startTest();

    Bot_SearchFAQ.faqSearchInput input = new Bot_SearchFAQ.faqSearchInput();
    input.sKeyword = 'Test Text?';

    List<Bot_SearchFAQ.faqSearchInput> listInput = new List<Bot_SearchFAQ.faqSearchInput>();
    listInput.add(input);

    Bot_SearchFAQ.searchFAQ(listInput);

    test.stopTest();
  }
}
I'm trying to create an Invocable Apex Class to Search Articles within Einstein bots. I'm using the "Einstein Bot Cookbook for Intermediate Developers" pdf which provides the following but i'm getting an Illegal string literal: Line breaks are not allowed in string literals error when trying to run.


String sArticleBaseUrl = getCommunityArticleBaseUrl();
        String sKeyword = faqSearchInput[0].sKeyword;
        String sQuery = 'FIND \'' + sKeyword + '\' IN ALL FIELDS RETURNING
            KnowledgeArticleVersion(Id, Title, UrlName WHERE PublishStatus = \'Online\'
                                    AND Language = \'en_US\' AND IsVisibleInPkb = true) WITH SNIPPET
                                    (target_length=255) LIMIT 3';
                                    Search.SearchResults searchResults = Search.find(sQuery);
                                    List<Search.SearchResult> articlelist =
                                    searchResults.get('KnowledgeArticleVersion');
                                    String sFAQSearchResult = '';
                                    for (Search.SearchResult searchResult : articlelist)
I'm trying to create a lightning component that updates a boolean field on the case object, I've been playing around with it for a few days and can't work it out. I'm getting an error : Uncaught Action failed: c:UnEscalate$controller$unescalate [FALSE is not defined]
Using the following to trying and achieve the desired outcome. 

Component
<aura:component controller="UnescalateController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
	  <aura:at>tribute name="CaseObj" type="Case" default="{ 'sobjectType' : 'case'}"/>
      <lightning:button label="Unescalate" onclick="{! c.unescalate}"/>
</aura:component
JS Controller
({
  unescalate : function(component, event, helper) {
      
      var caseObject = component.get("v.CaseObj");
        caseObject.Admin_Escalation__c = FALSE;
       
       
      var action = component.get("c.updateAdmin_Escalation__c");
          action.setParams({
            obj: caseObject,
            oId : component.get("v.recordId")  
        });
      // set call back 
        action.setCallback(this, function(response) {
            
            var state = response.getState();
            if (state === "SUCCESS") {
                alert('This case has been unescalated!');
                $A.get('e.force:refreshView').fire();
            }
             else if (state === "INCOMPLETE") {
                alert("From server: " + response.getReturnValue());
            } else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });
        // enqueue the action
        $A.enqueueAction(action);
   }
})
Apex Controller
 
public class UnescalateController {
 @AuraEnabled 
    public static void updateStatus(case obj,String oId){
        system.debug('obj' + obj);
        case cc = obj;
        cc.Id = oId;
        update cc;
    }
}