2

Problem description:

The following SOQL query:

[SELECT Id, ParentId, NormalizedScore, Channel 
 FROM FAQ__VoteStat
 WHERE ParentId IN : knowledgeArticleIDs AND Channel =: channelName
 ORDER BY NormalizedScore desc
 LIMIT 5];

Returning results in unexpected way, for example: If I have 3 articles with the following NormalizedScore:

Article 1: 0
Article 2: 0
Article 3: 3

I received the result order as follow:

Article 1: 0
Article 2: 0
Article 3: 3

When I was expecting to receive the following order:

Article 3: 3
Article 1: 0
Article 2: 0

Solution help needed:

I don't understand why the Order By Desc not working, it's seems weird. I know I can sort the articles manually from code, but that seems redundant, maybe there is something I missed regarding the NormalizedScore field, which can explain why the order by is not working properly.

Thank in advanced!

2
  • Does this go wrong for values other than zero? I wonder if the underlying values are null as nulls sort first by default.
    – Keith C
    Commented Oct 25, 2014 at 10:45
  • I already tried 'nulls last', it's still got the same result. I also tried with another article with score of 3.9, and he does goes first, but then I still got zeros in the middle and the last article with score 3, I was trying few other variants and still got weird ordering results (not in descending order!).
    – GoldenAxe
    Commented Oct 25, 2014 at 10:47

2 Answers 2

2

After much reading and searching, I have found that this is the standard behavior:

NormalizedScore - Description: "Article's weighted score on a scale of 1 to 5. A higher score means more votes. Articles without recent votes trend towards an average rating of three stars."

So that means (and I checked it) that if an article is never voted, it will have a score of zero, but Salesforce will look at it as score of 3 (stars). So if you have articles with the following scores:

  • a1: 2
  • a2: 0
  • a3: 5
  • a4: 0

the order will be:

  • a3: 5
  • a2: 0
  • a4: 0
  • a1: 2
0

This sounds like a relative of a known issue referenced below. Looks like sorting in code it is.

https://success.salesforce.com/issues_view?id=a1p30000000SU4fAAG

1
  • I don't think it's an issue, this is probably the solution they had for the Cold Start problem.
    – GoldenAxe
    Commented May 31, 2018 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .