I've a VF page which have readOnly='true'
attribute and I am trying to implement a button that when clicked will make a chatter post with some Blob content as element attachment using ConnectApi namespace classes in Apex.
I'm receiving this error:
Too many DML statements: 1
My code looks something like this:
<apex:page readOnly="true" controller="MyTestPageController">
This is a test page.<br />
Post Content of some Visualforce Page as content into a Chatter Feed.<br />
<br />
<apex:commandButton value=" Post Content to Chatter " action="{!postToChatter}" />
</apex:>
The Code Apex class looks like this:
public with sharing class MyTestPageController {
public MyTestPageController() { }
public void postToChatter() {
PageReference p = Page.MyTestVFPage;
ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
feedItemInput.subjectId = 'me';
ConnectApi.ContentCapabilityInput contentInput = new ConnectApi.ContentCapabilityInput();
contentInput.title = 'My File';
ConnectApi.FeedElementCapabilitiesInput capabilities = new ConnectApi.FeedElementCapabilitiesInput();
capabilities.content = contentInput;
feedItemInput.capabilities = capabilities;
Blob myBlob = p.getContent();
ConnectApi.BinaryInput binInput = new ConnectApi.BinaryInput(myBlob, 'application/x-excel', 'Data_File_'+Datetime.now().getTime());
ConnectApi.ChatterFeeds.postFeedElement(null, feedItemInput, binInput);
}
}
Can anyone suggest if I can make ConnectApi do chatter post without me having to remove readOnly="true" VF Page attribute?
readOnly=true
and this is something that I need in my app. – VarunC Nov 30 '15 at 17:09