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
Mikhail Nitko 5Mikhail Nitko 5 

PushTopic query creation issue

Hi folks,

I'm trying to create the following PushTopic
 
PushTopic pt = new PushTopic();

pt.Name = 'CaseNotifications';

pt.Query ='SELECT Display_Name__c,Display_Screen_Suffix__c FROM Case WHERE Origin = 'Walk-in' AND Status != 'Closed' AND Remove_From_Screen__c = False ORDER BY CreatedDate ASC NULLS FIRST LIMIT 10';

pt.ApiVersion = 40.0;

pt.NotifyForFields = 'Referenced';

pt.NotifyForOperationCreate = true;

pt.NotifyForOperationUpdate = true;

pt.NotifyForOperationUndelete = true;

pt.NotifyForOperationDelete = true;

insert pt;

And receiving an error that states: "Line: 5, Column: 85 expecting a semi-colon, found 'Walk'"

And I am trying to figure out whats going on, but I know for a fact that the query is formed right, because I use that query in a class and formed it via Workbench.

What is going on?
Best Answer chosen by Mikhail Nitko 5
Vivin MathewVivin Mathew
Hi Mikhail.
Np.
Can you include the column Id as well in your SOQL query? 
pt.Query ='SELECT Id, Display_Name__c,Display_Screen_Suffix__c FROM Case WHERE Origin = \'Walk-in\' AND Status != \'Closed\' AND Remove_From_Screen__c = False ORDER BY CreatedDate ASC NULLS FIRST LIMIT 10';

Vivin

All Answers

Vivin MathewVivin Mathew
Hi Mikhail
Can you try using this query. Can you replace line 05 with this one and try
 
​pt.Query ='SELECT Display_Name__c,Display_Screen_Suffix__c FROM Case WHERE Origin = \'Walk-in\' AND Status != \'Closed\' AND Remove_From_Screen__c = False ORDER BY CreatedDate ASC NULLS FIRST LIMIT 10';

 
Mikhail Nitko 5Mikhail Nitko 5
Hi Vivin,

Sorry it took so long to reply.

When I use that line I get the message: "Error: Line: 19, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD, 'Id' field must be selected: [Query]"
Vivin MathewVivin Mathew
Hi Mikhail.
Np.
Can you include the column Id as well in your SOQL query? 
pt.Query ='SELECT Id, Display_Name__c,Display_Screen_Suffix__c FROM Case WHERE Origin = \'Walk-in\' AND Status != \'Closed\' AND Remove_From_Screen__c = False ORDER BY CreatedDate ASC NULLS FIRST LIMIT 10';

Vivin
This was selected as the best answer
Mikhail Nitko 5Mikhail Nitko 5
Thank you Vivin, that got me past that issue.  

The error I get now is "Line: 19, Column: 1
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD, 'LIMIT' is not allowed: [Query]"

Does this mean that I won't be able to limit the results this way? .. perhaps its by design?
Vivin MathewVivin Mathew
Hi Mikhail
Yes .. Please refer to this link for unsupported PushTopic queries.
https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/unsupported_soql_statements.htm