DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • MuleSoft Integrate With ServiceNow
  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Make Your Integration Seamless By Using Ballerina Client Connectors
  • SharePoint Integration With MuleSoft

Trending

  • Navigating Double and Triple Extortion Tactics
  • Memory-Optimized Tables: Implementation Strategies for SQL Server
  • Designing for Sustainability: The Rise of Green Software
  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Integration of Salesforce Apex API With MuleSoft

Integration of Salesforce Apex API With MuleSoft

Here we are going to Build one sample Salesforce Apex Api and further, we will use the MuleSoft apex connector to access the Apex API.

By 
Dikshant Dwivedi user avatar
Dikshant Dwivedi
·
Jun. 05, 20 · Analysis
Likes (3)
Comment
Save
Tweet
Share
18.6K Views

Join the DZone community and get the full member experience.

Join For Free

Here we are going to Build one sample Salesforce Apex Api and further, we will use the MuleSoft apex connector to access the Apex API.

In this example, we will build one sample Apex API which will be fetched out all the Account name and phone number from the salesforce, and then we will build one Mulesoft rest API which will further access the salesforce apex API and then return the payload in response.

 So let's follow the below steps to build the Example.

  • Log in to your Salesforce developer account with your username and password
  • Click on Setup on the top right-hand corner
    lightning experience
  • On the left-hand side menu, under Build category go to Develop -> Apex Classes
    building ideas
  • Click on New -> (write below code) -> click save

    Java
     




    x
    22


     
    1
    @RestResource(urlMapping='/showAccountsDetails')
    2
    global class checkAccount
    3
    {
    4
    
                
    5
    @HttpGet
    6
    global static LIST<Account> getAccount()
    7
    {
    8
    LIST<Account> lst;
    9
    try
    10
    {
    11
    lst = [select name,phone from Account];
    12
    return lst;
    13
    }
    14
    catch(Exception ex)
    15
    {
    16
    system.debug('Error'+ex.getMessage());
    17
    }
    18
    
                
    19
    return lst;
    20
    }
    21
    
                
    22
    }


  •  Now open Anypoint Studio
  • Click on File -> New -> Mule Project
  • Enter the Project Name as “test-apex-API” and click Finish

    project settings
  • After clicking on Finish project will be created. Now, Expand the project and open pom.xml
  • Under the dependencies, tag add below dependency

    XML
     




    xxxxxxxxxx
    1


     
    1
    <dependency>
    2
                <groupId>com.mulesoft.connectors</groupId>
    3
                <artifactId>mule-salesforce-connector</artifactId>
    4
                <version>10.1.0</version>
    5
                <classifier>mule-plugin</classifier>
    6
    </dependency>
    7
    
                



    (Note: Kindly use version above 9.9.1. Because some people were facing session token error issue and they have fixed the issue in above version)
  • Now we will create the mule flow. Open the test-apex-api.xml
  • Search for the HTTP listener in Mule Palette
  • Drag and drop the listener on the test-apex-api.xml Message Flow tab
  • Now, let's configure the listener. So, click on the listener then below tab will get open

    listener
  • Click on the plus symbol against the Connector configuration, add below details as per the screenshot and click OK
    http listener
  • Under the General add the path “/test apex”
    /testapex
  • Search for the logger in Mule Palette, Drag and drop the logger
    error handling
  • Now configure logger message “Test apex API flow started”

    logger
  • Search for the Transform Message in Mule Palette, Drag and drop the Transform Message after logger and set the empty JSON in payload
    output
  • Search for the Invoke apex rest method in Mule Palette, Drag and drop the Invoke apex rest method after Transform Message
    listener
  • Now, let's configure the apex connector. Click on the plus symbol next to “connector configuration”
  • Fill out all your salesforce configuration details as mention below in the screenshot
    salesforce
    (Note: If you don’t have the security token of your developer account you can generate it. Got to your salesforce developer account My Settings -> Personal -> Reset My Security Token. Click Reset Security Token and it will send a security token to your registered email )
  • After filling out the salesforce details you can test your connection by clicking on Test Connection. As soon as you get the Test connection successful. Click OK on test connection window and then click Ok on Salesforce Config Window
  • Now in the “Invoke apex rest method” connector in going to “General” under “Apex class definition” write below details
    • Apex Class Name: checkAccount
    • Apex Class Method Name:
      getAccount (getAccount^/showAccountsDetails^HttpGet^List&lt;Account&gt;^)
      invoke apex
    • Note: Apex Class Name and Apex Class Method Name will be auto-populate by data sense. As soon as you give the Connector configuration of your developer account. It will be giving all the apex classes you have. Which you can further choose from the drop-down to access and the same will happen with the method, It will populate all the methods available in that particular class. If the data sense is not working you should check the connector configuration details again and test the connection. Then click the refresh option against the Apex Class Name
  • Now add one “Transform Message” which will convert the response payload coming from apex API to JSON format. Just drag and drop the “Transform Message” from Mule Pallete  after “Invoke apex rest method” connector and add below code
    output payload
  • Now add the logger to print the response. Drag and drop the “Logger” from Mule Pallete after the “Transform Message” connector. 
  • Configure the “Logger”  as per below screenshot
    logger 




  • xxxxxxxxxx
    1


     
    1
    %dw 2.0
    2
    output application/json
    3
    ---
    4
    payload
    5
    
             


    Now your final flow will look like below

    test apex
  • Run the Mule Project
  • After Running your mule project open the postman and give a GET call to  “http://localhost:8081/testapex “

You will get the output 

get localhost

Note: The response output will be stored against the key method_name_output. For example, here we have used the method getAccount so the key will be getAccountOutput.

API MuleSoft Connector (mathematics) Integration

Opinions expressed by DZone contributors are their own.

Related

  • MuleSoft Integrate With ServiceNow
  • Migrating MuleSoft System API to AWS Lambda (Part 1)
  • Make Your Integration Seamless By Using Ballerina Client Connectors
  • SharePoint Integration With MuleSoft

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!