Is it possible to restrict rights to delete of Pushtopic that is created in managed package?
Attribution to: Natallia
Possible Suggestion/Solution #1
Following on from what @bigassforce said.. I think you want to do a query on the PushTopic records first to check and see if your "unique" PushTopic Name returns an Id in the query and assigning that to an Id variable and using that; so if the PushTopic is not present, it will create one and if it is present then it will update it if there are any changes.
public class PushTopicLifecycleManager {
public void doUpsert() {
Id pushTopicId;
try{
pushTopicId = [SELECT Id FROM PushTopic WHERE Name = : 'yourTopicName'].Id;
System.debug('A PushTopic was found with that Name. It will now be updated.');
} catch(Exception e){
System.debug('No PushTopics were found with that Name. One will now be created.');
}
PushTopic pushTopic = new PushTopic(
Id = pushTopicId,
Name = 'yourTopicName',
Query = 'SELECT Id, Field__c FROM Object__c',
ApiVersion = 33.0
);
upsert pushTopic;
}
}
Attribution to: Tim
Possible Suggestion/Solution #2
Do I guess right that you are managing the life cycle of the PushTopic
using a PostInstallScript
and an UninstallScript
to insert/delete it when the package is installed?
In this case, I'm not sure you can prevent consumers of your package from destroying the PushTopic
records themselves. But what you can do is upsert it before rendering the pages that consume it.
<apex:page controller="PushTopicLifecycleManager" action="{!doUpsert}">
<script>
//streaming api bayeux client doing something here
</script>
</apex:page>
using a controller like so:
public class PushTopicLifecycleManager {
public void doUpsert() {
PushTopic pushTopic = new PushTopic(
Name = 'yourTopicName',
Query = 'SELECT Id, Field__c FROM Object__c',
ApiVersion = 29.0
);
upsert pushTopic Name;
}
}
This reinitializes the PushTopic before the client connects, assuming the client is a Visualforce Page.
Attribution to: bigassforce
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30306