function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Oliver Westlake-SimmOliver Westlake-Simm 

Illegal string literal: Line breaks are not allowed in string literals error when implementing chatbot

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)
SandhyaSandhya (Salesforce Developers) 
Hi,

When you copied the code line breaks might have copied. I would suggest you to remove the space from each line or on the line where you are getting this error.

Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya