1

I have created a Visualforce global publisher action with the intent to add it to the Chatter actions menu for several objects in the organization. The action should be able to post a message directly to the feed of whatever Chatter feed it is added to. This is pretty easy, provided that I have the current record Id. However, I don't see how to generically get the current record Id from within the context of the Visualforce page.

I know that this is possible if I create a separate Visualforce page for every single object that I wish to use the action for and then create an object specific publisher action for each one. But what a lot of clutter for something so simple!

Is there any way to get the current record Id from within a global Visualforce publisher action? Hacks are welcome!

  • Hi Jason, I've got the same question. Did you ever find an answer? Thanks – DaveS Aug 20 '15 at 8:55
  • No, I didn't... :( – Jason Hartfield Aug 21 '15 at 12:49
1

With New Lightning Url, you can simply get it within your VFPage as

{!$CurrentPage.parameters.id}
| improve this answer | |
1

I had to do the exact same thing. I used javascript on the page to deliver the raw URL and then extracted the ID within the controller. Note that we are only including the Quick Action on Object pages, not anywhere where there is no objectId. I imagine you could enhance my code to come up with the user id or group id for pages where there is no SObject id in the URL. Also, if you are working with communities, you'll have to parse out the extra community prefix part of the URL.

<script>
    var j$ = jQuery.noConflict();
    //on Document ready
    j$(document).ready(function(){
        j$('[Id*="theUrl"]').val(topUrl);
    });
 </script>
 <apex:form >
    <apex:inputHidden value="{!url}" id="theUrl"/>
 </apex:form>

Then I parsed the URL in my class with:

...

FeedItem fItem = new FeedItem();
fItem.parentId = getSObjectId(this.url);

....

public String getSObjectId(String rawUrl) {
    String urlNoDomain = awUrl.substringAfter('://').substringAfter('/');
    return urlNoDomain.substringBefore('/');
}
| improve this answer | |

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.