0

Count query on SuccessFactors entity doesn't work as it requires $top to be greater than 0 but count() method of FluentHelperCount is overriding $top with 0. Hence the SuccessFactors rejecting the call with 400 error.

enter image description here

Here is my code (throws exception):

long count = new UserFluentHelper(QueryUtils.getSFServicePath()).top(1).select(User.USER_ID).count()
            .execute(QueryUtils.getSFDestination());

Executed query using Postman with URL generated by count() method

enter image description here

Please point me out if I am doing something wrong when constructing query.

Thanks

Gippy Aulakh
  • 104
  • 7
  • Can you elaborate why your code example uses count and selectin the same query? Count returns you a number, so what is the semantics of selecting a particular entity field? – Emdee Jul 17 '20 at 08:07

2 Answers2

1

At first, can you elaborate on the semantics of your OData query? You use $select and $count together. Referring to the OData spec on $count it returns a plain number. I do not understand what your intention to select an entity field is based on.

Under the assumption that you only want to count entities, neglecting the additional $select in your shown query, here is an alternative code snippet available in the SAP Cloud SDK. Note that this API is experimental.

final HttpDestination httpDestination = DestinationAccessor.getDestination("my-destination").asHttp();

final ODataRequestCount requestCount = new ODataRequestCount("/odata/v2", "User, "", ODataProtocol.V2);

final ODataRequestResultGeneric result =
            requestCount.execute(HttpClientAccessor.getHttpClient(httpDestination));

final Long count = result.as(Long.class);

I'll update this answer if the FluentHelperCount is improved.

Emdee
  • 1,689
  • 5
  • 22
  • 35
  • Thanks Emdee for your answer. My intention to select only one field was to make query response lightweight. FluentHelper count construct query with $inlinecount=allpages which mean in response it will fetch all the fields of User entity and count comes as a separate field "__count" in addition to actual response. – Gippy Aulakh Jul 18 '20 at 11:46
  • Understood. Then, with my provided code snippet you do not need this additional projection as it uses `$count` directly. – Emdee Jul 20 '20 at 06:25
1

Update: As of Cloud SDK 3.29.1 querying the $count endpoint is supported.

You can change your code to use:

long count = new UserFluentHelper(QueryUtils.getSFServicePath())
            .count()
            .executeRequest(QueryUtils.getSFDestination());

The executeRequest method will query the $count endpoint. By contrast the now deprecated execute method will still perform the inline count.

For details check out the release notes.

MatKuhr
  • 505
  • 4
  • 13