4

Hi I'm creating a Visualforce intented for mobile devices, and I would like to know if it is possible to use the javascript canvas api to post to Chatter.

I've seen one example in here (https://github.com/forcedotcom/Delivery-Tracker-Java-App/blob/master/src/main/webapp/scripts/shipment.js), but I can't make it work inside my Visualforce .

Does anyone know how to do this?

Update: I would like to know a solution that works inside a PE org.

4
+50

Given the limitations of Professional Edition (no Apex Classes or Salesforce API) I can think of a few:

1. Remote Objects (coming in Spring '14)

Remoting without the need for Apex Code: Andy Fawcett has a great introduction to Remote Objects.

<apex:page>
  <apex:remoteObjects>
    <apex:remoteObjectModel name="FeedItem__c" jsShorthand="Post" fields="Body, ParentId">
      <apex:remoteObjectField name="Body" jsShorthand="body"/>
    </apex:remoteObjectModel>
  </apex:remoteObjects>
  <script>

    //create the record
    var post = new SObjectModel.Post({
      Body = 'Herp derp chatter post here!',
      ParentId = '{!$User.Id}'
    });

    //go postal
    post.create();

  </script>
</apex:page>

2. Use SFORCE javascript tool after installing some API-enabled app

The sforce 'AJAX toolkit' may be suitable if you can get API access enabled for the PE organization.

<apex:page>
  <apex:includeScript value="/soap/ajax/29.0/connection.js" />
  <script>

    //create the record
    var post = new sforce.SObject('FeedItem');
    post.Body = 'Herp derp chatter post here!';
    post.ParentId = '{!$User.Id}';

    //go postal
    sforce.connection.create([post]);

  </script>
</apex:page>
| improve this answer | |
  • 1
    Great answer, you pointed me in the right direction, although I ended up using the backbone mobile pack (github.com/developerforce/MobilePack-BackboneJS) – jucas Mar 17 '14 at 21:53
  • VF remote objects are only available in developer preview in Spring 14. It's an exciting feature, but not yet production ready. – pchittum Mar 19 '14 at 22:22
3

Posting to Chatter from a VF page and Javascript seems would be easiest by using an Apex controller being called via Javascript remoting methods. JS remoting basically surfaces a JS api in VF that allows you to invoke static Apex methods.

Because these methods are statically declared in your controller, your mobile app will incur no view state overhead from using them.

Inside the remoting call, you would then probably either want to use the ConnectApi namespace classes in Apex, or, if we're talking very simple text posts with no @mentions, you could simply construct the sObject in memory and commit it with a save.

Examples of remoting methods and invoking them from JS in your Visualforce page are found in the Visualforce code developer guide. The Chatter ConnectApi classes are documented in the Apex code developer guide.

Be forewarned that ConnectApi classes follow some slightly different rules with regards to "without sharing" declarations, and have different governor limits than traditional limits on queries and DML.

If Apex is not an option, you could use the AJAX toolkit. This is an older way to get Visualforce to talk to an org, but could work. But it is well documented with lots of examples in the world. But this would only happen in a Professional Edition org where API had been enabled.

| improve this answer | |
  • Does this work in Professional edition? – jucas Mar 14 '14 at 12:29
  • 1
    Is this a PE org? It might be worthwhile to amend the question to say so. – pchittum Mar 14 '14 at 23:11
  • yes it is, I've updated the question to reflect that – jucas Mar 17 '14 at 16:06

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.