Pregunta

When I execute this code in the developer console

PushTopic pushTopic = new PushTopic();
pushTopic.ApiVersion = 23.0;
pushTopic.Name = 'Test';
pushTopic.Description = 'test';
pushtopic.Query = 'SELECT Id, Account.Name FROM Case';
insert pushTopic;
System.debug('Created new PushTopic: '+ pushTopic.Id);

I receive this message:

FATAL ERROR System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD, relationships are not supported: [QUERY]

The same query runs fine on the Query Editor, but when I assign it to a Push Topic I get the INVALID_FIELD exception.

If the bottom line is what the exception message says, that relationships are just not supported by Push Topic objects, how do I create a Push Topic object that will return the data I'm looking for?

¿Fue útil?

Solución

Why

Salesforce prevents this because it will require them to join tables, joins in salesforces database are expensive due to the multi-tenancy. Usually when they add a new feature they will not support joins as it requires more optimization of the feature.

Push Topics are still quite new to the system and need to be real time, anything that would slow them down I'd say needs to be trimmed.

I'd suggest you look more closely at your requirement and see if there is something else that will work for you.

Workaround

A potential workaround is to add a Formula field to the Case object with the data you need and include that in the query instead. This may not work as it will still require a join to work.

A final option may be to use a workflow rule or trigger to update the account name to a custom field on the Case object this way the data is local so doesn't require a join...

Otros consejos

PushTopics support a very small subset of SOQL queries, see more here: https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/unsupported_soql_statements.htm

However this should work:

PushTopic casePushTopic = new PushTopic();
pushTopic.ApiVersion = 23.0;
pushTopic.Name = 'CaseTopic';
pushTopic.Description = 'test';
pushtopic.Query = 'SELECT Id, Account.Id FROM Case';
insert pushTopic;

PushTopic accountPushTopic = new PushTopic();
pushTopic.ApiVersion = 23.0;
pushTopic.Name = 'AccountTopic';
pushTopic.Description = 'test';
pushtopic.Query = 'SELECT Id, Name FROM Account';
insert pushTopic;

It really depends on your use case though, if it is for replicating into RDBMS this should be enough, you can use a join to get the full data.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top