1

I am trying to create a feed item programmatically and got the following error. Actually the code is inside a webservice and the webservice would be called from SAP system. For that i created a unuathenticated website and expose this webservice. Any suggestions please.

Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Entity is read-only: FeedItem: []

global without sharing class  SOBlockWebService{
    //webService static List<SOBlockResponseDTO> getSOBlock(List<SOBlockRequestDTO> SOBlock)  
    webService static List<SOBlockResponseDTO> getSOBlock()
    {  
            List<SOBlockResponseDTO> lstSOBlockDTO = new List<SOBlockResponseDTO> {};
            SOBlockResponseDTO so = new SOBlockResponseDTO('apptype','testname','docdate', 'doctime','time','ctx1','ctx2','ctx3','ctx4','ctx5','ctx6','msg','success');


            //Adding a Text post
            FeedItem txtpost = new FeedItem();
            txtpost.ParentId = Userinfo.getUserId(); //eg. Opportunity id, custom object id..
            txtpost.Body = 'Enter post text here';
            insert txtpost;

            //Adding a Link post
            FeedItem lnkpost = new FeedItem();
            lnkpost.ParentId = Userinfo.getUserId(); //eg. Opportunity id, custom object id..
            lnkpost.Body = 'Enter post text here';
            lnkpost.LinkUrl = 'http://www.someurl.com';
            insert lnkpost;


            lstSOBlockDTO.add(so); 
            //System.debug('>>>>>>>>>>>>>>>>>> SOBlock'+SOBlock);
            return lstSOBlockDTO;  
    }  

    global class SOBlockRequestDTO {
        webservice String ApplicationType {get;set;}
        webservice String CustomerNumber {get;set;}
        webservice String DocDate {get;set;}
        webservice String DocTime {get;set;}
        webservice String Timestamp {get;set;}
        webservice String Message {get;set;}
        webservice String Context1 {get;set;}
        webservice String Context2 {get;set;}
        webservice String Context3 {get;set;}
        webservice String Context4 {get;set;}
        webservice String Context5 {get;set;}
        webservice String Context6 {get;set;}
        webservice String Status {get;set;}

        public SOBlockRequestDTO(String ApplicationType,String CustomerNumber, String DocDate, String DocTime, String Timestamp, String Message, String Context1, String Context2, String Context3, String Context4, String Context5, String Context6, String Status) {
            this.ApplicationType = ApplicationType;
            this.CustomerNumber = CustomerNumber;
            this.DocDate = DocDate;
            this.DocTime = DocTime;
            this.Timestamp = Timestamp;
            this.Message = Message;
            this.Context1 = Context1;
            this.Context2 = Context2;
            this.Context3 = Context3;
            this.Context4 = Context4;
            this.Context5 = Context5;
            this.Context6 = Context6;
            this.Status = Status;
        }
    }


    global class SOBlockResponseDTO {
        webservice String ApplicationType {get;set;}
        webservice String CustomerNumber {get;set;}
        webservice String DocDate {get;set;}
        webservice String DocTime {get;set;}
        webservice String Timestamp {get;set;}
        webservice String Message {get;set;}
        webservice String Context1 {get;set;}
        webservice String Context2 {get;set;}
        webservice String Context3 {get;set;}
        webservice String Context4 {get;set;}
        webservice String Context5 {get;set;}
        webservice String Context6 {get;set;}
        webservice String Status {get;set;}

        public SOBlockResponseDTO(String ApplicationType,String CustomerNumber, String DocDate, String DocTime, String Timestamp, String Message, String Context1, String Context2, String Context3, String Context4, String Context5, String Context6, String Status) {
            this.ApplicationType = ApplicationType;
            this.CustomerNumber = CustomerNumber;
            this.DocDate = DocDate;
            this.DocTime = DocTime;
            this.Timestamp = Timestamp;
            this.Message = Message;
            this.Context1 = Context1;
            this.Context2 = Context2;
            this.Context3 = Context3;
            this.Context4 = Context4;
            this.Context5 = Context5;
            this.Context6 = Context6;
            this.Status = Status;
        }
    }

}

1 Answer 1

1

The issue is because you have gone unauthenticated .Unauthenticated users will not have write access to the feeditem object .

Try using a proxy user by authenticating with a user created specifically for this purpose .

2
  • Thanks @Mohith. If i understand correctly, did you mean proxy user is the integration user? Salesforce provides tool kit for some of the platform like java, .net and php. I think SAP does not have a sfdc tool kit to utilize sfdc API. If that is the case, shall i use REST based authentication for the proxy user to authenticate and access the feed item?
    – Bforce
    Commented Aug 11, 2014 at 12:56
  • Yes use a REST based oauth useragent password flow and then use that to do this callout Commented Aug 11, 2014 at 13:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .