+ Start a Discussion
Joaquin IudicaJoaquin Iudica 

pushtopic subscription in visualforce: does filtered subscription work?

I'm testing filtered subscriptions to pushtopics with a test visualforce page. This is the code:

public with sharing class PruebaPushTopicFiltradoController {

    public List<mlsales__Etiqueta_Zebra__c> etiquetas{get;set;}

    public PruebaPushTopicFiltradoController() {
        etiquetas = [SELECT Id, Documento_Id__c, Name, Identificacion_Impresora__c FROM Etiqueta_Zebra__c  ORDER BY Name LIMIT 5];

Visualforce page:
<apex:page standardStylesheets="false" controller="PruebaPushTopicFiltradoController" showHeader="TRUE" sidebar="false">
    <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
    <div class="container">
        <table id="oppTable" class="table table-hover table-bordered table-striped">
                        Documento Id
                        Identificacion Impresora
                <apex:repeat value="{!etiquetas}" var="etiqueta"> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>    
    <script src="{!URLFOR($Resource.jsUtilities, '/js/json2.js')}"></script>
    <script src="{!URLFOR($Resource.jsUtilities, '/js/cometd.js')}"></script>
    <script src="{!URLFOR($Resource.jsUtilities, '/js/jquery.cometd.js')}"></script>
      // initizlizing Streaming API
      (function($) {
        $(document).ready(function() { 
          //Initializing cometd library to cometd endpoint
            url: window.location.protocol + '//' + window.location.hostname + '/cometd/33.0/',
            requestHeaders: {
              Authorization: 'OAuth {!$Api.Session_ID}'
            appendMessageTypeToURL : false

          // Subscribing to the push topic. 
          //JSON-encoded data will be returned in the callback each time whenever opportunity is created
          $.cometd.subscribe("/topic/getZebraToPrint?mlsales__Identificacion_Impresora__c='test'", function(message) {
            if (message.data.event.type == 'created') {
                console.log('created object ===> ' + message.data.sobject);
                var etiqueta = message.data.sobject; 
              $("#oppTable > tbody").append('<tr class="success"><td>'+etiqueta.mlsales__Documento_Id__c+'</td><td>'+etiqueta.Name+'</td><td>'+etiqueta.mlsales__Identificacion_Impresora__c+'</td></tr>');

The string I'm passing as parameter for the subscribe method contains the filtering I need. the subscription works correctly, but doesn't filter, it gets all objects created despite whats the value of that field. Is the problem in the structure of the string, or doesn't it work this way? I can't find specific documentation for this. Any help is appreciated!
GreyGorilla VaporGreyGorilla Vapor
Truly, this article is really one of the very best in the history of articles. I am an antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work!

Caliburn AK2