3

I was just trying to get heads-up on Streaming API. Following is the link which provides a basic example for Streaming API. I'm using the same code, besides that i was trying to add one functionality i.e. redirecting users to detail page. Once i get the ID from the streaming API i want to provide a link to detail page. I tried but unable to crack it. I'm not a pro in jquery, javascript. Any suggestions will be helpful.

This is block of code

<script type="text/javascript">
(function($)
{
        $(document).ready(function() {
        // Connect to the CometD endpoint
        $.cometd.init({
            url: window.location.protocol+'//'+window.location.hostname+'/comet/24.0/',
                requestHeaders: { Authorization: 'OAuth {!$Api.Session_ID}'}
        });
        // Subscribe to a topic. JSON-encoded update will be returned
        // in the callback
        $.cometd.subscribe('/topic/EmailUpdates', function(message) {
        var $recordId = JSON.stringify(message.data.sobject.Id);
        alert('1' + message.data.sobject.URL__c);
        $('#content').append('<p><a href="javascript:void(0);return false;" onclick="redirectURL(JSON.stringify(message.data.sobject.Id));return false;">'+JSON.stringify(message.data.sobject.Subject__c) + '</a></p>');
       });
       });
       })(jQuery)

       // Tried with writing a function and calling this on click of a tag or  apex:outputLink
       function redirectURL(link)
       {
          alert('hi');
       }

1

An sObject detail page will have a URL with the format:

https://instance.salesforce.com/recordId

E.g. A lead detail page on the na5 server.

https://na5.salesforce.com/00Q700000000H50

So you will want something like the following in your JavaScript to redirect to the detail page.

window.location.href = '/' + JSON.stringify(message.data.sobject.Id);
| improve this answer | |
  • Thanks for the reply...Actually i tried this too before i didn't work....if i tried to add this on <a> tag href then it wont work...I tried using apex:outputLink and then called a Js function onClick of but somehow its not working saw "FireBug" also no clues. – Dev May 28 '13 at 4:11
  • 1
    Got a workaround for this...Created a formula field URL__c with HYPERLINK('../../../' & Id , Subject__c , '_new')....And in page instead of $('#content').append('<p><a href="javascript:void(0);return false;" onclick="redirectURL(JSON.stringify(message.data.sobject.Id));return false;">'+JSON.stringify(message.data.sobject.Subject__c) + '</a></p>'); used this $('#content').append('<p>' + message.data.sobject.URL__c + '</p>'); – Dev May 28 '13 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.