Quantcast
Channel: Salesforce Online Training
Viewing all articles
Browse latest Browse all 84

Does Composite API Support Chatter Posts?

$
0
0

Question

Is there an official documentation which shows what list of rest api does composite api supports?

I tried this composite api request body.

POST_URL : {{_endpoint}}/services/data/v59.0/composite

{
    "allOrNone": true,
    "compositeRequest": [
        {
            "method": "PATCH",
            "url": "/services/data/v59.0/sobjects/Case/500al00000Ht0vH",
            "referenceId": "caseUpdate",
            "body": {
                "Status": "Working"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v59.0/chatter/feed-elements",
            "referenceId": "newFeedElement",
            "body": {
                "body": {
                    "messageSegments": [
                        {
                            "type": "Text",
                            "text": "When should we meet for planning?"
                        }
                    ]
                },
                "feedElementType": "FeedItem",
                "subjectId": "500al00000Ht0vH" // Your valid Case ID
            }
        }
    ]
}

But seems like /services/data/v59.0/chatter/feed-elements is not supported via composite apis.

I get in response.

{
    "compositeResponse": [
        {
            "body": [
                {
                    "errorCode": "PROCESSING_HALTED",
                    "message": "The transaction was rolled back since another operation in the same transaction failed."
                }
            ],
            "httpHeaders": {},
            "httpStatusCode": 400,
            "referenceId": "caseUpdate"
        },
        {
            "body": [
                {
                    "errorCode": "NOT_FOUND",
                    "message": "The requested resource does not exist"
                }
            ],
            "httpHeaders": {},
            "httpStatusCode": 404,
            "referenceId": "newFeedElement"
        }
    ]
}   

If I try to fire {{_endpoint}}/services/data/v59.0/chatter/feed-elements separately, it works fine and adds chatter posts on case.

Answer

The Composite API in Salesforce allows multiple API requests in a single HTTP request but supports only specific resources. These include all sObject resources, the Query and QueryAll resources, and the sObject Collections resource. The /services/data/vXX.X/chatter/feed-elements endpoint for Chatter posts is not supported within Composite API requests, even though it works as a standalone request. Below is an example illustrating this limitation, followed by explanations of the code snippets.

Composite API Request Example:

POST {{_endpoint}}/services/data/v59.0/composite
{
    "allOrNone": true,
    "compositeRequest": [
        {
            "method": "PATCH",
            "url": "/services/data/v59.0/sobjects/Case/500al00000Ht0vH",
            "referenceId": "caseUpdate",
            "body": {
                "Status": "Working"
            }
        },
        {
            "method": "POST",
            "url": "/services/data/v59.0/chatter/feed-elements",
            "referenceId": "newFeedElement",
            "body": {
                "body": {
                    "messageSegments": [
                        {
                            "type": "Text",
                            "text": "When should we meet for planning?"
                        }
                    ]
                },
                "feedElementType": "FeedItem",
                "subjectId": "500al00000Ht0vH"
            }
        }
    ]
}

Code Explanation:
The request sets allOrNone to true to ensure that either all operations succeed or none are committed. The first composite request updates the status of a specific Case record using the PATCH method. The second composite request attempts to post a Chatter feed element to the Case using the /chatter/feed-elements endpoint. However, this fails because the Composite API does not support Chatter resources.

Composite API Response:

{
    "compositeResponse": [
        {
            "body": [
                {
                    "errorCode": "PROCESSING_HALTED",
                    "message": "The transaction was rolled back since another operation in the same transaction failed."
                }
            ],
            "httpHeaders": {},
            "httpStatusCode": 400,
            "referenceId": "caseUpdate"
        },
        {
            "body": [
                {
                    "errorCode": "NOT_FOUND",
                    "message": "The requested resource does not exist"
                }
            ],
            "httpHeaders": {},
            "httpStatusCode": 404,
            "referenceId": "newFeedElement"
        }
    ]
}

Code Explanation:
The PROCESSING_HALTED error occurs because one operation in the transaction failed, causing the rollback of all changes. The first request (caseUpdate) succeeds, but the second request (newFeedElement) results in a 404 NOT_FOUND error. This indicates that the Composite API does not recognize the /chatter/feed-elements resource. While the Chatter endpoint works as a standalone call, it cannot be processed within a composite request.

Summing up

The Composite API in Salesforce supports specific REST API resources, such as sObject operations, Query, QueryAll, and sObject Collections. However, Chatter API endpoints like /services/data/vXX.X/chatter/feed-elements are not supported in composite requests. While these endpoints function as standalone API calls, attempting to include them in a Composite API request results in errors, such as NOT_FOUND. This limitation is confirmed by Salesforce’s official documentation, which specifies the resources supported by the Composite API.

Job-Oriented Salesforce Course: Enroll for Free Demo

Our Salesforce Course offers an in-depth dive into the Salesforce platform, arming you with the essential skills to thrive in the competitive CRM industry. The program covers key areas like Salesforce Admin, Developer, and AI, blending theoretical knowledge with hands-on practical experience. Participate in live projects and assignments to gain real-world expertise and confidently address business challenges using Salesforce solutions. Our experienced trainers ensure you acquire the technical know-how and industry insight necessary to excel in the Salesforce ecosystem.

Beyond technical skills, our Salesforce training in Bangalore provides personalized mentorship, certification exam preparation, and interview coaching to help you stand out in the job market. You will have access to a wealth of study resources, real-world project exposure, and continuous support throughout your learning journey. Upon completion, you’ll be fully prepared for certification exams and equipped with the problem-solving abilities employers seek. Begin your Salesforce journey with us and unlock a world of career opportunities!

The post Does Composite API Support Chatter Posts? appeared first on Salesforce Online Training.


Viewing all articles
Browse latest Browse all 84

Trending Articles