2

I am exploring options of moving from code based apex to 'flows' using 'external services'. The service basically takes 3 parameters: SSN, account number and VIN (optional) and gives back a boolean result that the customer is validated.

I am getting stuck in passing the 'body' parameter of a POST request through the flow - below is the actual JSON payload that needs to be set in the request body parameter:

enter image description here

I cannot send this JSON as a text variable because it's expecting an object variable and gives an error. After reading some of the blogs I understand that I can pass this JSON object only by created a 'APEX Defined variables' based on a wrapper class that should be defined.

I created the below wrapper class to be used as an Apex variable

enter image description here

After I create the variable referencing this Apex class, I still get the error "Data type incompatible" error - below is the screenshot:

enter image description here

Any help on what I am doing wrong?

Here is the Swagger file:

openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: https://exp-accountmgt-svc-stg.com  
    description: Generated server url
paths:
 /expapi/v3/profile/accounts/customer:
    post:
      tags:
        - profile-account-controller-v-3
      summary: Validate Customer
      description: Used to check if the account is eligible for registration using account Number+ 4 digit SSN or last 8 digits of VIN + 4 digit SSN (OFSC)
      operationId: customerValidate_1
      parameters:
        - name: X-CAS-DB
          in: header
          required: false
          schema:
            type: string
        - name: X-Tenant-Id
          in: header
          required: true
          schema:
            type: string
        - name: X-Brand-Id
          in: header
          required: true
          schema:
            type: string
        - name: X-Channel-Id
          in: header
          required: true
          schema:
            type: string
        - name: X-Upstream-Trace-Id
          in: header
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomerValidateRequestBean'
        required: true
      responses:
        '200':
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/CustomerValidateResponseBean'
        
components:
  schemas:
    ErrorBean:
      type: object
      properties:
        code:
          type: string
        message:
          type: string
    ErrorResponseBean:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorBean'
    Message:
      type: object
      properties:
        type:
          type: string
        description:
          type: string
        code:
          type: string
        message:
          type: string
    Status:
      type: object
      properties:
        code:
          type: string
        messages:
          type: array
          items:
            $ref: '#/components/schemas/Message'
    CustomerDetails:
      type: object
      properties:
        accountNumber:
          type: string
        borrowerPosition:
          type: string
        customerName:
          type: string
        businessAccountType:
          type: string
        uniquePartyIdentifier:
          type: string
        email:
          type: string
        customerFirstName:
          type: string
        customerLastName:
          type: string
        regEligibleFlag:
          type: string
        ssnValid:
          type: string
        guid:
          type: string
        token:
          type: string
        userId:
          type: string
        editMessageCode:
          type: string
        accountGroup:
          type: string
        remainingAttempts:
          type: string
        username:
          type: string
        emailId:
          type: string
    CustomerValidateResponseBean:
      type: object
      properties:
        response:
          $ref: '#/components/schemas/CustomerDetails'
        status:
          $ref: '#/components/schemas/Status'
    CustomerValidateRequestBean:
      type: object
      properties:
        channel:
          type: string
          readOnly: true
        ssn:
          type: string
        fullAccountNumber:
          type: string
        vin:
          type: string
        casDb:
          type: string
          readOnly: true
    
   
2
  • 2
    When you registered your external service, what were the parameters? It's little odd that full body became a parameter. Can you share your open API swagger file? Oct 8, 2022 at 13:55
  • Yes mohit thats unfortunate but we have already flagged them to breakdown the body so we get them parametrized (we are parallely working on that update) But posting the body with a JSON like we do with apex seem to be something not clear on how it works Oct 9, 2022 at 0:10

2 Answers 2

2

OK, I kind of got the answer, it was a hidden feature I missed.

So when you consume the Swagger JSON for an external service, Salesforce creates a system generated Apex class based on the definition file I loaded. The system generated apex class is basically the wrapper class I was needing to match the structure of the request response - I didn't know this part and was trying to create a custom wrapper class of my own :(

enter image description here

So what I did is use this system generated Apex class to create my Apex defined variables and then I don't get this error and see the response - hope this helps someone stuck in my situation.

0

first of all thank you soooooo much. I had the same issue and now I understand how this works!!!! I have another question though. Must say, I am not a developer, so I apologize if the questions sounds stupid. So I've got my Open API Spec, I have created the external system and the flow. In my flow (record triggered flow) I have created an action (scheduled path 2 mins after). In my action, I have set the input parameters using the apex defined class as explained by you and it works. Now my problem is that when I try to debug it says "Error Occurred: Missing required input parameter: body Required field is missing value: body" I guess this happens because the fields name used in the apex class are not the same as the ones in SF? So the mapping is missing. Again, I am not a dev so I might be wrong. Do you have any suggestion??

Thanks again for your help

1
  • Welcome to Salesforce Stack Exchange (SFSE)! This is a Questions & Answers site, not a threaded forum. Please see the various pertinent/relevant notes in Why and how are some answers deleted?, and be aware that your "answer" will likely be deleted. You should ask a new question, and in it you can link to this question or its other answer for reference if helpful (just click "Share" at the bottom left of the post to get a URL).
    – Moonpie
    Nov 30, 2022 at 12:08

You must log in to answer this question.

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