I've set up a chat for my Salesforce Org and I want to change the chat capacity through code. From the Salesforce documentation (see documentation) it is possible to update the PresenceUserConfig. I want to update the capacity and have tried doing so with regular Apex code updating the object. This leads to DML operation errors on the object.

It seems that I only can update the objects with the SOAP API. Can anyone confirm if this is the correct way to do it? I want to update the object through Apex code so I can keep my code dynamic. I've looked into doing so with WSDL files. But I only get errors when importing it to Apex classes. If someone could guide me in the correct direction as I've been hitting the wall with this issue for over 3 days now.

1 Answer 1


You can do this with either the SOAP or REST API. Here's an example I built in Workbench:

PresenceUserConfig in workbench

You don't need a WSDL, just make the appropriate JSON and make the call.

HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer '+UserInfo.getSessionId());
        new Map<String, Object> {
            'Capacity' => 20,
            'DeveloperName' => 'Fox',
            'MasterLabel' => 'Fox',
            'OptionsIsAutoAcceptEnabled' => true,
            'OptionsIsDeclineEnabled' => false,
            'OptionsIsDeclineReasonEnabled' => false,
            'OptionsIsDisconnectSoundEnabled' => true,
            'OptionsIsRequestSoundEnabled' => true
HttpResponse res = new Http().send(req);

You will need to make additional modifications to the above code, but this should get you started.

  • Thank you for the response. When you set an endpoint, you specify '/services/data/52.0/sobjects/PresenceUserConfig'. How did you acquire this url? I have to make that specific to my code.
    – Nonya
    Commented Oct 6, 2021 at 9:10
  • @Nonya Start with the REST API Developer's Guide. The first part, /services/data/ is the root for all API requests, 52.0 is the API version to use, and the remaining parts describe the specific action you wish to perform with the API.
    – sfdcfox
    Commented Oct 6, 2021 at 12:27
  • @sfdxfox I see. So in theory the endpoint you specified in that sample code should work? I've tried using it and modifying it but I get errors: |System.HttpResponse[Status=Unsupported Media Type, StatusCode=415].
    – Nonya
    Commented Oct 6, 2021 at 12:58
  • @Nonya I think I forgot req.setHeader('Content-Type','application/json').
    – sfdcfox
    Commented Oct 6, 2021 at 13:00
  • would this line replace the previous req.setHeader('Authorization', 'Bearer '+UserInfo.getSessionId());? If so another error presents itself, 401 error. This indicates lack of privileges, which probably occurs from removing userinfo? When checking the url endpoint, I get an xml file with this format: <Errors> <Error> <errorCode>INVALID_SESSION_ID</errorCode> <message>Session expired or invalid</message> </Error> </Errors> Could this be the reason for the error?
    – Nonya
    Commented Oct 6, 2021 at 13:17

You must log in to answer this question.

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