[SalesForce] How to post to Chatter from Visualforce using Javascript

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.

Best Answer

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>
Related Topic