1

I am trying to use jsforce to post a message to the chatter section of a salesforce opportunity. I pieced the following together from watching how salesforce.com works, but it doesn't do what I want it to do. I am guessing on some of this. recordId is the opportunity number as pulled from the salesforce URL. I am using similar code to create tasks and upload files to an opportunity and that works fine. Does anyone have any ideas as to how to approach this? Thanks!

    conn.sobject('/feed-elements').create({
        feedElementType: "FeedItem",
        feedItemInput: {
            subjectId: recordId,
            body: {
                messageSegments: [
                    {
                        "type":"MarkupBegin",
                        "markupType":"Paragraph"
                    },
                    {
                        type: 'Text',
                        text: 'This is new comment #1'
                    },
                    {
                        "type":"MarkupEnd",
                        "markupType":"Paragraph"
                    }
                ]
            }
        }
    });

1 Answer 1

2

conn.sobject is for SOQL and DML using REST APIs.

Try using the chatter REST APIs as documented in jsforce docs

conn.chatter.resource('/feed-elements').create({
 body: {
      messageSegments: [
                {
                    "type":"MarkupBegin",
                    "markupType":"Paragraph"
                },
                {
                    type: 'Text',
                    text: 'This is new comment #1'
                },
                {
                    "type":"MarkupEnd",
                    "markupType":"Paragraph"
                }
            ]
  },
 feedElementType : 'FeedItem',
 subjectId: recordId
}, function(err, result) {
   if (err) { return console.error(err); }
     console.log("Id: " + result.id);
     console.log("URL: " + result.url);
     console.log("Body: " + result.body.messageSegments[0].text);
     console.log("Comments URL: " + 
     result.capabilities.comments.page.currentPageUrl);
 });
2
  • Thank you! I saw that, but for some reason I thought I had to go a different direction. Silly me. It works now, though! Much appreciated. Dec 17, 2021 at 21:51
  • @Andrew Please mark the answer as answered so it helps community Dec 17, 2021 at 22:12

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.