You need to sign in to do that
Don't have an account?

Query returning "line breaks not allowed in string literals" error.
Can anyone tell me what is wrong with the format of this query?:
Thank you!
List<KnowledgeArticleVersion> kavs = new List<KnowledgeArticleVersion>([SELECT Id, title, UrlName, Summary FROM KnowledgeArticleVersion WHERE PublishStatus = 'online' AND Language = \''+ String.escapeSingleQuotes(language) +'\' AND KnowledgeArticleId IN :statIds]);
Thank you!
What are the potetial values of the variable 'language'? And where does statIds come from?
That works fine.
Potential variables of language are:
Try this query:
Use followings:
List<KnowledgeArticleVersion> kavs = new List<KnowledgeArticleVersion>([SELECT Id, title, UrlName, Summary FROM KnowledgeArticleVersion WHERE PublishStatus = 'online' AND Language = '\''+ String.escapeSingleQuotes(language) + '\'' + AND KnowledgeArticleId IN :statIds]);
Both of your queries are identical, so I put it in my code:
Here is the error I received now:
"Compile Error: expecting right square bracket, found '+' at line 38 column 194"
Seems like the number of quotation marks may be off a little. I will mess around with it myself, but if you have a quick fix that would be great!
Try followings. It can give you results.
String languagename = '\''+ String.escapeSingleQuotes(language) + '\'';
List<KnowledgeArticleVersion> kavs = new List<KnowledgeArticleVersion>([SELECT Id, title, UrlName, Summary FROM KnowledgeArticleVersion WHERE PublishStatus = 'online' AND Language = :languagename AND KnowledgeArticleId IN :statIds]);
System.Debug('----------------------------------------------------> Here is the value: '+kavs);
Compile Error: Implementation restriction: When querying the KnowledgeArticleVersion object, you must filter using the following syntax: Id = [single ID], Id IN [list of ID's] or Language = [language ISO code]. In addition Language is only permitted in a top-level AND condition. at line 38 column 80
I have no clue as to why this is only failing with the KAV object. I know for SURE that the value of "language" in this case is "en_us", which is a valud language ISO code.
Your error indicates, need to add id=some id of knowledgeArticleVersion or id IN [list of id of knowledgeArticleVersion]
So, query will be like tis:
String languagename = '\''+ String.escapeSingleQuotes(language) + '\'';
String knowledgeArticleId = [id of the knowledgeArticleversion record];
List<KnowledgeArticleVersion> kavs = new List<KnowledgeArticleVersion>([SELECT Id, title, UrlName, Summary FROM KnowledgeArticleVersion WHERE PublishStatus = 'online' AND Language = :languagename AND KnowledgeArticleId IN :statIds AND Id = knowledgeArticleId]);
System.Debug('----------------------------------------------------> Here is the value: '+kavs);
Just to make sure this information is out there, the results of System.Debug calls for "language" and "statIds" produce the following:
language
en_US
statIds
{kA1a0000000d58kCAA, kA1a0000000d58lCAA}
The exact value of "language" has no single quotes in it, does that matter?
The "ParentId" of the KnowledgeArticleViewStat should be a knowledgeArticleId, right?
Then I attempt:
And get the compile error.
Aren't the "statIds" already KnowledgeArticleIds?
Yes, but when youquery on KAV then need to filter by ID. SO, append id = some id value or id IN: set of ids
To get the statIds:
To get the KAV Ids:
Up to here everything is good. I have two full sets - statIds, and kavIds.
To attempt to get the Article Ids themselves:
Here is the error I receive:
Error: Compile Error: Implementation restriction: When querying the KnowledgeArticleVersion object, you must filter using the following syntax: Id = [single ID], Id IN [list of ID's] or Language = [language ISO code]. In addition Language is only permitted in a top-level AND condition. at line 51 column 80
As far as I can tell I have included all necessary requirements - I have the language in there, and I now have included the "Id" of a set of KnowledgeArticleVersions.
What am I still missing?
However, I know it is a horrible practice to place a DB query in a for loop, so I am trying to find a way to remove it.
Does that make finding a solution easier?