Failed to Invoke Salesforce Apex Rest endpoint in Mule 3

83 Views Asked by At

I am new to Salesforce and am trying to invoke a APEX rest endpoint in Salesforce.
This Salesforce endpoint is created by me - code as below :

    @RestResource(urlMapping='/MyAccounts/*')
    global with sharing class MyAccountsService {
    
    @HttpGet
    global static List<Account> getAccounts() {
        System.Debug('<<<<<<< hello world 001 >>>>>>>>');
        List<Account> accounts = [select id,name,BillingStreet,BillingCity,BillingState,BillingPostalCode,BillingAddress from Account Limit 200 ];
        System.Debug('<<<<<<< hello world 002 >>>>>>>>');
        return accounts;
    }
    
}

I am able to call this endpoint from postman successfully and am getting a 200 response with response body .

Next I tried to invoke this from a Mule 3 application . To connect to SFDC am using Salesforce__OAuth_2_0_Username_Password

I have confirmed connection to Salesforce via mule is working using above connector Here is source code for connector :

<sfdc:cached-config-oauth-user-pass 
name="Salesforce__OAuth_2_0_Username_Password" consumerKey="xxx" consumerSecret="xxx" 
username="[email protected] " password="abcd" clearNullFields="true" 
fetchAllApexRestMetadata="true" doc:name="Salesforce: OAuth 2.0 Username-Password" 
batchSobjectMaxDepth="200" fetchAllApexSoapMetadata="true">
        <reconnect blocking="false"/>
    </sfdc:cached-config-oauth-user-pass>

Next I have used it in my flow and the apex class and method name are also populating : [![Salesforce connector with Apex class and method][1]][1]

However when I am trying to invoke the Apex class it is throwing this error :

DEBUG 2023-10-01 18:37:58,018 [[simple_pocs].HTTP_Listener_Configuration.worker.01] org.mule.modules.salesforce.config.login.LoginServiceImpl: Requesting an OAuth2 Access Token with OAuth2-Username-Password (a.k.a login)

DEBUG 2023-10-01 18:37:59,191 [[simple_pocs].HTTP_Listener_Configuration.worker.01] org.mule.modules.salesforce.config.login.LoginServiceImpl: OAuth2 Access Token acquired.

ERROR 2023-10-01 10:31:33,086 [[simple_pocs].HTTP_Listener_Configuration.worker.01] org.mule.modules.salesforce.SalesforceConnector: org.glassfish.grizzly.utils.BufferInputStream cannot be cast to java.util.Map java.lang.ClassCastException: org.glassfish.grizzly.utils.BufferInputStream cannot be cast to java.util.Map

When I call via postman I can see Debug logs in Salesforce console , but when I invoke it via mule am getting above error and no logs in Sasleforce console . So definitely the call from Mule is not going through , though Mule is connecting successfully ( have configured connected app in Salesforce )

Here is my mule relevant code :

<flow name="simple_pocsFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
        <logger level="INFO" doc:name="Logger"/>
        
        <sfdc:invoke-apex-rest-method 
         config-ref="Salesforce__OAuth_2_0_Username_Password" 
         restMethodName=
         "MyAccountsService||getAccounts^/MyAccounts/*^HttpGet^List&amp;lt;Account&amp;gt;^" 
         doc:name="Salesforce"/>
        <logger level="INFO" doc:name="Logger"/>
    </flow>

Do I need to make some config changes maybe in Salesforce ? or is there something wrong in my code ? [1]: https://i.stack.imgur.com/FCHvj.png

0

There are 0 best solutions below