You need to sign in to do that
Don't have an account?
ShaikA
How to insert FeedItem when code is executing in a Force.com Site?
Hi All,
Please let me know, how to insert feeditem for site user
Vf page publish in sites:
<apex:page controller="fileUploadController">
<apex:messages />
<apex:form id="frm">
<apex:pageblock >
<apex:pageblocksection columns="1">
<apex:inputFile value="{!file}" filename="{!conVers.title}"/>
<apex:commandbutton action="{!upload}" value="Upload" />
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
Class:
public with sharing class fileUploadController{
public blob file { get; set; }
public ID accid{get;set;}
public ContentVersion conVers{get;set;}
public fileUploadController(){
accid=ApexPages.currentPage().getParameters().get('id');
conVers= new ContentVersion();
}
public PageReference upload(){
conVers.versionData = file;
conVers.pathOnClient ='/'+conVers.Title;
try
{
insert conVers;
FeedItem elm = new FeedItem(Body = 'Post with related document body', ParentId = accid, RelatedRecordId =conVers.Id, Type = 'ContentPost');
insert elm;
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading File'));
return null;
}
finally
{
conVers= new ContentVersion();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
return null;
}
}
getting error like:
DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Entity is read-only: FeedItem: []
Thanks in Advance
Shaik
Please let me know, how to insert feeditem for site user
Vf page publish in sites:
<apex:page controller="fileUploadController">
<apex:messages />
<apex:form id="frm">
<apex:pageblock >
<apex:pageblocksection columns="1">
<apex:inputFile value="{!file}" filename="{!conVers.title}"/>
<apex:commandbutton action="{!upload}" value="Upload" />
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
Class:
public with sharing class fileUploadController{
public blob file { get; set; }
public ID accid{get;set;}
public ContentVersion conVers{get;set;}
public fileUploadController(){
accid=ApexPages.currentPage().getParameters().get('id');
conVers= new ContentVersion();
}
public PageReference upload(){
conVers.versionData = file;
conVers.pathOnClient ='/'+conVers.Title;
try
{
insert conVers;
FeedItem elm = new FeedItem(Body = 'Post with related document body', ParentId = accid, RelatedRecordId =conVers.Id, Type = 'ContentPost');
insert elm;
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading File'));
return null;
}
finally
{
conVers= new ContentVersion();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
return null;
}
}
getting error like:
DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Entity is read-only: FeedItem: []
Thanks in Advance
Shaik
Please check with below link with similar issue.
- http://salesforce.stackexchange.com/questions/36605/how-to-guard-a-feeditem-insert-when-code-is-executing-in-a-force-com-site
Hope this helps.Regards,
Nagendra.