Exercise Guide
nypoint Platform
A
Development: Fundamentals
DEX401 | November 26, 2024
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Table of Contents
able of Contents
T
2
Introducing the course 4
Walkthrough: Set up your computer for class 5
Module 1: Accessing and modifying Mule events 12
Walkthrough 1-1: View event data 13
Walkthrough 1-2: Debug a Mule application 23
Walkthrough 1-3: Track event data as it moves in and out of a Mule application 32
Walkthrough 1-4: Set request and response data 41
Walkthrough 1-5: Get and set event data using DataWeave expressions 47
Walkthrough 1-6: Set and get variables 59
Module 2: Structuring Mule applications 65
Walkthrough 2-1: Create and reference subflows and private flows 66
Walkthrough 2-2: Trigger flows using the VM connector 74
Walkthrough 2-3: Encapsulate global elements in a separate configuration file 86
Walkthrough 2-4: Use property placeholders in connectors 98
Walkthrough 2-5: Create a well-organized Mule project 104
Walkthrough 2-6: Manage metadata for a project 118
Module 3: Consuming web services 128
alkthrough 3-1: Consume a RESTful web service that has an API (and connector) in
W
Exchange 129
Walkthrough 3-2: Consume a RESTful web service 147
Walkthrough 3-3: Consume a SOAP web service 159
Walkthrough 3-4: Transform data from multiple services to a canonical format 175
Module 4: Controlling event flow 187
Walkthrough 4-1: Multicast an event 188
Walkthrough 4-2: Route events based on conditions 196
Walkthrough 4-3: Validate events 211
Module 5: Handling errors 220
Walkthrough 5-1: Explore default error handling 221
Walkthrough 5-2: Handle errors at the application level 232
Walkthrough 5-3: Handle specific types of errors 243
Walkthrough 5-4: Handle errors at the flow level 250
Walkthrough 5-5: Handle errors at the processor level 262
© Copyright 2023 salesforce.com, inc. All rights reserved. 2
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-6: Map an error to a custom error type 273
Walkthrough 5-7: Review and integrate with APIkit error handlers 282
Walkthrough 5-8: Set a reconnection strategy for a connector 299
Module 6: Writing DataWeave transformations 301
Walkthrough 6-1: Create transformations with the Transform Message component 303
Walkthrough 6-2: Transform basic JSON, Java, and XML data structures 318
Walkthrough 6-3: Transform complex data structures with arrays 325
Walkthrough 6-4: Transform to and from XML with repeated elements 339
Walkthrough 6-5: Define and use variables and functions 349
Walkthrough 6-6: Coerce and format strings, numbers, and dates 356
Walkthrough 6-7: Define and use custom data types 364
Walkthrough 6-8: Use DataWeave functions 369
Module 7: Triggering flows 377
Walkthrough 7-1: Trigger a flow when a new file is added to a directory 378
alkthrough 7-2: Trigger a flow when a new record is added to a database and use
W
automatic watermarking 389
Walkthrough 7-3: Schedule a flow and use manual watermarking 404
Walkthrough 7-4: Publish and listen for JMS messages 423
Module 8: Processing records 434
Walkthrough 8-1: Process items in a collection using the For Each scope 435
Walkthrough 8-2: Process records using the Batch Job scope 445
Walkthrough 8-3: Use filtering and aggregation in a batch step 455
© Copyright 2023 salesforce.com, inc. All rights reserved. 3
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Introducing the course
In this module, you will:
● Learn about the course format.
● Access the course files.
● Make sure your computer is set up for class.
● Review the course outline.
© Copyright 2023 salesforce.com, inc. All rights reserved. 4
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough: Set up your computer for class
In this walkthrough, you make sure your computer is set up correctly, so you can complete
the class exercises. You will:
● Access the course files.
● Make sure Anypoint Studio starts successfully.
● Install Advanced REST client (if you did not already).
● Make sure you have an active Anypoint Platform account.
● Make sure you have a Salesforce developer account and an API security token.
Access course files
1. Locate your course enrollment email and follow the instructions to download the
student files ZIP.
2. On your computer, locate the student files ZIP and expand it.
3. Open the two course snippets.txt files, one for each part of the course.
NOTE: Keep these files open. You will copy and pastetext from them during class.
4. Again, follow your course enrollment email to access the student manuals and
slides.
Start Anypoint Studio
5. In your computer's file browser, navigate to where you installed Anypoint Studio and
open it.
© Copyright 2023 salesforce.com, inc. All rights reserved. 5
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE:If you do not have Anypoint Studio, you can download it from
https://www.mulesoft.com/lp/dl/studio.
Upon starting Anypoint Studio, users on Windows may get a popup asking to allow
Windows Defender Firewall access for OpenJDK; access should be allowed.
6. In the Workspace Launcher dialog box, look at the location of the default
workspace; change the workspace location if you want.
7. ClickOKto select the workspace; Anypoint Studioshould open.
NOTE:If you cannot successfully start Anypoint Studio,make sure that you have enough
available memory (at least 8GB available) to run Anypoint Studio.
© Copyright 2023 salesforce.com, inc. All rights reserved. 6
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. If you get a new features page, click theContinue to Studiobutton to close it.
9. If you get an Updates Available popup in the lower-right corner of the application,
click it and install the available updates.
Open Advanced REST Client
10.OpenAdvanced REST Client.
NOTE:If you do not have Advanced REST Client (oranother REST API client) installed,
download it now from https://install.advancedrestclient.com/and install it.
© Copyright 2023 salesforce.com, inc. All rights reserved. 7
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.Leave Advanced REST Client open; you will use it throughout class.
Make sure you have an active Anypoint Platform account
12.In a web browser, navigate tohttp://anypoint.mulesoft.com/and log in.
NOTE:If you do not have an account, sign up for afree, 30-day trial account now. Also, if
you get prompted here or in other parts of the course to enable multi-factor authentication,
select Not Now.
13.Click the menu button located in the upper left in the main menu bar.
14.In the menu that appears, selectAccess Management.
NOTE:This will be called the main menu from now on.
© Copyright 2023 salesforce.com, inc. All rights reserved. 8
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.In the left-side navigation, click the Runtime Manager link under Subscription.
16.Check your subscription level and if it is a trial account, make sure it is not expired.
NOTE:If your trial is expired or will expire duringclass, sign out and then sign up for a new
trial account now.
© Copyright 2023 salesforce.com, inc. All rights reserved. 9
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Make sure you have a Salesforce developer account and an API
security token
17.In the same or another web browser tab, navigate tohttp://salesforce.comand log
in to your Salesforce org.
NOTE:If you did not sign up for a free developeraccount yet, go to
http://developer.salesforce.com/and sign up for onenow. You will want to use a free
developer account and not your company account (if you already have one) for class. You
will use the API to add new fictitious accounts to it and will probably not want to add those
to your real data.
18.In Salesforce, click your avatar at the top of the screen and selectSettings.
19.In the left-side navigation, selectMy Personal Information> Reset My Security
Token.
© Copyright 2023 salesforce.com, inc. All rights reserved. 10
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
20.If you did not already request a security token, click theReset Security Token
button.
NOTE:A security token will be sent to your email in a few minutes. You will need this token
to make API calls to Salesforce from your Mule applications.
© Copyright 2023 salesforce.com, inc. All rights reserved. 11
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
odule 1: Accessing and modifying Mule
M
events
At the end this module, you should be able to:
● Log event data.
● Debug Mule applications.
● Read and write event properties.
● Write expressions with the DataWeave expression language.
● Create variables.
© Copyright 2023 salesforce.com, inc. All rights reserved. 12
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 1-1: View event data
In this walkthrough, you create a new project to use in the next two modules to learn about
Mule events and Mule applications. You will:
● Create a new Mule project with an HTTP Listener and set the event payload.
● View event data in the DataSense Explorer.
● Use a Logger to view event data in the Anypoint Studio console.
Create a new Mule project
1. Return to Anypoint Studio.
2. SelectFile > New > Mule Project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 13
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Set the project name toapdev-examplesand clickFinish.
Create an HTTP Listener to receive requests
4. In the Mule Palette, selectFavorites.
5. Drag anHTTP Listenerfrom the Mule Palette to thecanvas.
6. In the Listener properties view, click theAddbuttonnext to Connector
configuration.
7. In the Global Element Properties dialog box, verify the host value is set to0.0.0.0
and the port value to8081.
8. ClickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 14
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
9. In the Listener properties view, set the path to/hello.
10.Click theAdvancedtab and set the allowed methods toGET.
© Copyright 2023 salesforce.com, inc. All rights reserved. 15
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.Click theGeneraltab and set the display name toGET /hello.
Change the flow name
12.Select the flow.
13.In the apdev-examplesFlow properties view, change the name tohelloFlow.
Set the event payload
14.Drag aSet Payloadtransformer from the Favoritessection of the Mule Palette into
the process section of the flow.
15.In the Set Payload properties view, set the display name toHello.
© Copyright 2023 salesforce.com, inc. All rights reserved. 16
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
16.Switch the value to literal mode and set its value toHello.
Add a Logger
17.Drag a Logger component from the Mule Palette and drop it at the end of the flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 17
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
View event structure and metadata in the DataSense Explorer
18.Select theGET /helloHTTP Listenerand locate theDataSense Explorer in the right
side of its properties view.
19.In the Input tab, examine Payload and Attributes.
20.Select theOutputtab and examine Payload, Attributes,and HttpRequestAttributes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 18
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Select theSet Payloadcomponent in helloFlow.
22.In the DataSense Explorer, examinePayloadandAttributeson the Input tab.
23.Select theOutputtab and examinePayloadandAttributes.
24.Select theLoggercomponent in helloFlow.
25.In the DataSense Explorer, examinePayloadandAttributeson the Input tab.
26.Select theOutputtab and examinePayloadandAttributes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 19
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Run the application and review response data
27.Save the file and run the project.
28.Return toAdvanced REST Clientand click the buttonto create a new tab.
NOTE:You are adding a new tab so that you can keepthe request to the American API you
created in the Getting Started with Anypoint Platform course saved in another tab for later
use.
29.In the new tab, make a GET request tohttp://localhost:8081/hello; you should see
Hellodisplayed.
View event data in the Anypoint Studio console
30.Return to Anypoint Studio and look at the console.
31.Locate the data displayed by using the Logger.
© Copyright 2023 salesforce.com, inc. All rights reserved. 20
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
32.Review the event attributes.
Send query parameters with a request
33.Return to Advanced REST Client and add a query parameter with a key offnameand
a value ofmax.
34.Add a second key/value pair oflnameandmule.
35.ClickSend.
© Copyright 2023 salesforce.com, inc. All rights reserved. 21
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
36.Return to Anypoint Studio and look at the console.
37.Locate the query parameters in the logged event data.
38.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 22
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 1-2: Debug a Mule application
In this walkthrough, you debug and step through the code in a Mule application. You will:
● Locate the port used by the Mule Debugger.
● Add a breakpoint, debug an application, and step through the code.
● Use the Mule Debugger to view event properties.
● Pass query parameters to a request and locate them in the Mule Debugger.
● Increase the request timeout for Advanced REST Client.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 23
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Locate the port used by the Mule Debugger
1. Return to Anypoint Studio.
2. In the main menu bar, selectRun > Debug Configurations.
3. Selectapdev-examplesin the left menu bar under MuleApplications; you should
see that the apdev-examples project is selected to launch.
4. Select theMule Debugtab; you should see the debuggerport is set to 6666 for the
project.
NOTE:If you know you have another program using port6666 like McAfee on Windows,
change this to a different value. Otherwise, you can test the Debugger first and come back
and change the value here later if there is a conflict.
5. ClickClose.
© Copyright 2023 salesforce.com, inc. All rights reserved. 24
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add a breakpoint
6. Right-click theSet Payloadcomponent and selectAddbreakpoint.
Debug the application
7. Right-click in the canvas and selectDebug projectapdev-examples.
NOTE:You can also select Run > Debug or click theDebug button in the main menu bar.
8. If you get a Confirm Perspective Switch dialog box, selectRemember my decision
and clickYes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 25
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
9. Look at the console and wait until the application starts.
10.In Advanced REST Client, make another request to
http://localhost:8081/hello?fname=max&lname=mule.
View event data in the Mule Debugger
11.Return to Anypoint Studio and locate theMule Debuggerview.
12.Look at the value of the payload.
13.ExpandAttributesand review the values.
14.ExpandqueryParamsand review the values.
© Copyright 2023 salesforce.com, inc. All rights reserved. 26
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Step through the application
15.Click theNext processorbutton.
16.Look at the new value of the payload; it should beHello.
© Copyright 2023 salesforce.com, inc. All rights reserved. 27
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
17.ExpandAttributesand review the values.
18.Click theNext processorbutton again to finish steppingthrough the application.
Use Resume to step to the next breakpoint and then the end of the
application
19.Add a breakpoint to the Logger.
20.In Advanced REST Client, make another request to
http://localhost:8081/hello?fname=max&lname=mule.
21.In the Mule Debugger, click theResumebutton; youshould step to the Logger.
22.Click theResumebutton again; you should step throughthe rest of the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 28
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Cause the HTTP request to timeout
23.In Advanced REST Client, make another request to
http://localhost:8081/hello?fname=max&lname=mule.
24.Do not step through the application and wait (90 seconds by default) for the request
to timeout.
Increase the request timeout for Advanced REST Client
25.In the Advanced REST Client main menu, selectFilethenSettingsto navigate to the
application settings.
NOTE:Depending on your platform, accessing the applicationsettings may differ such as
AdvancedRestClient then Preferences.
26.In the application settings, locate theRequest timeoutsetting and click the arrow
next to it.
© Copyright 2023 salesforce.com, inc. All rights reserved. 29
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.Change the request timeout to300 seconds.
28.Click the arrow next toAPI Clientto return to therequest.
29.In the main screen, verify the tab with your last failed request is selected.
© Copyright 2023 salesforce.com, inc. All rights reserved. 30
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Switch perspectives
30.Return to Anypoint Studio.
31.Click theResumebutton twice to finish stepping throughthe application.
32.Click theMule Designbutton in the upper-right cornerof Anypoint Studio to switch
perspectives.
NOTE:In Eclipse, a perspective is a specific arrangement of views in specific locations. You
can rearrange the perspective by dragging and dropping tabs and views to different
locations. Use the Window menu in the main menu bar to save and reset perspectives.
33.Leave the project running.
© Copyright 2023 salesforce.com, inc. All rights reserved. 31
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 1-3: Track event data as it moves in and out of a
Mule application
In this walkthrough, you call an external resource, which for simplicity is another HTTP
Listener in the same application, so that you can watch event data as it moves in and out of
a Mule application. You will:
● Create a second flow with an HTTP Listener.
● Make an HTTP request from the first flow to the new HTTP Listener.
● View the event data as it moves through both flows.
NOTE:You are making an HTTP request from one flowto another in this exercise only so
you can watch the value of event data as it moves in and out of a Mule application. You will
learn how to pass events between flows within and between Mule applications in the next
module.
Starting file
If you did not complete walkthrough 1-1, you can get a starting file h
ere. This file is also
located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 32
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a second flow with an HTTP Listener
1. Return to apdev-examples.xml.
2. Drag an HTTP Listener from the Mule Palette and drop it in the canvas beneath the
first flow.
3. Change the name of the flow to goodbyeFlow.
4. In the Listener view, ensure the connector configuration is set to the existing
HTTP_Listener_config.
5. Set the path to/goodbyeand the allowed methods toGET.
6. Set the display name toGET /goodbye.
7. Add aSet Payloadtransformer and aLoggerto theflow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 33
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. In the Set Payload properties view, set the display name toGoodbyeand then use
literal mode to set the value toGoodbye.
Make an HTTP request
9. From the Mule Palette, drag anHTTP Requestto thecanvas and drop it before the
Logger in helloFlow.
10.In the Request properties view, set the display name toGET /goodbye.
© Copyright 2023 salesforce.com, inc. All rights reserved. 34
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.Set the path to/goodbyeand leave the method set to GET.
12.Click theAddbutton next to configuration.
13.In the HTTP Request configuration dialog box, set the host tolocalhostand the port
to8081and clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 35
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
View event structure and metadata in the DataSense Explorer
14.In the DataSense Explorer, examinePayload,Attributes,andHttpRequestAttributes
on the Input tab.
15.Select theOutputtab and examinePayload,Attributes, and
HttpResponseAttributes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 36
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change timeout for HTTP Request response
16.In the properties view for the GET /goodbye HTTP Request, click theResponsetab.
17.Set the Response timeout to300000.
NOTE:This is being set only for debugging purposesso that the HTTP Request does not
timeout when you are stepping through the application and examining data in the Mule
Debugger.
Debug the application
18.Save the file to redeploy the application.
19.In Advanced REST Client, send the same request to
http://localhost:8081/hello?fname=max&lname=mule.
20.In the Mule Debugger, step to theGET /goodbyerequest.
© Copyright 2023 salesforce.com, inc. All rights reserved. 37
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Look at the values of the payload and the attributes, including the queryParams.
22.Step intogoodbyeFlow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 38
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Look at the values of the payload and the attributes.
24.Step through the flow until the event returns to the Logger in helloFlow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 39
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
25.Look at the values of the payload and the attributes.
26.Step through the rest of the application.
Review response data
27.Return to Advanced REST Client and view the return data and the http status code.
28.Select Headers from the options menu above the http status code.
29.Look at the response headers; you should see content-type, content-length, and date
headers.
30.Return to Anypoint Studio and switch to the Mule Design perspective.
© Copyright 2023 salesforce.com, inc. All rights reserved. 40
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 1-4: Set request and response data
In this walkthrough, you set response and request data for HTTP Listener and HTTP Request
operations. You will:
● View the default setting for a response body.
● Set a response header.
● View the default setting for a request body.
● Set a request query parameter.
© Copyright 2023 salesforce.com, inc. All rights reserved. 41
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Starting file
I f you did not complete the previous walkthrough, you can get a starting file h ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
View default response body
1. Return toapdev-examples.xml.
2. Double-click theGET /hello HTTP Listenerin helloFlow.
3. In the GET /hello properties view, click theResponsestab.
4. In the Response section, locate the expression that sets the response body by
default to the value of the payload.
Set a response header
5. In the Headers section for the response, click theAddbutton.
6. Set the name to"name"and the value to “Max”.
7. Locate the status code field and leave it blank so the default value200is returned.
© Copyright 2023 salesforce.com, inc. All rights reserved. 42
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. Set the reason phrase toSuccess.
Run the application and review response data
9. Save the file to deploy the project.
10.Return to Advanced REST Client and send the same request.
11.In the Mule Debugger, clickResumeuntil you stepthrough the application.
12.In Advanced REST Client, locate the status code and your new reason phrase on the
Raw or Response tab.
13.On the Headers tab, review the response headers; you should now see the new
name header.
© Copyright 2023 salesforce.com, inc. All rights reserved. 43
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
View default request body
14.Return to Anypoint Studio and switch perspectives.
15.Double-click theGET /goodbye HTTP Requestin helloFlow.
16.In the GET /goodbye properties view, locate the Request section on the General tab.
17.On the Body tab, locate the expression that sets the request body by default to the
value of the payload.
Set a request query parameter
18.Select the Query Parameters tab and click theAddbutton.
© Copyright 2023 salesforce.com, inc. All rights reserved. 44
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.Set the name to "fullName" and the value to"Max Mule".
Debug and verify that the query parameter is sent with the request
20.Save the file to redeploy the project.
21.Return to Advanced REST Client and send the same request.
22.Return to the Mule Debugger and step intogoodbyeFlow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 45
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.ExpandAttributesand locate thefullNamequery parameter.
24.Step through the rest of the application.
25.Switch to theMule Designperspective.
26.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 46
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 1-5: Get and set event data using DataWeave
expressions
In this walkthrough, you get and set event data using DataWeave expressions. You will:
● Use expressions to set the payload and a logged value.
● Use expressions to set a response header and a request query parameter.
● In expressions, reference values for the event payload and attributes.
● Use the DataWeave upper() function, the concatenation, as, and default operators.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Use an expression to set the payload
1. Return to apdev-examples.xml.
2. Navigate to the properties view for the Goodbye Set Payload transformer in
goodbyeFlow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 47
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Use expression mode to change the value to an expression.
#['Goodbye']
4. Save the file and run the project.
5. In Advanced REST Client, send the same request; you should get the same result of
Goodbye as before.
Use a DataWeave function
6. In Anypoint Studio, return to the Goodbye Set Payload properties view.
7. Inside the brackets and before the string, type the wordupand pressCtrl+Spacebar.
© Copyright 2023 salesforce.com, inc. All rights reserved. 48
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. Ensure auto-completion inserts the upper function.
9. Move the Goodbye string into the parentheses.
#[upper('Goodbye')]
10.Save the file to redeploy the application.
11.In Advanced REST Client, send the same request; the return string should now be in
upper case.
Use an expression that references the payload in a Logger
12.Return to Anypoint Studio.
13.Navigate to the properties view for the Logger in helloFlow.
14.Change the display name to payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 49
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.Type#in the message field and double-click#[payload]in the auto-completion
menu.
16.Save the file to redeploy the application.
17.In Advanced REST Client, send the same request.
18.Return to the console in Anypoint Studio; you should see GOODBYE displayed for
the second Logger instead of the entire event object.
Use a string literal and a DataWeave expression in a property value
19.Return to the properties view for the Logger in helloFlow.
20.Switch the message field to literal mode then change the value to display the string
Message in front of the payload.
Message: #[payload]
21.Save the file to redeploy the application.
22.In Advanced REST Client, send the same request.
© Copyright 2023 salesforce.com, inc. All rights reserved. 50
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Return to the console in Anypoint Studio; you should see the new string displayed.
24.Return to the properties view for the Logger in helloFlow.
Use the DataWeave concatenation operator
25.Switch the message field to expression mode then change its value so the string is
part of the evaluated expression and use the concatenation operator.
#['Message: ' ++ payload]
26.Add\nin front of the message to display it on a new line.
27.Save the file to redeploy the application.
28.In Advanced REST Client, send the same request.
29.Return to the console in Anypoint Studio; you should see the same string displayed
on a new line.
© Copyright 2023 salesforce.com, inc. All rights reserved. 51
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Use an expression that references an attribute in a Logger
30.Navigate to the properties view for the Logger in goodbyeFlow.
31.Change the display name tofullName.
32.Switch the message field to expression mode then type the wordatand press
Ctrl+Spacebar; you should see auto-completion insertthe attributes keyword.
33.At the end of attributes, add a period, typeqanddouble-clickqueryParamsin the
auto-completion menu.
#[attributes.queryParams]
34.ClickApply Changesto redeploy the application.
35.In Advanced REST Client, send the same request.
36.Return to the Anypoint Studio console; you should see an object displayed by the
first Logger.
37.Modify the message for the Logger in goodbyeFlow to display the value of the query
parameter.
#[attributes.queryParams.fullName]
38.ClickApply Changesto redeploy the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 52
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
39.In Advanced REST Client, send the same request.
40.Return to the console; you should now see the value of the parameter displayed.
Use an expression that references an attribute when setting the
payload
41.Navigate to the properties view for the Goodbye Set Payload in goodbyeFlow.
42.Use the concatenation operator to also display the value of the query parameter
separated by a space.
#[upper('Goodbye') ++ ' ' ++ attributes.queryParams.fullName]
43.Select theProblemstab and review the error.
Use the as operator to coerce the attribute to a String
44.Add the as operator to display the value of the query parameter as a string.
#[upper('Goodbye') ++ ' ' ++ attributes.queryParams.fullName as
String]
NOTE:This step coerces a null value to a String,to avoid UI errors. The recommended way
to handle null values is by using a default value, which is explained later in this walkthrough.
45.ClickApply Changesto redeploy the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 53
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
46.In Advanced REST Client, send the same request; you should now also see the name
displayed.
Use an expression to set a request header
47.Return to the Anypoint Studio and navigate to the properties view for the GET
/goodbye HTTP Request in helloFlow.
48.In the Request section, select theQuery Parameterstab.
49.Change the value offullNameto the value of thefnamequery parameter.
50.ClickApply Changesto redeploy the application.
51.In Advanced REST Client, send the same request; you should now see the name of
the fname query parameter displayed.
© Copyright 2023 salesforce.com, inc. All rights reserved. 54
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Make a request and do not send a query parameter
52.Remove the query parameters and make a request tohttp://localhost:8081/hello;
you should get an error.
Set a default value in an expression
53.Return to the Anypoint Studio and navigate to the properties view for the Goodbye
Set Payload in goodbyeFlow.
54.Removeas String.
55.Use the default operator to add a default value ofMaxine.
#[upper('Goodbye') ++ ' ' ++ (attributes.queryParams.fullName
default
'Maxine')]
56.ClickApply Changesto redeploy the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 55
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
57.In Advanced REST Client, send the same request; you should now see the default
value Maxine displayed.
Use a query parameter in the expression for a response header
58.Return to the Anypoint Studio and navigate to the properties view for the GET /hello
HTTP Listener.
59.Select theResponsestab.
60.Change the name header value to the value of thefnamequery parameter.
attributes.queryParams.fname
61.ClickApply Changesto redeploy the application.
62.In Advanced REST Client, add anfnamequery parameterand set it equal to max or
some other value and send the request.
© Copyright 2023 salesforce.com, inc. All rights reserved. 56
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
63.Look at the response headers; you should no longer see a name header.
Debug and verify that the query parameter is sent with the request
64.Return to Anypoint Studio.
65.Stop and then debug the project.
66.Return to Advanced REST Client and send the same request.
67.Return to the Mule Debugger and look at the attributes and query parameters; you
should see the fname query parameter.
© Copyright 2023 salesforce.com, inc. All rights reserved. 57
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
68.Step into goodbyeFlow and look at the attributes and query parameters; you should
see the fullName query parameter.
69.Step back to helloFlow and look at the value of the attributes; you should not see
any query parameters.
70.Step through the rest of the application.
71.Switch to the Mule Design perspective.
© Copyright 2023 salesforce.com, inc. All rights reserved. 58
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 1-6: Set and get variables
In this walkthrough, you create variables associated with an event. You will:
● Use the Set Variable transformer to create a variable.
● Reference a variable in a DataWeave expression.
● Use a variable to dynamically set a response header.
● Use the Mule Debugger to see the value of a variable.
● Track variables across a transport boundary.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 59
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add the Set Variable transformer to the Favorites section of the Mule
Palette
1. Return toapdev-examples.xml.
2. In the Mule Palette, selectCore.
3. Locate the Set Variable transformer and right-click it and selectAdd to favorites.
Create a variable
4. Drag theSet Variabletransformer from the Favoritessection of the Mule Palette and
drop it after the GET /hello HTTP Listener in helloFlow.
5. In the Set Variable properties view, set the display name and name to firstName.
© Copyright 2023 salesforce.com, inc. All rights reserved. 60
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
6. Set the value to your query parameter, fname.
Use an expression that references the variable to set a response
header
7. Return to the properties view for the GET /hello HTTP Listener in helloFlow.
8. Select theResponsestab.
9. Change the name header value fromattributes.queryParams.fnameto the value of
thefirstNamevariable.
vars.firstName
© Copyright 2023 salesforce.com, inc. All rights reserved. 61
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
View variables in the Mule Debugger
10.Save the file to redeploy the project in debug mode.
11.In Advanced REST Client, send the same request.
12.In the Mule Debugger, locate and expand the newVariablessection; you should see
your firstName variable.
13.Step intogoodbyeFlow; you should see no variablesin the vars section.
© Copyright 2023 salesforce.com, inc. All rights reserved. 62
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.Step back tohelloFlow; you should see the Variables section again with your
firstName variable.
15.Step through the rest of the application.
16.Return to Advanced REST Client; you should see the header with the value of the
query parameter.
17.Change the value of the query parameter and send another request.
18.In the Mule Debugger, click theResumebutton untilyou step through the
application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 63
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.Return to Advanced REST Client; you should see the new query parameter value
returned in both the body and the header.
20.Return to Anypoint Studio and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 64
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Module 2: Structuring Mule applications
At the end of this module, you should be able to:
● Create applications composed of multiple flows and subflows.
● Pass events between flows using asynchronous queues.
● Encapsulate global elements in separate configuration files.
● Specify application properties in a separate properties file and use them in the
application.
● Describe the purpose of each file and folder in a Mule project.
● Define and manage application metadata.
© Copyright 2023 salesforce.com, inc. All rights reserved. 65
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 2-1: Create and reference subflows and private
flows
In this walkthrough, you continue to work with apdev-examples.xml. You will:
● Extract processors into separate subflows and private flows.
● Use the Flow Reference component to reference other flows.
● Explore event data persistence through subflows and private flows.
Starting file
I f you did not complete the previous walkthrough, you can get a starting file h ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 66
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Collapse a flow
1. Return toapdev-examples.xmlin Anypoint Studio.
2. Click the arrow to the left of thegoodbyeFlowtocollapse it.
Create a subflow
3. In the Mule Palette, selectCore.
4. Drag aSub Flowscope from the Mule Palette and dropit between the existing flows
in the canvas.
5. Right-click theSet Payloadtransformer in helloFlowand selectRemove breakpoint.
© Copyright 2023 salesforce.com, inc. All rights reserved. 67
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
6. Select theSet VariableandSet Payloadtransformers in helloFlow and drag them
into the subflow.
Reference a subflow
7. Drag aFlow Referencecomponent from the Mule Paletteand drop it into helloFlow
between the GET /hello HTTP Listener and the GET /goodbye HTTP Request.
8. In the Flow Reference properties view, set the flow name to
apdev-examplesSub_Flowand the display name tosubflow.
9. Change the name of the subflow fromapdev-examplesSub_Flowtosubflow.
10.In the subflow Flow Reference properties view, notice that value in the Flow name
field has been automatically changed to subflow.
11.Add a breakpoint to the subflow Flow Reference.
© Copyright 2023 salesforce.com, inc. All rights reserved. 68
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Extract processors into another flow
12.Right-click theGET /goodbye HTTP Requestand selectExtract to > Flow.
13.In the Extract Flow dialog box, set the flow name toprivateFlow.
NOTE:If you get a problem dialog containing an internalmetadata error, selectOKand
proceed.
© Copyright 2023 salesforce.com, inc. All rights reserved. 69
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.Click theMetadata Preferencesbutton and review the metadata propagation
information.
15.Leave the target Mule configuration set toCurrentand clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 70
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
16.Look at the new Flow Reference properties view; set the display name to
privateFlow.
17.DragprivateFlowabovesubflowin the canvas.
© Copyright 2023 salesforce.com, inc. All rights reserved. 71
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
18.Save the file to redeploy the application in debug mode.
19.In Advanced REST Client, send a request to
http://localhost:8081/hello?fname=Maxwell.
20.In the Mule Debugger, step through the application, watching as you step into and
out of the flows and subflows.
21.Step through the rest of the application.
22.In Advanced REST Client, send the same request again.
© Copyright 2023 salesforce.com, inc. All rights reserved. 72
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.In the Mule Debugger, step through the application again, this time watching the
values of the attributes, payload, and variables in each of the flows.
24.Step through the rest of the application.
25.Switch to theMule Designperspective.
© Copyright 2023 salesforce.com, inc. All rights reserved. 73
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 2-2: Trigger flows using the VM connector
In this walkthrough, you trigger flows to run both synchronously and asynchronously. You
will:
● Trigger flows using the VM connector.
● Explore variable persistence with VM communication.
● Publish content to a VM queue and then wait for a response.
● Publish content to a VM queue without waiting for a response.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Add the VM module to the project
1. Return toapdev-examples.xml.
2. In the Mule Palette, selectAdd Modules.
© Copyright 2023 salesforce.com, inc. All rights reserved. 74
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Select theVM connectorin the right side of the Mule Palette and drag and drop it
into the left side.
4. In the Package Explorer, locate theJARfile for theVM connector.
Add a VM Publish Consume operation
5. In helloFlow, delete theprivateFlowFlow Reference.
6. SelectVMin the Mule Palette.
© Copyright 2023 salesforce.com, inc. All rights reserved. 75
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. Select thePublish consumeoperation and drag and drop it before theLoggerin
helloFlow.
8. In the Publish consume properties view, change the display name toVM goodbye.
9. Click theAddbutton next to connector configuration.
© Copyright 2023 salesforce.com, inc. All rights reserved. 76
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
10.In the queues dropdown menu, selectEdit inlinethen click theAdd Queuebutton.
11.In the Queue dialog box, set the queue name togoodbyeand clickFinish.
© Copyright 2023 salesforce.com, inc. All rights reserved. 77
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
12.In the Global Element Properties dialog box, clickOK.
13.In the VM goodbye Publish consume properties view, set the queue name to
goodbye.
NOTE:If you do not see the queue name in the dropdownmenu, click the refresh icon for it
to be populated and then set it.
© Copyright 2023 salesforce.com, inc. All rights reserved. 78
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.Set the timeout to300 secondsfor debugging purposes.
Add a VM Listener
15.ExpandgoodbyeFlowand delete itsHTTP Listener.
© Copyright 2023 salesforce.com, inc. All rights reserved. 79
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
16.Locate theListeneroperation for the VM connector in the right side of the Mule
Palette and drag and drop it in the source section of goodbyeFlow.
17.In the VM Listener properties view, change the display name toVM goodbye.
18.Ensure the connector configuration is set to the existingVM_Configthen, if
necessary, set the queue name togoodbye.
© Copyright 2023 salesforce.com, inc. All rights reserved. 80
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
19.Save the file to redeploy the project in debug mode.
20.In Advanced REST Client, send the same request.
21.In the Mule Debugger, step through the application to theVM Publish consume.
22.Look at the payload, attributes, and variables.
23.Step intogoodbyeFlow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 81
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
24.Look at the payload, attributes, and variables (or lack thereof).
25.Step through the flow until the event returns to helloFlow.
26.Look at the payload, attributes, and variables.
27.Step through the rest of the application.
28.Switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 82
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change the VM Publish Consume operation to Publish
29.Delete theVM Publish consumeoperation in helloFlow.
30.Drag aVM Publish operationfrom the Mule Paletteand drop it before the Logger.
31.In the Publish properties view, set the display name toVM goodbye.
32.Ensure the connector configuration is set to the existingVM_Configand the queue
name is set togoodbye.
© Copyright 2023 salesforce.com, inc. All rights reserved. 83
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
33.Save the file to redeploy the project in debug mode.
34.In Advanced REST Client, send the same request.
35.In the Mule Debugger, step through the application to the VM Publish operation.
36.Step again; you should step to the Logger in helloFlow.
37.Look at the value of the payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 84
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
38.Step again; you should see execution stopped in goodbyeFlow.
39.Step to the end of the application.
40.Return to Advanced REST Client; you should see a response of Hello – not
GOODBYE.
41.Return to Anypoint Studio and switch perspectives.
42.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 85
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 2-3: Encapsulate global elements in a separate
configuration file
In this walkthrough, you refactor your apdev-examples project. You will:
● Create a new configuration file with an endpoint that uses an existing global
element.
● Create a configuration file global.xml for just global elements.
● Move the existing global elements to global.xml.
● Create a new global element in global.xml and configure a new connector to use it.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a new configuration file
1. Return to theapdev-examplesproject.
2. In the Package Explorer, right-click the project and selectNew > Mule Configuration
File.
3. In the dialog box, set the name to accounts and clickFinish.
© Copyright 2023 salesforce.com, inc. All rights reserved. 86
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. Drag an HTTP Listener to the canvas from the Mule Palette.
5. In the Listener properties view, set the display name toGET /sfdc.
6. Ensure the connector configuration is set to the existingHTTP_Listener_config.
7. Set the path to/sfdcand the allowed methods toGET.
8. Add a Transform Message component to the flow.
9. In the Transform Message properties view, change the output type to
application/json and set the expression to payload.
10.Change the name of the flow togetSFDCaccounts.
© Copyright 2023 salesforce.com, inc. All rights reserved. 87
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.Switch to the Global Elements view; you should not see any global elements.
Create a global configuration file
12.Create a new Mule configuration file calledglobal.xml.
13.In global.xml, switch to theConfiguration XMLview.
14.Place some empty lines between the start and end mule tags.
© Copyright 2023 salesforce.com, inc. All rights reserved. 88
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Move the existing global elements to the new global configuration file
15.Return toapdev-examples.xml.
16.Switch to theGlobal Elementsview and see there arethree configurations.
17.Switch to the Configuration XML view.
18.Select and cut the three configuration elements defined before the flows.
© Copyright 2023 salesforce.com, inc. All rights reserved. 89
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE:If you delete the global elements from the GlobalElements view instead, the
config-ref values are also removed from the connector operations and you need to re-add
them.
19.Return to the Message Flow view.
20.Return toglobal.xml.
© Copyright 2023 salesforce.com, inc. All rights reserved. 90
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Paste the global elements you cut to the clipboard between the start and end mule
tags.
NOTE:If you are prompted to regenerate ID values,click Yes.
22.Switch to the Global Elements view; you should see the three configurations.
© Copyright 2023 salesforce.com, inc. All rights reserved. 91
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
23.Return toapdev-examples.xml.
24.Select theGET /hello HTTP Listenerin helloFlow; the connector configuration
should still be set to HTTP_Listener_config, which is now defined in global.xml.
25.Run the project.
26.In the dialog box, ensure all the resources are selected and click Save 3 of 3.
27.In Advanced REST Client, send the same request; you should still get a response of
Hello.
© Copyright 2023 salesforce.com, inc. All rights reserved. 92
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a new global element for the Salesforce component in
global.xml
28.Return to apdev-examples.xml.
29.In the Mule Palette, selectAdd Modules.
30.Select theSalesforceconnector in the right sideof the Mule Palette and drag and
drop it into the left side.
31.Locate the new set of Salesforce JAR files in the project.
32.Return to global.xml.
33.In the Global Elements view, clickCreate.
© Copyright 2023 salesforce.com, inc. All rights reserved. 93
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
34.In the Choose Global Type dialog box, selectConnector Configuration >Salesforce
Configand clickOK.
35.In the Global Element Properties dialog box, locate the Connection section and
enter yourSalesforce username,password, andsecuritytoken.
© Copyright 2023 salesforce.com, inc. All rights reserved. 94
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
36.ClickTest Connection; your connection should be successful.
37.In the Test connection dialog box, clickOK.
38.In the Global Element Properties dialog box, clickOK; you should now see the new
configuration in global.xml.
Add a new Salesforce operation that uses the global configuration
39.Return to the Message Flow view in accounts.xml.
40.In the Mule Palette, selectSalesforce.
© Copyright 2023 salesforce.com, inc. All rights reserved. 95
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
41.Locate the Query operation in the right side of the Mule Palette and drag and drop it
before the Transform Message component in getSFDCaccounts.
42.In the Query properties view, set the display name toAccount.
43.Ensure the connector configuration is set to the existingSalesforce_Config.
44.Return to the course snippets.txt file and copy theSalesforce query.
45.Return to Anypoint Studio and paste the query in the Salesforce query section of the
Query properties view.
© Copyright 2023 salesforce.com, inc. All rights reserved. 96
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
46.Save all the files; the application should successfully redeploy.
47.In Advanced REST Client, send a GET request tohttp://localhost:8081/sfdc;you
should get a list of the accounts in your Salesforce account.
© Copyright 2023 salesforce.com, inc. All rights reserved. 97
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 2-4: Use property placeholders in connectors
In this walkthrough, you introduce properties into your API implementation. You will:
● Create a YAML properties file for an application.
● Configure an application to use a properties file.
● Define and use HTTP and Salesforce connector properties.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 98
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a properties file
1. Return to theapdev-examplesproject.
2. Right-click thesrc/main/resourcesfolder in the PackageExplorer and selectNew >
File.
3. Set the file name toconfig.yamland clickFinish.
Create a Configuration properties global element
4. Return toglobal.xml.
5. In the Global Elements view, clickCreate.
6. In the Choose Global Type dialog box, selectGlobalConfigurations > Configuration
propertiesand clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 99
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. In the Global Element Properties dialog box, set the file toconfig.yamland clickOK.
Parameterize the HTTP Listener port
8. In config.yaml, define a property calledhttp.portand set it to8081.
9. Save the file.
10.Return toglobal.xml.
11.Double-click theHTTP Listenerconfig global element.
© Copyright 2023 salesforce.com, inc. All rights reserved. 100
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
12.Change the port from8081to the application property,${http.port}.
13.ClickOK.
Parameterize the Salesforce credentials
14.Double-click theSalesforce Configglobal element.
15.Copy the username value and clickOK.
16.Return to config.yaml.
17.Define a property calledsfdc.usernameand set itto your Salesforce username.
18.Add properties for password and token and set them to your values.
© Copyright 2023 salesforce.com, inc. All rights reserved. 101
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.Save the file.
20.Return toglobal.xml.
21.Double-click theSalesforce Configglobal element.
22.Change the values to use the application properties.
23.ClickTest Connectionand make sure it succeeds.
NOTE:If your connection fails, click OK and thengo back and make sure you do not have
any syntax errors in config.yaml and that you saved the file.
24.ClickOK.
25.In the Global Element Properties dialog box, clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 102
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
26.Save all files to redeploy the application.
27.In Advanced REST Client, make the same request tohttp://localhost:8081/sfdc and
confirm you still get data.
28.Return to Anypoint Studio and stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 103
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 2-5: Create a well-organized Mule project
In this walkthrough, you create a new project for the Mule United Airlines (MUA) flights
application that you will build during the course and then review and organize its files and
folders. You will:
● Create a project based on a new API in Design Center.
● Review the project's configuration and properties files.
● Create an application properties file and a global configuration file for the project.
● Add Java files and test resource files to the project.
● Create and examine the contents of a deployable archive for the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 104
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a new API in Design Center using Import from File
1. Return to Anypoint Platform in a web browser.
2. In Design Center, select theCreate +button and selectImport from File.
3. In the Import from file dialog box, set the project name toMUA Flights APIthen
select theChoose filebutton.
© Copyright 2023 salesforce.com, inc. All rights reserved. 105
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. Browse to your student files and select theMUA Flights API.zipfile located in the
resources folder.
5. ClickOpen.
6. Back in the Import from file dialog box, ensureAPIspecificationis selected with
REST APIin its dropdown menu.
7. ClickImport.
© Copyright 2023 salesforce.com, inc. All rights reserved. 106
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. Explore the API; be sure to look at what resources are defined, the name of the
query parameters, and the structure of the Flight data type.
Create a new project to implement this API in Anypoint Studio
9. Return to Anypoint Studio.
10.Right-click in thePackage Explorerand selectNew> Mule Project.
11.In the New Mule Project dialog box, set the project name toapdev-flights-ws.
© Copyright 2023 salesforce.com, inc. All rights reserved. 107
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
12.Ensure theDownload RAML from Design Centertab is selected.
13.On this tab, click thebrowsebutton next toLocation.
14.Sign into Anypoint Platform if prompted, then, in the Browse Design Center for APIs
dialog box, selectMUA Flights APIand clickOK.
15.In the New Mule Project dialog box, clickFinish.
© Copyright 2023 salesforce.com, inc. All rights reserved. 108
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Locate the new RAML files in Anypoint Studio
16.In the Package Explorer, expand the folders in thesrc/main/resourcesfolder of the
newapdev-flights-wsproject; you should see the MUAFlights API files.
17.Openmua-flights-api.ramland review the file.
18.Leave the file open.
Review project configuration files
19.Look at themua-flights-api.xmlfile that was created;it should have aget:\flights
flow and apost:\flightsflow.
20.Renamemua-flights-api.xmltointerface.xml.
21.Create a new Mule configuration file calledimplementation.xml.
© Copyright 2023 salesforce.com, inc. All rights reserved. 109
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
22.Locatelog4j2.xmlin src/main/resources and open it.
23.Review its contents and then close the file.
24.Locate pom.xml in the project and open it.
25.Review its contents.
26.Return to the apdev-examples project and open itspom.xmlfile.
© Copyright 2023 salesforce.com, inc. All rights reserved. 110
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.Compare the two pom.xml files.
28.Close both pom.xml files.
29.In the Package Explorer, right-clickapdev-examplesand selectClose Project.
Create a properties file for application properties
30.In the apdev-flights-ws project, right-clicksrc/main/resourcesand selectNew > File.
31.In the Create New File dialog box, set the file name toconfig.yamland clickFinish.
© Copyright 2023 salesforce.com, inc. All rights reserved. 111
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
32.In config.yaml, define a property calledhttp.portequal to“8081”.
33.Save and close the file.
Create a global configuration file
34.In src/main/mule, create a new Mule configuration file calledglobal.xml.
35.In global.xml, switch to theGlobal Elementsview.
36.Create a new Configuration properties element with the file set toconfig.yaml.
37.Create a new HTTP Listener config element with the host set to0.0.0.0and the port
set to thehttp.portproperty.
© Copyright 2023 salesforce.com, inc. All rights reserved. 112
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
38.Confirm you now have two global elements defined in global.xml.
39.Save and close the file.
40.Go to the Global Elements view in interface.xml.
41.Delete themua-flights-api-httpListenerConfig HTTPListener Configuration.
42.Return to the Message Flow view.
43.Select theHTTP Listenerin mua-flights-api-main,and in the Listener properties view,
ensure the connector configuration is set toHTTP_Listener_config.
© Copyright 2023 salesforce.com, inc. All rights reserved. 113
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
44.Select the HTTP Listener in mua-flights-api-console, and in the Listener properties
view, ensure the connector configuration is set toHTTP_Listener_config.
Add Java files to src/main/java
45.In the Package Explorer, right-click the src/main/java folder and selectNew >
Package.
46.In the New Java Package dialog box, set the name tocom.mulesoft.trainingand
clickFinish.
47.In your computer's file browser, locate theFlight.javafile in the resources folder of
the student files.
48.Drag the Flight.java file into the new com.mulesoft.training package in the
src/main/java folder in the apdev-flights-ws project.
49.In the File Operation dialog box, ensureCopy filesis selected and clickOK.
50.Open theFlight.javafile.
© Copyright 2023 salesforce.com, inc. All rights reserved. 114
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
51.Review the code.
Review src/test folders
52.In the project, locate the three src/test folders.
53.Expand the src/test/resources folder.
Add test resources
54.In your computer's file browser, expand theresources/examplesfolder in the
student files.
55.Select the three flights and one united-flights files (JSON and XML) and drag them
into the src/test/resources folder in the apdev-flights-ws project.
56.In the File Operation dialog box, ensureCopy filesis selected and clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 115
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Examine the contents of a deployable archive
57.In Anypoint Studio, save all files, and then right-click the project and selectExport.
58.In the Export dialog box, select Mule > Anypoint Studio Project to Mule Deployable
Archive and click Next.
59.In the Export Mule Project dialog box, set the JAR file to a location that you can find
and clickFinish.
60.In the Export Mule Project dialog box, clickOK.
61.In your computer's file browser, locate theJARfileand expand it.
© Copyright 2023 salesforce.com, inc. All rights reserved. 116
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
62.Open the resultingapdev-flights-wsfolder and examine the contents.
© Copyright 2023 salesforce.com, inc. All rights reserved. 117
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 2-6: Manage metadata for a project
In this walkthrough, you define metadata for the apdev-flights-ws project. You will:
● Review existing metadata for the training4-american-ws project.
● Define new metadata to be used in transformations in the new apdev-flights-ws
project.
● Manage metadata.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 118
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Locate existing metadata in the training4-american-ws project
1. Open thetraining4-american-wsproject.
2. Locateapplication-types.xml in src/main/resources.
3. Open the file and review the code.
4. Right-click thetraining4-american-wsproject in thePackage Explorer and review the
options under Mule; you should see two for metadata.
5. SelectMule > Manage Metadata Types.
© Copyright 2023 salesforce.com, inc. All rights reserved. 119
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
6. In the Manage Metadata Types dialog box, select theamerican_flights_json type.
7. ClickOK.
8. Close the project.
Review the API specification and resources for the apdev-flights-ws
project
9. Return to theapdev-flights-wsproject.
10.Return tomua-flights-api.ramland review the specifiedresponse and request types.
11.Locate the files you added to the src/test/resources folder.
© Copyright 2023 salesforce.com, inc. All rights reserved. 120
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
12.Locate the file you added to the src/main/java folder.
Create flights_json metadata type
13.Right-click the project and selectMule > Manage MetadataTypes.
14.In the Manage Metadata Types dialog box, click theAddbutton.
15.In the Create new type dialog box, set the type id toflights_json.
16.ClickCreate type.
17.In the Manage Metadata Types dialog box, set the first type toJSON.
© Copyright 2023 salesforce.com, inc. All rights reserved. 121
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
18.In the dropdown menu beneath the type, selectExample.
19.Click thebrowsebutton and select theflights-example.jsonfile in
src/test/resources.
20.In the Manage Metadata Types dialog box, clickOK.
21.In the Apply changes dialog box, clickYes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 122
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Locate the new metadata definition file
22.Locateapplication-types.xmlin src/main/resources.
23.Open the file and review the code.
Create flight_json metadata type
24.Right-click the project and selectMule > Manage MetadataTypes.
25.In the Manage Metadata Types dialog box, clickAdd.
26.In the Create new type dialog box, set the type id toflight_jsonand clickCreate
type.
27.In the Manage Metadata Types dialog box, set the first type toJSON.
© Copyright 2023 salesforce.com, inc. All rights reserved. 123
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
28.SelectExampleand browse to and select theflight-example.jsonfile in
src/test/resources.
Create flights_xml metadata type
29.In the Manage Metadata Types dialog box, clickAdd.
30.In the Create new type dialog box, set the type id toflights_xmland clickCreate
type.
31.In the Apply changes dialog box, clickYes.
32.In the Manage Metadata Types dialog box, set the first type toXML.
© Copyright 2023 salesforce.com, inc. All rights reserved. 124
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
33.Select Example and browse to theflights-example.xmlfile in src/test/resources.
Create Flight_pojo metadata type
34.In the Manage Metadata Types dialog box, click theAddbutton.
35.In the Create new type dialog box, set the type id toFlight_pojoand clickCreate
type.
36.In the Apply changes dialog box, clickYes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 125
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
37.In the Manage Metadata Types dialog box, set the first type toObject.
38.In the Data structure section, clickClick heretoselect an option.
39.In the dropdown menu that appears, selectJava object.
40.In the dialog box that opens, typefliin the Selectentries field and then in the list of
classes that appears, selectFlight – com.mulesoft.training.
© Copyright 2023 salesforce.com, inc. All rights reserved. 126
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
41.ClickOK.
42.In the Manage Metadata Types dialog box, clickOK.
43.In the Apply changes dialog box, clickYes.
Review the metadata definition file
44.Return toapplication-types.xml.
45.Close the file.
© Copyright 2023 salesforce.com, inc. All rights reserved. 127
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Module 3: Consuming web services
At the end of this module, you should be able to:
● Consume web services that have an API (and connector) in Exchange.
● Consume RESTful web services.
● Consume SOAP web services.
● Pass parameters to SOAP web services using the Transform Message component.
● Transform data from multiple services to a canonical format.
© Copyright 2023 salesforce.com, inc. All rights reserved. 128
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 3-1: Consume a RESTful web service that has an API
(and connector) in Exchange
In this walkthrough, you consume a pre-built American flights RESTful web service that has
an API and a connector in Exchange. You will:
● Create a new flow to call the American RESTful web service.
● Add a REST connector from Exchange to an Anypoint Studio project.
● Configure and use a REST connector to make a call to a web service.
● Dynamically set a query parameter for a web service call.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 129
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Examine the REST connectors for the pre-built Training:
American Flights API in Exchange
1. Navigate toExchangein Anypoint Platform.
2. Locate theTraining: American flights APIin the publicExchange.
NOTE: If you still have access to the American FlightsAPI you created in the Getting Started
with Anypoint Platform course, you are encouraged to review and use that API instead in
the steps that follow. If you do not have access to port 3306, using your API (or, if necessary,
a new API created using the Derby Database connector option detailed in Walkthrough 4-2
of the Getting Started course) is required. In order to use your API, you'll need its client
credentials and endpoint URL.
© Copyright 2023 salesforce.com, inc. All rights reserved. 130
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Select the API and review its information.
4. Click theDownloaddropdown menu button; you shouldsee that REST Connect has
created connectors for the API in Exchange.
© Copyright 2023 salesforce.com, inc. All rights reserved. 131
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Make a request to the web service
5. Return to the coursesnippets.txtfile and copy thevalue for the Training: American
Flights API client_id.
6. Return to Advanced REST Client, select the first tab, and add a header called
client_id.
7. Setclient_idto the value you copied from the snippets.txtfile.
8. Repeat forclient_secret.
© Copyright 2023 salesforce.com, inc. All rights reserved. 132
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
9. Return to the coursesnippets.txtfile and copy the value for the Training: America
Flights API web service URL.
10.Return to Advanced REST Client and send a GET request to the value you copied; you
should see JSON data for the American flights as a response.
© Copyright 2023 salesforce.com, inc. All rights reserved. 133
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE:The client credentials in the snippets file may be different than what is shown here;
the values in the snippets file differ for instructor-led and self-study training classes.
Add a new flow with an HTTP Listener
11.Return to theapdev-flights-wsproject in AnypointStudio.
12.Return toimplementation.xml.
13.Drag out an HTTP Listener and drop it in the canvas.
14.Rename the flow togetAmericanFlights.
15.In the Listener properties view, set the display name toGET /american.
16.Ensure the connector configuration is set to the existing HTTP_Listener_config.
17.Set the path to/american.
18.Set the allowed methods toGET.
Add the American Flights API module to Anypoint Studio
19.In the Mule Palette, selectSearch in Exchange.
20.In the Add Dependencies to Project dialog box, enteramericanin the search field.
© Copyright 2023 salesforce.com, inc. All rights reserved. 134
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Select theTraining - American Flights APIand clickAdd.
22.ClickFinish.
23.Wait for the module to be downloaded.
24.Select the newAmerican Flights APImodule in theMule Palette.
Add a Get all flights operation
25.Select theGet flightsoperation on the right sideof the Mule Palette and drag and
drop it in the process section of the flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 135
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
26.Select theGet flightsoperation in the canvas andin its properties view, see that you
need to create a new configuration and enter aclient_idand client_secret.
Configure the American Flights API connector
27.Openglobal.xml.
28.In the Global Elements view, clickCreate.
29.In the Choose Global Type dialog box, selectConnectorConfiguration > American
Flights APIConfig and clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 136
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
30.In the Global Element Properties dialog box, set each field to a corresponding
property placeholder (that you will define and set next):
● host: ${american.host}
● port: ${american.port}
● protocol: ${american.protocol}
● basePath: ${american.basepath}
© Copyright 2023 salesforce.com, inc. All rights reserved. 137
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
31.ClickOK.
32.Return to the course snippets.txt file and copy the text for the American RESTful web
service properties.
33.Openconfig.yamlinsrc/main/resourcesand paste thecode at the end of the file.
34.Return to Advanced REST Client and copy the value for your client_id.
35.Return toconfig.yamland paste the value within doublequotes.
36.Repeat for yourclient_secret.
© Copyright 2023 salesforce.com, inc. All rights reserved. 138
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Configure the Get flights operation
37.Return toimplementation.xml.
38.In the Get flights properties view, ensure the Connector configuration is set to
American_Flights_API_Config.
39.Set the client id to the${american.client_id}property.
40.Set the client secret to the${american.client_secret}property.
41.Leave the destination field blank.
© Copyright 2023 salesforce.com, inc. All rights reserved. 139
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review metadata associated with the operation
42.Select theOutputtab in the DataSense Explorer andexpandPayload.
Test the application
43.Run the project.
44.In the dialog box, ensure all the resources are selected and clickSave 3 of 3.
45.In Advanced REST Client, return to the tab with the localhost request.
© Copyright 2023 salesforce.com, inc. All rights reserved. 140
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
46.Change the URL to make a GET request tohttp://localhost:8081/american; you
should get all the flights.
Review the specification for the API you are building
47.Return tomua-flights-api.ramlinsrc/main/resources/api.
48.Review the optional query parameters.
© Copyright 2023 salesforce.com, inc. All rights reserved. 141
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
49.Locate the return type for the get method of the /flights resource.
50.OpenFlightsExample.ramlin src/main/resources/api.examplesand review its
structure.
Create a variable to set the destination airport code
51.Return toimplementation.xml.
52.Drag aSub Flowscope from the Mule Palette and dropit at the top of the canvas.
53.Change the name of the flow tosetCode.
© Copyright 2023 salesforce.com, inc. All rights reserved. 142
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
54.Drag aSet Variabletransformer from the Mule Palette and drop it in thesetCode
subflow.
55.In the Set Variable properties view, set the name and display name tocode.
56.Switch the value field to expression mode then set its value to a query parameter
calledcodeand give it a default value ofSFOifno query parameter is passed to the
flow.
message.attributes.queryParams.code default 'SFO'
Dynamically set a query parameter for the web service call
57.Drag aFlow Referencecomponent from the Mule Paletteand drop it after theGET
/americanListenerin getAmericanFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 143
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
58.In the Flow Reference properties view, set the flow name and display name to
setCode.
59.In the Get flights properties view, switch the destination field to expression mode
then set its value to the variable containing the airport code.
vars.code
© Copyright 2023 salesforce.com, inc. All rights reserved. 144
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
60.Save the file to redeploy the application.
61.In Advanced REST Client, send the same request; this time you should only get
flights to SFO.
© Copyright 2023 salesforce.com, inc. All rights reserved. 145
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
62.Add a query parameter calledcodeequal to LAX and make the request; you should
now only see flights to LAX.
63.Examine the data structure of the JSON response.
NOTE:You will transform the data to the format specifiedby the mua-flights-api in a later
walkthrough.
© Copyright 2023 salesforce.com, inc. All rights reserved. 146
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 3-2: Consume a RESTful web service
In this walkthrough, you consume the United RESTful web service that does not have an API
in Exchange. You will:
● Create a new flow to call the United RESTful web service.
● Use the HTTP Request operation to call a RESTful web service.
● Dynamically set a URI parameter for a web service call.
● Add metadata for an HTTP Request operation’s response.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 147
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Make a request to the United web service
1. Return to the coursesnippets.txtfile.
2. Locate and copy theUnited RESTful web service URL.
3. In Advanced REST Client, make a new tab and make a GET request to this URL.
4. Review the structure of the JSON response.
5. Look at the destination values; you should see SFO, LAX, CLE, PDX, and PDF.
6. In the URL field, add the destination CLE as a URI parameter.
7. Send the request; you should now only see flights to CLE.
Add a new flow with an HTTP Listener operation
8. Return to implementation.xml in Anypoint Studio.
© Copyright 2023 salesforce.com, inc. All rights reserved. 148
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
9. Drag out anHTTP Listenerfrom the Mule Palette and drop it at the bottom of the
canvas.
10.Change the name of the flow togetUnitedFlights.
11.In the Listener properties view, set the display name toGET /united.
12.Ensure the connector configuration is set to the existingHTTP_Listener_config.
13.Set the path to/united.
14.Set the allowed methods toGET.
© Copyright 2023 salesforce.com, inc. All rights reserved. 149
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add an HTTP Request operation
15.Drag out anHTTP Requestfrom the Mule Palette anddrop it into the process
section of getUnitedFlights.
16.In the Request properties view, set the display name toGet flights.
Create an HTTP Request configuration
17.Return to thecourse snippets.txtfile and copy thetext for theTraining web service
properties.
18.Return toconfig.yamland paste the code at the endof the file.
© Copyright 2023 salesforce.com, inc. All rights reserved. 150
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: The Training web service properties you see may be different than what is shown
here; the values in the snippets file differ for instructor-led and self-study training classes.
19.Return to the Global Elements view in global.xml.
20.Create a new HTTP Request configuration with the following values:
● Name: HTTP_Request_config_training
● Base Path: ${training.basepath}
● Host: ${training.host}
● Port: ${training.port}
21.ClickOK.
Configure the HTTP Request operation
22.Return toimplementation.xml.
© Copyright 2023 salesforce.com, inc. All rights reserved. 151
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Navigate to theGet flights Requestproperties view ingetUnitedFlights.
24.Set the configuration to the existingHTTP_Request_config_training.
25.Leave the method set toGET.
26.Set the path to/united/flights.
Review metadata associated with the United Get flights operation
response
27.Select theOutputtab in the DataSense Explorer; youshould see no metadata for
the payload.
Test the application
28.Save the files to redeploy the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 152
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
29.In Advanced REST Client, return to the tab with the localhost request.
30.Change the URL to make a GET request tohttp://localhost:8081/united;you should
get JSON flight data for all destinations returned.
31.Add a query parameter named code and set it to one of the destination airport code
values:http://localhost:8081/united?code=CLE; youshould still get flights to all
destinations.
Add a URI parameter to the web service call
32.Return toimplementation.xmlin Anypoint Studio.
33.Drag aFlow Referencecomponent from the Mule Paletteand drop it after the GET
/united Listener in getUnitedFlights.
34.In the Flow Reference properties view, set the flow name and display name to
setCode.
© Copyright 2023 salesforce.com, inc. All rights reserved. 153
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
35.Navigate to the Get flights Request properties view in getUnitedFlights.
36.In the Request section, change the path to /united/flights/{dest}.
37.Select theURI Parameterstab.
38.Click theAddbutton.
39.Set the name todest.
40.Set the value to the value of the code variable.
© Copyright 2023 salesforce.com, inc. All rights reserved. 154
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
vars.code
Test the application
41.Save the file to redeploy the application.
42.In Advanced REST Client, make the same request; you should now only get flights to
CLE.
43.Remove the code parameter and make the request; you should now only get results
for SFO.
© Copyright 2023 salesforce.com, inc. All rights reserved. 155
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: You will transform the data to the format specified by the mua-flights-api in a later
walkthrough.
Add metadata for the United Get flights operation response
44.Return to Anypoint Studio.
45.Navigate to the properties view for theGet flightsoperation in getUnitedFlights.
46.Select theOutputtab in the DataSense Explorer andexaminePayload; you should
still see no metadata for the payload.
47.In the Get flights properties view, select theMetadatatab.
© Copyright 2023 salesforce.com, inc. All rights reserved. 156
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
48.Click theAdd metadatabutton.
49.Change the dropdown menu toOutput:Payload.
50.Click theEditbutton.
51.In the Select metadata type dialog box, click theAddbutton.
52.In the Create new type dialog box, set the type id tounited_flights_json.
53.ClickCreate type.
54.In the Select metadata type dialog box, set the first type toJSON.
55.Change the Schema selection toExample.
© Copyright 2023 salesforce.com, inc. All rights reserved. 157
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
56.Click the browse button and navigate to the projects'ssrc/test/resourcesfolder.
57.Select united-flights-example.json and click Open; you should see the example data
for the metadata type.
58.ClickSelect.
59.In the DataSense Explorer, ensure theOutputtab isselected and expandPayload;
you should now see the structure for the payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 158
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 3-3: Consume a SOAP web service
In this walkthrough, you consume a Delta SOAP web service. You will:
● Create a new flow to call the Delta SOAP web service.
● Use a Web Service Consumer connector to consume a SOAP web service.
● Use the Transform Message component to pass arguments to a SOAP web service.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Browse the WSDL
1. Return to the coursesnippets.txtfile and copy theDelta SOAP web service WSDL.
2. In Advanced REST Client, return to the tab with themule-trainingrequest.
3. Paste the URL and send the GET request; you should see the web service WSDL
returned.
© Copyright 2023 salesforce.com, inc. All rights reserved. 159
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. Browse the WSDL; you should find references to operations listAllFlights and
findFlight.
Create a new flow with an HTTP Listener connector endpoint
5. Return to Anypoint Studio.
6. Drag out anotherHTTP Listenerfrom the Mule Paletteand drop it in the canvas after
the existing flows.
© Copyright 2023 salesforce.com, inc. All rights reserved. 160
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. Rename the flow togetDeltaFlights.
8. In the Listener properties view, set the display name toGET /delta.
9. Ensure the connector configuration is set to the existingHTTP_Listener_config.
10.Set the path to/deltaand the allowed methods toGET.
© Copyright 2023 salesforce.com, inc. All rights reserved. 161
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add the Web Service Consumer module to the project
11.In the Mule Palette, selectAdd Modules.
12.Select the Web Service Consumer connector on the right side of the Mule Palette
and drag and drop it into the left side.
13.If you get a Select module version dialog box, select the latest version and clickAdd.
Configure the Web Service Consumer connector
14.Return to the coursesnippets.txtfile and copy thetext for the Delta web service
properties.
© Copyright 2023 salesforce.com, inc. All rights reserved. 162
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.Return toconfig.yamlin src/main/resources and paste the code at the end of the
file.
NOTE: The Delta web service properties you see maybe different than what is shown here;
the values in the snippets file differ for instructor-led and self-study training classes.
16.Save the file.
17.Return toglobal.xml.
18.ClickCreate.
© Copyright 2023 salesforce.com, inc. All rights reserved. 163
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.In the Choose Global Type dialog box, selectConnector Configuration > Web
Service Consumer Config.
20.ClickOK.
21.In the Global Element Properties dialog box, change the name to
Delta_Web_Service_Consumer_Config.
22.Set the following values:
● Wsdl location: ${delta.wsdl}
● Service: ${delta.service}
● Port: ${delta.port}
© Copyright 2023 salesforce.com, inc. All rights reserved. 164
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.ClickOK.
Add and configure a Consume operation
24.Return toimplementation.xml.
25.Locate theConsumeoperation for the Web Service Consumerconnector in the
Mule Palette and drag and drop it in the process section ofgetDeltaFilghts.
26.In the Consume properties view, change its display name toGet flights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 165
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.Ensure the connector configuration is set to the existing
Delta_Web_Service_Consumer_Config.
28.Click the operation dropdown menu; you should see the web service operations
listed.
29.Select thelistAllFlightsoperation.
© Copyright 2023 salesforce.com, inc. All rights reserved. 166
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review metadata associated with the Delta Get flights operation
response
30.Select theOutputtab in the DataSense Explorer andexpandPayload; you should
see the payload structure.
Test the application
31.Save the files and wait for the application to redeploy.
32.In Advanced REST Client, return to the tab with the localhost request.
33.Make a GET request tohttp://localhost:8081/delta;you should get a 200 status
code and a response listing the contents of listAllFlightsResponse.
© Copyright 2023 salesforce.com, inc. All rights reserved. 167
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Transform the response to JSON
34.Return to Anypoint Studio.
35.Add aTransform Messagecomponent to the end of theflow.
36.Set the display name toSOAP to JSON.
37.In the Transform Message properties view, change the output type to
application/jsonand set the expression topayload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 168
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
38.Save the file to redeploy the project.
39.In Advanced REST Client, make another request tohttp://localhost:8081/deltathen
examine the Response tab; you should get JSON returned.
40.Click theRawtab; you should see all the flights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 169
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
41.Add a query parameter called code and set it equal toLAX.
42.Send the request; you should still get all flights.
Call a different web service operation
43.Return to thegetDeltaFlightsflow in Anypoint Studio.
44.In the properties view for Get flights Consume operation, change the operation to
findFlight.
© Copyright 2023 salesforce.com, inc. All rights reserved. 170
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review metadata associated with the Delta Get flights operation
response
45.Select theOutputtab in the DataSense Explorer andexpandPayload; you should
now see the payload metadata for findFlightResponse.
46.Select theInputtab and expandPayload; you shouldsee this operation now
expects a destination.
© Copyright 2023 salesforce.com, inc. All rights reserved. 171
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
47.Save the file to redeploy the project.
48.In Advanced REST Client, send the same request with the query parameter; you
should get a 500 Server Error with a message that the operation requires input
parameters.
Use the set airport code subflow
49.Return to thegetDeltaFlightsflow in Anypoint Studio.
50.Add aFlow Referencecomponent after the GET /deltaListener.
51.In the Flow Reference properties view, set the flow name and display name to
setCode.
© Copyright 2023 salesforce.com, inc. All rights reserved. 172
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
se the Transform Message component to pass a parameter to the
U
web service
52.Add aTransform Messagecomponent after the Flow Referencecomponent.
53.Change its display name toPass code.
54.In the Pass code properties view, look at the input and output sections.
55.Drag the code variable in the input section to the destination element in the output
section.
© Copyright 2023 salesforce.com, inc. All rights reserved. 173
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
56.Save the file to redeploy the application.
57.In Advanced REST Client, make another request; you should now only see flights to
LAX.
© Copyright 2023 salesforce.com, inc. All rights reserved. 174
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 3-4: Transform data from multiple services to a
canonical format
In this walkthrough, you will transform the JSON returned from the American and United
web services and the SOAP returned from the Delta web service to the same format. You
will:
● Define a metadata type for the Flight Java class.
● Transform the results from RESTful and SOAP web service calls to a collection of
Flight objects.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 175
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review Flight.java
1. Return toapdev-flights-wsin Anypoint Studio.
2. Return toFlight.java in src/main/javaand reviewthe file.
3. Close the file.
Change the American flow to return Java Flight objects instead of
JSON
4. Return togetAmericanFlightsin implementation.xml.
5. Add aTransform Messagecomponent to the end of theflow.
6. Add aLoggerat the end of the flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 176
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. Change the name of the Transform Message component toJSON to [Flight].
8. In the Transform Message properties view, look at the input section; you should see
metadata already defined.
9. In the output section of the Transform Message properties view, click theDefine
metadatalink.
10.In the Select metadata type dialog box, select theuser-defined Flight_pojo.
© Copyright 2023 salesforce.com, inc. All rights reserved. 177
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.SelectWrap element in a collectionin the lower-left corner.
12.ClickSelect; you should now see output metadata inthe output section of the
Transform Message properties view.
13.Map fields (except ID and totalSeats) by dragging them from the input section and
dropping them on the corresponding field in the output section.
14.Double-click theairlineNamefield in the output section.
© Copyright 2023 salesforce.com, inc. All rights reserved. 178
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.In the generated DataWeave expression, change the airlineName value from null to
"American".
Test the application
16.Save the file to redeploy the project.
17.In Advanced REST Client, change the URL and make a request to
http://localhost:8081/american; you should see a representationof a collection of
Java objects.
Debug the application
18.Return to Anypoint Studio.
19.Stop the project.
20.Add a breakpoint to theGet flightsoperation ingetAmericanFlights.
21.Debug the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 179
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
22.In Advanced REST Client, make another request tohttp://localhost:8081/american.
23.In the Mule Debugger, step to theTransform Messagecomponent and examine the
payload.
24.Step to theLoggerand look at the payload; it shouldbe a collection of Flight
objects.
25.Step through the rest of the application and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 180
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change the United airline flows to return Java Flight objects instead of
JSON
26.Return togetUnitedFlightsinimplementation.xml.
27.Add aTransform Messagecomponent at the end of theflow.
28.Change the name of the Transform Message component toJSON to [Flight].
29.Add aLoggerto the end of the flow.
30.In the Transform Message properties view, look at the input section; you should see
metadata already defined.
31.In the output section of the Transform Message properties view, click theDefine
metadatalink.
32.In the Select metadata type dialog box, select theuser-defined Flight_pojo.
33.SelectWrap element in a collectionin the lower-leftcorner.
© Copyright 2023 salesforce.com, inc. All rights reserved. 181
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
34.ClickSelect; you should now see output metadata in the output section of the
Transform Message properties view.
35.Map fields by dragging them from the input section and dropping them on the
corresponding field in the output section.
Debug the application
36.Add a breakpoint to the Transform Message component.
37.Save the file to redeploy the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 182
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
38.In Advanced REST Client, change the URL to make a request to
http://localhost:8081/united.
39.In the Mule Debugger, examine the payload.
40.Step to the Logger and look at the payload; it should be a collection of Flight objects.
41.Step through the rest of the application and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 183
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change the Delta flow to return Java Flight objects
42.Return togeDeltaFlightsinimplementation.xml.
43.Change the name of theSOAP to JSONTransform Messagecomponent toSOAP to
[Flight].
44.Add a Logger to the end of the flow.
45.Look at the input section in the SOAP to [Flight] Transform Message properties view;
you should see metadata already defined.
46.In the output section of the Transform Message properties view, click theDefine
metadatalink.
47.In the Select metadata type dialog box, select the user-definedFlight_pojo.
48.SelectWrap element in a collectionin the lower-leftcorner.
49.ClickSelect; you should now see output metadata inthe output section of the
Transform Message properties view.
© Copyright 2023 salesforce.com, inc. All rights reserved. 184
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
50.Map the fields by dragging them from the input section and dropping them on the
corresponding field in the output section.
Debug the application
51.Add a breakpoint to theSOAP to [Flight]TransformMessage component.
52.Save the file to redeploy the project.
53.In Advanced REST Client, change the URL to make a request to
http://localhost:8081/delta.
54.In the Mule Debugger, examine the payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 185
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
55.Step to the Logger and look at the payload; it should be a collection of Flight objects.
56.Step through the rest of the application and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 186
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Module 4: Controlling event flow
At the end of this module, you should be able to:
● Multicast events.
● Route events based on conditions.
● Validate events.
© Copyright 2023 salesforce.com, inc. All rights reserved. 187
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 4-1: Multicast an event
In this walkthrough, you create a flow that calls each of the three airline services and
combines the results. You will:
● Use a Scatter-Gather router to concurrently call all three flight services.
● Use DataWeave to flatten multiple collections into one collection.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a new flow
1. Return toimplementation.xmlin theapdev-flights-wsproject in Anypoint Studio.
2. From the Mule Palette, drag anHTTP Listenerand dropit at the top of the canvas.
3. Change the flow name togetAllAirlineFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 188
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. In the Listener properties view, set the display name toGET /flights.
5. Ensure the connector configuration is set to the existingHTTP_Listener_config.
6. Set the path to /flights and the allowed methods toGET.
Browse the flow control elements in the Mule Palette
7. In the Core section of the Mule Palette, locate theFlow Controlelements.
© Copyright 2023 salesforce.com, inc. All rights reserved. 189
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add a Scatter-Gather to call all three airline services
8. Drag aScatter-Gatherflow control element from the Mule Palette and drop it in the
process section ofgetAllAirlineFlights.
9. Add three parallelFlow Referencecomponents to theScatter-Gather router.
10.In the first Flow Reference properties view, set the flow name and display name to
getAmericanFlights.
11.Set the flow name and display name of the second Flow Reference to
getUnitedFlights.
12.Set the flow name and display name of the third Flow Reference togetDeltaFlights.
13.Add aLoggerafter theScatter-Gather.
© Copyright 2023 salesforce.com, inc. All rights reserved. 190
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review the metadata for the Scatter-Gather output
14.In the Logger properties view, explore the input payload structure in the DataSense
Explorer.
Debug the application
15.Add abreakpointto theScatter-Gather.
16.Add abreakpointto theLogger.
17.Save the file to redeploy the project in debug mode.
18.In Advanced REST Client, change the URL to make a request to
http://localhost:8081/flights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 191
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.In the Mule Debugger, step through the application; you should step through each
of the airline flows.
20.Stop at the Logger after the Scatter-Gather and explore the payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 192
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Drill down into one of the objects in the payload.
22.Step through the rest of the application and switch perspectives.
23.Return to Advanced REST Client and review the response; you should get a 500
Server Error with a message that the object could not be serialized.
Flatten the combined results
24.Return to Anypoint Studio.
25.In getAllAirlineFlights, add aTransform Messagecomponentbefore theLogger.
© Copyright 2023 salesforce.com, inc. All rights reserved. 193
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
26.Change the display name to flatten to[Flight].
27.In the input section of the Transform Message properties view, review the payload
data structure.
28.In the expression section, use the DataWeave flatten function to flatten the
collection of objects into a single collection.
© Copyright 2023 salesforce.com, inc. All rights reserved. 194
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
29.Save the file to redeploy the project.
30.In Advanced REST Client, make the same request tohttp://localhost:8081/flights.
31.In the Mule Debugger, clickResumeuntil you are stoppedat the Logger at the end
of the Scatter-Gather; you should see the payload is now one ArrayList of Flights.
32.Step through the rest of the application and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 195
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 4-2: Route events based on conditions
In this walkthrough, you create a flow to route events to either the American, United, Delta,
or get all airline flows based on the value of an airline query parameter. You will:
● Use a Choice router.
● Use DataWeave expressions to set the router paths.
● Route all flight requests through the router.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Look at possible airline values specified in the API
1. Return to theapdev-flights-wsproject in AnypointStudio.
© Copyright 2023 salesforce.com, inc. All rights reserved. 196
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
2. Return tomua-flights-api.ramlinsrc/main/resources/api.
3. Locate the airline query parameter and its possible values.
Create a new flow
4. Return toimplementation.xml.
5. Drag aFlowscope from the Mule Palette and drop itat the top of the canvas above
all the other flows.
6. Change the name of the flow togetFlights.
7. Move theGET /flightsHTTP Listener fromgetAllAirlineFlightsto the source section
ofgetFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 197
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add a Choice router
8. Drag a Choice flow control element from the Mule Palette and drop it in the process
section ofgetFlights.
9. Add three parallelFlow Referencecomponents to theChoice router.
10.Add aFlow Referencecomponent to the default branchof the router.
11.In the first Flow Reference properties view, set the flow name and display name to
getAmericanFlights.
12.Set the flow names and display names for the other two Flow References to
getUnitedFlightsandgetDeltaFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 198
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
13.For the Flow Reference in the default branch, set the flow name and display name to
getAllAirlineFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 199
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Store the airline query parameter in a variable
14.Add aSet Variabletransformer before the Choice router.
15.In the Set Variable properties view, set the name and display name toairline.
16.Switch the value field toexpression modethen setits value to a query parameter
calledairline.
message.attributes.queryParams.airline
© Copyright 2023 salesforce.com, inc. All rights reserved. 200
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Configure the Choice router
17.In the Choice router getAmericanFlights flow reference branch, click theWhen
scope.
18.In the When properties view, switch the value field toexpression mode, and then
add an expression to check if the airline variable is equal toamerican.
vars.airline == "american"
19.Set a similar expression for theUnitedroute, routingto it whenvars.airlineis equal
tounited.
© Copyright 2023 salesforce.com, inc. All rights reserved. 201
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
20.Set a similar expression for theDeltaroute, routing to it whenvars.airlineis equal to
delta.
© Copyright 2023 salesforce.com, inc. All rights reserved. 202
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Route all requests through the router
21.Add aFlow Referenceto the flow before the Choicerouter.
22.Set the flow name and display name tosetCode.
23.IngetAmericanFlights, delete theHTTP ListenerandthesetCodeFlow Reference.
24.IngetUnitedFlights, delete theHTTP ListenerandthesetCodeFlow Reference.
25.IngetDeltaFlights, delete theHTTP Listenerand thesetCodeFlow Reference.
© Copyright 2023 salesforce.com, inc. All rights reserved. 203
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Return JSON from the flow
26.In the getFlights flow, add aTransform Messagecomponentafter theChoicerouter.
27.Change its display name to[Flight] to JSON.
28.Add aLoggerat the end of the flow.
29.In the Transform Message properties view, change the output type to
application/json and set the expression to payload.
Debug the application
30.Add abreakpointto the airlineSet Variabletransformerat the beginning of
getFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 204
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
31.Add abreakpointto the[Flight] to JSONTransform Message component after the
Choicerouter.
32.Save the file to redeploy the project in debug mode.
33.In Advanced REST Client, make a request tohttp://localhost:8081/flights.
34.In the Mule Debugger, step through the application; you should see the Choice
router pass the event to the default branch.
35.Resume to the Transform Message component after the Choice router; the payload
should be an ArrayList of Flight objects
36.Step to theLogger; the payload should be JSON.
37.Step to the end of the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 205
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
38.Return to Advanced REST Client; you should see American, United, and Delta flights
to SFO (the default airport code).
39.Add an airline query parameter set toamericanandsend the request:
http://localhost:8081/flights?airline=american.
© Copyright 2023 salesforce.com, inc. All rights reserved. 206
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
40.In the Mule Debugger, step through the application; you should see the event
passed to getAmericanFlights and then back to getFlights.
41.Return to Advanced REST Client; you should see onlyAmerican flights to SFO
returned.
© Copyright 2023 salesforce.com, inc. All rights reserved. 207
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
42.Change the airline tounitedand add a second query parameter code set toLAX:
http://localhost:8081/flights?airline=united&code=LAX.
43.Send the request.
44.In the Mule Debugger, step through the application; the event should be routed to
the United branch.
45.Return to Advanced REST Client; you should see onlyUnited flights to LAXare
returned.
© Copyright 2023 salesforce.com, inc. All rights reserved. 208
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
46.Change the airline todeltaand the code toPDX:
http://localhost:8081/flights?airline=delta&code=PDX.
47.Send the request.
48.In the Mule Debugger, step through the application; the event should be routed to
the Delta branch.
49.Return to Advanced REST Client; you should see onlyDelta flights to PDXare
returned.
© Copyright 2023 salesforce.com, inc. All rights reserved. 209
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: This JSON structure does not match that specified in the API: mua-flights-api.raml in
src/main/resources/api. The datashould, of course,be transformed so the response from
the API matches this specification – but we are going to hold off doing that right now so
that the scenario stays simpler for the error handling module (there is one less error to
handle at the beginning).
Test the application with a destination that has no flights
50.Remove the airline parameter and set the code toFOO:
http://localhost:8081/flights?code=FOO.
51.Send the request.
52.In the Mule Debugger, step through the application; you should see multiple errors.
53.Return to Advanced REST Client; you should get a 500 Server Response and an
exception.
© Copyright 2023 salesforce.com, inc. All rights reserved. 210
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 4-3: Validate events
In this walkthrough, you use a validator to check if a query parameter called code with a
value of SFO, LAX, CLE, PDX, or PDF is sent with a request and to throw an error if it is not.
You will:
● Add the Validation module to a project.
● Use an Is true validator to check if a query parameter called code with a value of
SFO, LAX, CLE, PDX, or PDF is sent with a request.
● Return a custom error message if the condition is not met.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 211
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add the Validation module to the project
1. Switch to the Mule Design perspective and return toimplementation.xml.
2. In the Mule Palette, selectAdd Modules.
3. Select theValidationmodule in the right side ofthe Mule Palette and drag and drop
it into the left side.
4. If you get a Select module version dialog box, select the latest version and clickAdd.
Use the Is true validator to check for a valid destination code
5. Locate theIs truevalidator in the right side ofthe Mule Palette.
© Copyright 2023 salesforce.com, inc. All rights reserved. 212
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
6. Drag and drop theIs truevalidator after thesetCodeFlow Reference in the
getFlightsflow.
7. In theIs trueproperties view, set the display nametoIs validdestination.
8. Change the expression fromFalse (Default)toExpression.
9. Add aDataWeave expressionto check if the code variableis one of the five
destination codes.
#[['SFO','LAX','CLE','PDX','PDF'] contains vars.code]
NOTE: You can copy this expression from the coursesnippets.txt file.
10.Using expression mode, set the error message to Invalid destination followed by the
provided code.
'Invalid destination' ++ ' ' ++ (vars.code default ' ')
© Copyright 2023 salesforce.com, inc. All rights reserved. 213
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: You can copy this expression from the course snippets.txt file.
Debug the application
11.Save the file and wait for the application to redeploy.
12.In Advanced REST Client, change the code to make a request to
http://localhost:8081/flights?code=CLE.
13.In the Mule Debugger, step past the validator; you should see the code is valid and
application execution steps to the Choice router.
© Copyright 2023 salesforce.com, inc. All rights reserved. 214
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.Resume through the rest of the application.
15.In Advanced REST Client, you should see flights for CLE.
16.Change the code and make a request tohttp://localhost:8081/flights?code=FOO.
17.In the Mule Debugger, attempt to step past the validator; you should see an error.
© Copyright 2023 salesforce.com, inc. All rights reserved. 215
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
18.Resume through the rest of the application; you should see your Invalid destination
message in the console.
19.Return to Advanced REST Client; you should get a 500 Server Error with your Invalid
destination message.
NOTE: You will catch this error and send a JSON responsewith a different status code in the
next module.
20.Remove the code and make a request tohttp://localhost:8081/flights.
21.In the Mule Debugger, step past the validator; you should not get any errors.
© Copyright 2023 salesforce.com, inc. All rights reserved. 216
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
22.Resume through the rest of the application.
23.Return to Advanced REST Client; you should get a 200 response with all airline flights
to SFO.
24.Return to Anypoint Studio and switch to the Mule Design perspective.
© Copyright 2023 salesforce.com, inc. All rights reserved. 217
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Remove the default destination
25.Locate thesetCodesubflow.
26.In the Set Variable properties view, review the default value.
27.Remove the default value from the value.
Debug the application
28.Save the file to redeploy the project.
29.In Advanced REST Client, make another request tohttp://localhost:8081/flights.
30.In the Mule Debugger, attempt to step past the validator; you should now get an
error.
31.Resume through the rest of the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 218
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
32.Return to Advanced REST Client; you should get a 500 Server Error with your Invalid
destination message.
NOTE: You will catch this error and send a JSON responsewith a different status code in the
next module.
33.Return to Anypoint Studio and stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 219
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Module 5: Handling errors
At the end of this module, you should be able to:
● Handle messaging errors at the application, flow, and processor level.
● Handle different types of errors, including custom errors.
● Use different error scopes to either handle an error and continue execution of the
parent flow or propagate an error to the parent flow.
● Set the success and error response settings for an HTTP Listener.
● Set reconnection strategies for system errors.
© Copyright 2023 salesforce.com, inc. All rights reserved. 220
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-1: Explore default error handling
In this walkthrough, you get familiar with the three errors you will learn to handle in this
module. You will:
● Explore information about different types of errors in the Mule Debugger and the
console.
● Review the default error handling behavior.
● Review and modify the error response settings for an HTTP Listener.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a connectivity error
1. Return toapdev-flights-wsin Anypoint Studio.
2. Return toconfig.yaml.
3. Change thedelta.wsdlproperty from/delta?wsdlto/deltas?wsdl.
© Copyright 2023 salesforce.com, inc. All rights reserved. 221
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. Save the file.
5. Return toimplementation.xmland debug the project.
6. If you get an Errors in Workspace dialog box, clickProceed.
Review a validation error in the Mule Debugger and console
7. In Advanced REST Client, add a code and make a request to
http://localhost:8081/flights?code=FOO.
© Copyright 2023 salesforce.com, inc. All rights reserved. 222
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. In the Mule Debugger, step to where the error is thrown and examine the error
object; you should see an error description, errorType, and other properties.
9. Step through the rest of the application and review the error information logged in
the console.
10.In Advanced REST Client, locate the response status code, status reason, and body;
you should see a 500 status code, a status reason of Server Error, and a response
body equal to the error description.
© Copyright 2023 salesforce.com, inc. All rights reserved. 223
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review a connectivity error in the Mule Debugger and console
11.Add an airline and change the code to make a request to
http://localhost:8081/flights?airline=delta&code=PDX.
12.In the Mule Debugger, step to where the error is thrown and review the error object.
13.Step again and review the error information logged in the console.
14.Step through the rest of the application.
15.Return to Advanced REST Client; you should see a 500 Server Error with the error
description.
Review a bad request error in the Mule Debugger and console
16.Change the airline to make a request to
http://localhost:8081/flights?airline=american&code=PDX.
© Copyright 2023 salesforce.com, inc. All rights reserved. 224
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
17.In the Mule Debugger, step to where the error is thrown and review the error object.
18.Step through the rest of the application.
19.Review the error information logged in the console.
20.Return to Advanced REST Client; you should see a 500 Server Error with the error
description.
21.Return to Anypoint Studio and switch to the Mule Design perspective.
22.Stop the project.
Review the default error response settings for an HTTP Listener
23.Navigate to the properties view for theGET /flightsListener in getFlights.
24.Select theResponsestab.
© Copyright 2023 salesforce.com, inc. All rights reserved. 225
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
25.Locate theError Responsesection and review the default settings for the body,
status code, and reason phrase.
Remove the default error response settings for the HTTP Listener
26.Select and cut the body expression (so it has no value, but you can paste it back
later).
Test the application
27.Save the file, run the project, and proceed through any errors in the workspace.
© Copyright 2023 salesforce.com, inc. All rights reserved. 226
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
28.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=PDX; you should get the same
response.
Modify the default error response settings for the HTTP Listener
29.Return to Anypoint Studio.
30.Return to the Responses tab in the properties view for the GET /flights Listener.
31.In the error response body, paste back the original value.
output
text/plain --- error.description
32.Change the output type of the error response toapplication/jsonand display the
error.errorType.
output
application/json --- error.errorType
NOTE: Ensure the error response body is in expressionmode.
33.Set the error response status code to 400.
© Copyright 2023 salesforce.com, inc. All rights reserved. 227
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
34.Save the file to redeploy the application.
35.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=PDX;you should get the new
status code and reason and the response body should be the errorType object.
36.Look at the error namespace and identifier.
37.Change the airline to make a request to
http://localhost:8081/flights?airline=delta&code=PDX.
38.Look at the error namespace and identifier.
© Copyright 2023 salesforce.com, inc. All rights reserved. 228
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
39.Change the code to make a request to
http://localhost:8081/flights?airline=delta&code=FOO.
40.Look at the namespace and identifier.
© Copyright 2023 salesforce.com, inc. All rights reserved. 229
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Return the default error response settings for the HTTP Listener
41.Return to Anypoint Studio.
42.Return to theResponsestab in the properties viewfor the GET /flights Listener.
43.Change the error response output type back totext/plainand display the
error.description.
output
text/plain --- error.description
44.Remove the status code.
Test the application
45.Save the file to redeploy the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 230
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
46.In Advanced REST Client, change the airline and code to make a request to
http://localhost:8081/flights?airline=american&code=PDX;you should get the 500
Server Error again with the plain text error description.
47.Return to Anypoint Studio.
48.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 231
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-2: Handle errors at the application level
In this walkthrough, you create a default error handler for the application. You will:
● Create a global error handler in an application.
● Configure an application to use a global default error handler.
● Explore the differences between the On Error Continue and On Error Propagate
scopes.
● Modify the default error response settings for an HTTP Listener.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Browse the error handling elements in the Mule Palette
1. Return toglobal.xmland switch to the Message Flowview.
2. In the Core section of the Mule Palette, locate the Error Handling elements.
© Copyright 2023 salesforce.com, inc. All rights reserved. 232
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a global error handler with an On Error Continue scope
3. Drag out an Error Handler element and drop it in the canvas ofglobal.xml.
4. Drag out an On Error Continue scope and drop it inglobalError_Handler.
5. In the On Error Continue properties view, click thesearchbutton for type.
6. In the dropdown menu that appears, selectANY.
© Copyright 2023 salesforce.com, inc. All rights reserved. 233
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Set the payload in the error handler to a JSON message
7. Add aTransform Messagecomponent to theOn ErrorContinue.
8. Set theTransform Messagedisplay name toerror.description.
9. In the Transform Message properties view, change the output type to
application/json.
10.Add a message property to the output JSON and give it a value of the
error.description.
Set a default error handler for the application
11.Switch to the Global Elements view ofglobal.xml.
12.ClickCreate.
13.In the Choose Global Type dialog box, selectGlobalConfigurations > Configuration
and clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 234
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.In the Global Element Properties dialog box, set the default error handler to
globalError_Handlerand clickOK.
15.Switch to theMessage Flowview.
Review the default response settings for an HTTP Listener
16.Return toimplementation.xml.
17.Navigate to the properties view for theGET /flightsListener ingetFlights.
18.Select theResponsestab.
19.Locate the Response section (not the Error Response section) and review the default
settings for the body, status code, and reason phrase.
© Copyright 2023 salesforce.com, inc. All rights reserved. 235
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
20.Locate the Error Response section and review the default settings for the body,
status code, and reason phrase.
Test the On Error Continue behavior
21.Save all files, debug the project, and proceed through any errors in the workspace.
22.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=PDX.
23.In the Mule Debugger, step through the application until the event is passed to
globalError_Handler.
© Copyright 2023 salesforce.com, inc. All rights reserved. 236
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
24.Expand the error object and review the exception.
25.Step again; the event should be passed back to getFlights, which continues to
execute after the error occurs.
26.Review the payload and note the absence of an error object.
© Copyright 2023 salesforce.com, inc. All rights reserved. 237
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.Resume through the rest of the application.
28.Return to Advanced REST Client; you should see a 200 OK response with the
response body equal to the payload value set in the error handler.
Change the default error handler to use an On Error Propagate scope
29.Return to Anypoint Studio and switch to the Mule Design perspective.
30.Return toglobal.xml.
© Copyright 2023 salesforce.com, inc. All rights reserved. 238
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
31.Drag anOn Error Propagatescope from the Mule Palette and drop it to the right or
left of theOn Error Continueto add it toglobalError_Handler.
32.In theOn Error Propagateproperties view, set thetype toANY.
33.Move theTransform Messagecomponent from theOn ErrorContinueto theOn
Error Propagate.
34.Delete the On Error Continue scope.
Test the On Error Propagate behavior
35.Save the file to redeploy the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 239
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
36.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=PDX.
37.Step through the application until the event is passed to globalError_Handler.
38.Look at the error object in the Mule Debugger; it should be the same as before.
39.Step again; the error is propagated up to the getFlights parent flow.
40.Look at the payload and the error object in the Mule Debugger.
41.Step twice more; the error is handled by the application’s default error handler again.
42.Look at the payload and the error object in the Mule Debugger.
43.Resume through the rest of the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 240
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
44.Return to Advanced REST Client; you should get a 500 Server Error response with the
response body equal to the plain text error description – not the payload.
45.Return to Anypoint Studio and switch to the Mule Design perspective.
46.Stop the project.
Modify the default error response settings for the HTTP Listener
47.Return toimplementation.xml.
48.Navigate to theResponsestab in the properties viewfor the GET /flights Listener.
49.Change the error response body to return the payload instead of error.description.
payload
© Copyright 2023 salesforce.com, inc. All rights reserved. 241
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
50.Save the file, run the project, and proceed through any errors in the workspace.
51.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=PDX;you should now get the
message that you set in the error handler.
NOTE: You will handle this error differently in alater walkthrough, so it does not return a
server error. It is a valid request; there are just no American flights to PDX.
52.Change the airline to make a request to
http://localhost:8081/flights?airline=delta&code=PDX;the error is handled by the
same default handler.
53.Return to Anypoint Studio.
© Copyright 2023 salesforce.com, inc. All rights reserved. 242
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-3: Handle specific types of errors
In this walkthrough, you continue to work with the application’s default error handler. You
will:
● Review the possible types of errors thrown by different processors.
● Create error handler scopes to handle different error types.
Starting file
I f you did not complete the previous walkthrough, you can get a starting file h ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Review the possible types of errors thrown by a Web Service Consumer
operation
1. Return toimplementation.xml.
2. Navigate to the properties view for the Get flights Consume operation in
getDeltaFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 243
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Select theError Mappingtab.
4. Click theAdd new mappingbutton and review (but don’tselect!) theWSCerror
types.
Review the possible types of errors thrown by a REST Connector
operator
5. Navigate to the properties view for theGet flightsoperation ingetAmericanFlights.
6. Select theError Mappingtab.
7. Click theAdd new mappingbutton, and review (butdon’t select!) the
AMERICAN-FLIGHTS-APIerror types.
© Copyright 2023 salesforce.com, inc. All rights reserved. 244
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review the possible types of errors thrown by a Validator operation
8. Navigate to the properties view for theIs truevalidatoringetFlights.
9. Select theError Mappingtab.
10.Click theAdd new mappingbutton and locate (but don’tselect!) theVALIDATION
error type.
© Copyright 2023 salesforce.com, inc. All rights reserved. 245
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add a second error handler scope to catch Web Service Consumer
connectivity errors
11.Return toglobal.xml.
12.Add a secondOn Error PropagatetoglobalError_Handler.
13.If necessary, drag and drop it so it is the first scope inside the error handler.
14.Return to the coursesnippets.txtfile and copy theexpression for the error type.
15.Return toglobal.xmlin Anypoint Studio.
© Copyright 2023 salesforce.com, inc. All rights reserved. 246
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
16.In the properties view for the newOn Error Propagate, set the error type by pasting
the expression you copied.
WSC:CONNECTIVITY, WSC:INVALID_WSDL
17.Add a Transform Message component to the newOn ErrorPropagateand set its
display name toData unavailable.
© Copyright 2023 salesforce.com, inc. All rights reserved. 247
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
18.In the Transform Message properties view, change the output type to
application/json.
19.Add a message property to the output JSON and give it a value ofData unavailable.
Try later.
20.For development purposes, concatenate theerror.descriptionto the message; be
sure to use the auto-completion menu.
21.Coerce the variable to a String.
Test the application
22.Save the file to redeploy the project.
23.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=delta&code=PDX;you should now get a 500
Server Error response with your new Data unavailable message.
© Copyright 2023 salesforce.com, inc. All rights reserved. 248
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
24.Change the code to make a request to
http://localhost:8081/flights?airline=delta&code=FOO; you should still get a 500
Server Error response with the Invalid destination JSON message.
NOTE: This should also not be a server error, buteither a 4XX bad request or a 200 OK with
an appropriate message. You will handle this error differently in the next walkthrough.
25.Return to Anypoint Studio.
26.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 249
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-4: Handle errors at the flow level
In this walkthrough, you add multiple error handlers to a flow. You will:
● Add error handlers to a flow.
● Test the behavior of errors thrown in a flow and by a child flow.
● Compare On Error Propagate and On Error Continue scopes in a flow.
● Set an HTTP status code in an error handler and modify an HTTP Listener to return it.
© Copyright 2023 salesforce.com, inc. All rights reserved. 250
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Add an On Error Propagate error handler to a flow
1. Return toimplementation.xml.
2. Expand theError handlingsection of thegetFlightsflow.
3. Add anOn Error Propagatescope.
4. Set the error type toANYso it will initially catchboth the validation and American
flights errors.
© Copyright 2023 salesforce.com, inc. All rights reserved. 251
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Set the payload in the error handler to the error description
5. Add aTransform Messagecomponent to the scope and set the display name toNo
flights.
6. In the Transform Message properties view, set the payload to aJSON message
propertyequal to the stringNo flights toand concatenatethe code variable.
7. Coerce the variable to aString.
Set the HTTP status code in the error handler to 200
8. Add a Set Variable transformer to theOn Error Propagate.
9. In the Set Variable properties view, set the display name and name tohttpStatus.
10.Set the value to200.
Set the HTTP Listener error response status code to use a variable
11.Navigate to theResponsestab in the properties viewfor the GET /flights Listener.
© Copyright 2023 salesforce.com, inc. All rights reserved. 252
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
12.Use expression mode to change the error response status code (not the response
status code!) to an expression that sets it equal to the value of an httpStatus variable
with a default value of500.
vars.httpStatus
default
500
Test the flow’s On Error Propagate with an error in the flow
13.Save the file, debug the project, and proceed through any errors in the workspace.
14.In Advanced REST Client, change the airline to make a request to
http://localhost:8081/flights?airline=american&code=FOO.
15.In the Mule Debugger, step until the event is passed to the flow’s error handler.
16.Step through the rest of the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 253
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
17.Return to Advanced REST Client; you should get the 200 status code and the JSON
message.
© Copyright 2023 salesforce.com, inc. All rights reserved. 254
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the flow’s On Error Propagate with an error in a child flow
18.In Advanced REST Client, change the code to make a request to
http://localhost:8081/flights?airline=american&code=PDX.
19.Step until the event is passed to the globalError_Handler.
20.Step until the error is passed to the parent flow’s error handler.
© Copyright 2023 salesforce.com, inc. All rights reserved. 255
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Step through the rest of the application.
22.Return to Advanced REST Client; you should get the 200 status code and the JSON
error message.
23.Return to Anypoint Studio and switch to the Mule design perspective.
Specify the type of error to be handled by the flow’s error handler
24.Navigate to the properties view for theOn Error PropagateingetFlights.
25.Change the type fromANYtoAMERICAN-FLIGHTS-API:BAD_REQUEST.
© Copyright 2023 salesforce.com, inc. All rights reserved. 256
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
26.Save the file to redeploy the project.
27.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=PDX.
28.In the Mule Debugger, step through the application; the error should still be handled
by globalError_Handler and then the getFlights flow error handler.
29.In Advanced REST Client, change the code to make a request to
http://localhost:8081/flights?airline=american&code=FOO.
30.In the Mule Debugger, step through the application; you should get a 500 Server
Error and no message because the error is not handled by the getFlights flow error
handler or by globalError_handler.
© Copyright 2023 salesforce.com, inc. All rights reserved. 257
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
31.Return to Anypoint Studio and switch to the Mule Design perspective.
32.Stop the project.
33.Navigate to theResponsestab in the properties viewfor theGET /flightsListener.
34.Review theerror response body(not the response body!)and ensure you know why
you got the last response for
http://localhost:8081/flights?airline=american&code=FOO.
Use an On Error Continue error handler in a flow
35.Add anOn Error Continuescope togetFlights.
36.In the On Error Continue properties view, set the type to
VALIDATION:INVALID_BOOLEAN.
37.Add aTransform Messagecomponent to the scope andset the display name to
error.description.
38.In the Transform Message properties view, set the payload to aJSON message
property equal to the error.description.
© Copyright 2023 salesforce.com, inc. All rights reserved. 258
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
39.Add aSet Variabletransformer to the On Error Continuescope.
40.Set the display name and name to httpStatus and set the value to 400.
Test the application
41.Save the file, run the project, and proceed through any errors in the workspace.
42.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=FOO;you should get a 200
response and the invalid destination message again – not the 400 response.
© Copyright 2023 salesforce.com, inc. All rights reserved. 259
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Set the HTTP Listener response status code
43.Return to Anypoint Studio.
44.Navigate to theResponsestab in the properties viewfor the GET /flights Listener.
45.Use expression mode to set theresponse status code(not the error response status
code!) to an expression that sets it equal to the value of an httpStatus variable with a
default value of 200.
vars.httpStatus
default
200
Test the application
46.Save the file to redeploy the project.
47.In Advanced REST Client, make another request to
http://localhost:8081/flights?airline=american&code=FOO;you should now get the
400 response.
Test the application to see what happens with the Scatter-Gather
48.In Advanced REST Client, change the code and make a request to
http://localhost:8081/flights?airline=american&code=PDX;you should get a 200
response and no flights to PDX.
© Copyright 2023 salesforce.com, inc. All rights reserved. 260
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
49.Change the airline to make a request to
http://localhost:8081/flights?airline=united&code=PDX; you should get United
flights to PDX.
50.Remove the airline to make a request tohttp://localhost:8081/flights?code=PDX;
you should get flights to PDX because United has flights, but you get none.
51.Return to Anypoint Studio.
52.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 261
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-5: Handle errors at the processor level
In this walkthrough, you work with the Scatter-Gather in getAllAirlineFlights so that it
correctly returns results when one but not all airlines have flights. You will:
● Wrap the Flow Reference in each branch of a Scatter-Gather in a Try scope.
● Use an On Error Continue scope in each Try scope error handler to provide a valid
response so flow execution can continue.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 262
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application when a Scatter-Gather branch has an error
1. Return toimplementation.xmlin Anypoint Studio.
2. Debug the project and proceed through any errors in the workspace.
3. In Advanced REST Client, make another request to
http://localhost:8081/flights?code=PDX.
4. Return to the Mule Debugger and step through the application until you see a
routing exception.
5. Step through the rest of the application.
6. Return to Advanced REST client, you should get the 500 Server Error that there were
exceptions in routes 0 and 2.
© Copyright 2023 salesforce.com, inc. All rights reserved. 263
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. Return to Anypoint Studio and switch to the Mule Design perspective.
Place each Flow Reference in the Scatter-Gather in a Try scope
8. Locate thegetAllAirlineFlightsflow.
9. Drag aTryscope from the Mule Palette and drop itin theScatter-Gatherbefore the
getAmericanFlightsFlow Reference.
10.Drag thegetAmericanFlightsFlow Reference into theTryscope.
© Copyright 2023 salesforce.com, inc. All rights reserved. 264
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.AddTryscopes to the other two routes of the Scatter-Gather.
12.Move the getUnitedFlights Flow Reference into one of the Try scopes and the
getDeltaFlights Flow Reference into the other.
Add an error handler to each branch that passes through the error
message
13.Expand the error handling section of the first Try scope.
14.Add anOn Error Continuescope and set the types oferrors it handles to ANY.
15.Repeat these steps to add the same error handler to the two other Try scopes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 265
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
16.Save the file to redeploy the project.
17.In Advanced REST Client, make another request to
http://localhost:8081/flights?code=PDX.
18.In the Mule Debugger, resume to the Logger after the Scatter-Gather in
getAllAirlineFlights.
19.ExpandPayload; you should see three flights (fromUnited) and two error messages.
© Copyright 2023 salesforce.com, inc. All rights reserved. 266
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
20.Step through the rest of the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 267
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Return to Advanced REST Client; you should see United flights and error messages.
Modify each error handler to set the payload to an empty array
22.Return to Anypoint Studio and switch to the Mule Design perspective.
23.In getAllAirlineFlights, add aTransform Messagecomponentto one of the On Error
Continue scopes.
24.Set the display name to[].
© Copyright 2023 salesforce.com, inc. All rights reserved. 268
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
25.In the Transform Message properties view, set the payload to an empty array.
26.Repeat the steps to add the same Transform Message component to the two other
error handlers.
© Copyright 2023 salesforce.com, inc. All rights reserved. 269
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
© Copyright 2023 salesforce.com, inc. All rights reserved. 270
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
27.Save the file to redeploy the project.
28.In Advanced REST Client, make another request to
http://localhost:8081/flights?code=PDX.
29.In the Mule Debugger, resume to the Logger after the Scatter-Gather in
getAllAirlineFlights.
30.ExpandPayload; you should now see the three flightsand no error messages.
31.Step through the rest of the application.
© Copyright 2023 salesforce.com, inc. All rights reserved. 271
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
32.Return to Advanced REST Client; you should now only see the three flights.
33.Return to Anypoint Studio and switch to the Mule Design perspective.
34.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 272
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-6: Map an error to a custom error type
In this walkthrough, you map the Validation error to a custom error type for the application.
You will:
● Map a module error to a custom error type for an application.
● Create an event handler for the custom error type.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Map a validation module error to a custom error type
1. Return toimplementation.xml.
2. Navigate to the properties view for the validator ingetFlights.
3. Select theError Mappingtab.
© Copyright 2023 salesforce.com, inc. All rights reserved. 273
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. Click theAdd new mappingbutton.
5. Select theVALIDATION:INVALID_BOOLEANerror type.
6. Leave the namespace of the custom error to map to set toAPP.
7. Set the identifier toINVALID_DESTINATION.
8. PressEnter; you should see your new error mapping.
© Copyright 2023 salesforce.com, inc. All rights reserved. 274
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change the existing validation error handler to catch the new custom
type
9. Navigate to the properties view for the getFlights validation On Error Continue error
handler.
10.Change the type fromVALIDATION:INVALID_BOOLEANtothe new
APP:INVALID_DESTINATIONthat should now appear inthe type drop-down menu.
Test the application
11.Save the file, run the project, and proceed through any errors in the workspace.
12.In Advanced REST Client, change the code and make a request to
http://localhost:8081/flights?code=FOO; you shouldstill get a 400 response with
the invalid destination error.
© Copyright 2023 salesforce.com, inc. All rights reserved. 275
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Move the American error handler into the American flow
13.Collapse thegetAllAirlineFlightsandsetCodeflows.
14.Move theAMERICAN-FLIGHTS-APIerror scope fromgetFlightsinto
getAmericanFlights.
Move the error handler to the global error handler
NOTE: The following steps have instructions to makechanges in the XML. If you prefer, you
can copy and paste the error handler to move it between files and then delete the original.
© Copyright 2023 salesforce.com, inc. All rights reserved. 276
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.Right-click the validationOn Error Continueerror handler in getFlights and selectGo
to XML.
16.Select and cut theAPP:INVALID_DESTINATIONon-error-continue.
17.Delete the remaining empty error-handler tag set.
18.Return toglobal.xml.
19.Right-click theglobalError_Handlerand selectGoto XML.
20.Place the cursor on a new line inside and at the start of theglobalError_Handler
error-handler.
© Copyright 2023 salesforce.com, inc. All rights reserved. 277
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Paste the on-error-continue you cut to the clipboard.
NOTE: If you are prompted to regenerate ID values,clickYes.
22.Switch back to the Message Flow view; you should see the
APP:INVALID_DESTINATION handler.
© Copyright 2023 salesforce.com, inc. All rights reserved. 278
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Return to implementation.xml and switch to the Message Flow view; you should no
longer see an error handler in getFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 279
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
24.Save the files to redeploy the project.
25.In Advanced REST Client, make another request to
http://localhost:8081/flights?code=FOO; you shouldstill get a 400 response with
the invalid destination error.
© Copyright 2023 salesforce.com, inc. All rights reserved. 280
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
26.Change the code and make a request tohttp://localhost:8081/flights?code=PDX;
you should still get only United flights to PDX.
© Copyright 2023 salesforce.com, inc. All rights reserved. 281
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-7: Review and integrate with APIkit error handlers
In this walkthrough, you connect the application’s implementation to the interface and
ensure all the error handling works. You will:
● Review the error handlers generated by APIkit.
● Review settings for the APIkit Router and HTTP Listener in the APIkit generated
interface.
● Connect the implementation to the interface and test the error handling behavior.
● Modify implementation error scopes so they work with the APIkit generated
interface.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 282
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Review APIkit generated error handlers
1. Return toapdev-flights-wsin Anypoint Studio.
2. Return tointerface.xml.
3. Review the error handling section inmua-flights-api-main.
4. Review the types of errors handled by each error handler scope.
5. Navigate to the Transform Message properties view for the first error handling scope.
6. Review the expression that sets the payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 283
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. Use the output dropdown menu to change the output toVariable – httpStatus.
8. Review the expression that sets an httpStatus variable; you should see that for a bad
request the httpStatus variable is set to 400.
Review settings for the APIkit Router
9. Navigate to the properties view for the APIkit Router in mua-flights-api-main.
10.Click theEditbutton next to router configuration.
© Copyright 2023 salesforce.com, inc. All rights reserved. 284
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.In the Global Element Properties dialog box, locate the HTTP status var name
setting; you should seehttpStatus.
12.ClickOK.
Review settings for the HTTP Listener
13.Navigate to theResponsestab in the properties viewfor the HTTP Listener in
mua-flights-api-main.
© Copyright 2023 salesforce.com, inc. All rights reserved. 285
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.Review the response body and status code.
15.Review the error response body and status code.
Connect the interface to the implementation
16.In interface.xml, locate theget:\flightsflow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 286
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
17.Review the default transformation in this flow.
18.Delete theTransform Messagecomponent.
19.Add aFlow Referencecomponent to the flow.
20.In the Flow Reference properties view, set the flow name and display name to
getFlights.
21.Return toimplementation.xml.
22.Delete theGET /flightsListener in getFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 287
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Save all the files to redeploy the application.
Test the application
24.In Advanced REST Client, make another request to
http://localhost:8081/flights?code=PDX; you shouldget a 404 response with a no
listener message.
© Copyright 2023 salesforce.com, inc. All rights reserved. 288
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
25.Add/apito the URL and make a request to
http://localhost:8081/api/flights?code=PDX; you shouldget the United flights to
PDX as before.
26.Change the code to make a request tohttp://localhost:8081/api/flights?code=FOO;
you should now get a 400 Bad Request response instead of your custom message.
27.Remove the code to make a request tohttp://localhost:8081/api/flights;you should
now get your custom error message.
© Copyright 2023 salesforce.com, inc. All rights reserved. 289
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
28.Add the airline and code to make a request to
http://localhost:8081/api/flights?airline=american&code=PDX;you should now get
a 200 response with the bad request description in the error message.
Review the API
29.Return to Anypoint Studio and stop the project.
30.Return tomua-flights-api.ramland review the code;you should see the code query
parameter is not required but it has allowed values enumerated.
© Copyright 2023 salesforce.com, inc. All rights reserved. 290
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
31.Return tointerface.xml.
32.Add a breakpoint to the APIkit Router inmua-flights-api-main.
33.Debug the project and proceed through any errors in the workspace.
34.In Advanced REST Client, make another request to
http://localhost:8081/api/flights?airline=american&code=PDX.
35.In the Mule Debugger, watch the payload and variables and step through the
application.
36.Step back to the APIkit router.
37.Review the exception, the payload, and the variables.
© Copyright 2023 salesforce.com, inc. All rights reserved. 291
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
38.Resume through the rest of the application.
39.In Advanced REST Client, change the code to make a request to
http://localhost:8081/api/flights?airline=american&code=FOO.
40.In the Mule Debugger, step through the application; the APIkit router should
immediately throw an error.
© Copyright 2023 salesforce.com, inc. All rights reserved. 292
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
41.Step again; you should see that the error is handled by theAPIKIT:BAD_REQUEST
handler.
42.Resume through the rest of the application.
43.In Advanced REST Client, remove the airline and code to make a request to
http://localhost:8081/api/flights.
44.In the Mule Debugger, step through the application; the validator should throw an
error and execution should not return to the APIkit router.
45.Return to Advanced REST Client; you should get a 400 response with the custom
message.
© Copyright 2023 salesforce.com, inc. All rights reserved. 293
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: If you had specified the code query parameter to be required in the RAML file from
which the interface was generated, the APIkit router would catch this immediately and
respond with a 400 Bad Request response. The event would never get to the validator in
your implementation.
Change the American flights error scope to On Error Continue
46.Return to Anypoint Studio and switch to the Mule Design perspective.
47.Return toimplementation.xml.
48.Locate the error handler in thegetAmericanFlightsflow.
49.Right-click it and selectGo To XML.
50.Change theon-error-propagatestart and end tags inthegetAmericaFlightsflow to
on-error-continue.
© Copyright 2023 salesforce.com, inc. All rights reserved. 294
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
51.Change the doc:name in the start tag toOn Error Continue.
52.Switch back to the Message Flow view; you should now see an On Error Continue.
Change the global default error scopes to On Error Continue
53.Return toglobal.xml.
54.Review the types of error handler scopes.
55.Right-click theWSCerror handler and selectGo ToXML.
56.Change the fouron-error-propagate start and endtagstoon-error-continue.
57.Change the doc:names in both start tags toOn ErrorContinue.
© Copyright 2023 salesforce.com, inc. All rights reserved. 295
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
58.Switch back to the Message Flow view; you should now see both are On Error
Continue scopes.
Set the HTTP status code for the On Error Continue scopes so you do
not get 200
59.Add aSet Variabletransformer to theWSCerror handler.
60.In the Set Variable properties view, set the display name and name tohttpStatus.
61.Set the value to500.
62.Copy theSet Variabletransformer and add it to theANYerror scope.
© Copyright 2023 salesforce.com, inc. All rights reserved. 296
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
63.Save the files to redeploy the project.
64.In Advanced REST Client, add the airline and code to make a request to
http://localhost:8081/api/flights?airline=american&code=PDX.
65.In the Mule Debugger, step through the application; the application now does not
return to the APIkit router.
66.Return to Advanced REST Client; you should now get a 200 response with the No
flights to PDX message.
© Copyright 2023 salesforce.com, inc. All rights reserved. 297
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
67.In Advanced REST Client, change the airline to make a request to
http://localhost:8081/api/flights?airline=delta&code=PDX.
68.In the Mule Debugger, step through the application.
69.Return to Advanced REST Client; you should now get the 500 response with the data
unavailable message.
70.Return to Anypoint Studio and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 298
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 5-8: Set a reconnection strategy for a connector
In this walkthrough, you will:
● Set a reconnection strategy for the Web Service Consumer connector.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Set a reconnection strategy for a connector
1. Return toglobal.xmlin Anypoint Studio.
2. Switch to theGlobal Elementsview.
3. Double-click theWeb Service Consumer Config.
4. In the Global Element Properties dialog box, select theAdvancedtab in the second
tab bar.
5. Select theReconnectioncheckbox.
6. Change the reconnection strategy tostandard.
© Copyright 2023 salesforce.com, inc. All rights reserved. 299
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. Review the default frequency and attempts.
8. ClickOK.
9. Save the file.
© Copyright 2023 salesforce.com, inc. All rights reserved. 300
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Module 6: Writing DataWeave transformations
At the end of this module, you should be able to:
● Write DataWeave expressions for basic XML, JSON, and Java transformations.
● Write DataWeave transformations for complex data structures with repeated elements.
● Define and use global and local variables and functions.
● Use DataWeave functions.
● Coerce and format strings, numbers, and dates.
● Define and use custom data types.
© Copyright 2023 salesforce.com, inc. All rights reserved. 301
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
● Use flow results in DataWeave expressions.
● Store DataWeave scripts in external files.
© Copyright 2023 salesforce.com, inc. All rights reserved. 302
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 6-1: Create transformations with the Transform
Message component
In this walkthrough, you create a new flow that receives flight POST requests that you will
use as the input for writing transformations in the next several walkthroughs. You will:
● Create a new flow that receives POST requests of JSON flight objects.
● Customize propagated metadata.
● Add sample data and use live preview.
● Create a second transformation that stores the output in a variable.
● Save a DataWeave script in an external file.
● Review DataWeave script errors.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 303
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a new flow that receives POST requests and returns the payload
as Java
1. In theapdev-flights-wsMule project, return toconfig.yaml.
2. Change thedelta.wsdlproperty from/deltas?wsdlto/delta?wsdl.
3. Return toimplementation.xml.
4. Right-click in the canvas and selectCollapse All.
5. Drag a Transform Message component from the Mule Palette to the bottom of the
canvas; a new flow should be created.
6. Change the name of the flow topostFlight.
7. In the Transform Message properties view, set the expression topayload.
NOTE: If you see a metadata propagation error on theTransform Message, you can proceed
normally.
8. Add abreakpointto theTransform Messagecomponent.
9. Add aLoggerto the flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 304
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
10.Return tointerface.xml.
11.Remove the breakpoint from theAPIkit Routerinmua-flights-api-main.
12.Locate thepost:\flights:application\json:mua-flights-api-configflow.
13.Delete theTransform Messagecomponent and replaceit with a Flow Reference.
14.In the Flow Reference properties view, set the flow name and display name to
postFlight.
15.Save the files to redeploy the project in debug mode.
Post a flight to the flow
16.Openflight-example.jsoninsrc/test/resources.
17.Copy the code and close the file.
18.In Advanced REST Client, change the method to POST and remove any query
parameters.
19.Add a request header calledContent-Typeand set itequal toapplication/json.
20.Set the request body to the value you copied fromflight-example.json.
21.Make the request tohttp://localhost:8081/api/flights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 305
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
22.In the Mule Debugger, expandAttributesand locatethecontent-typeheader.
23.Review the payload; you should see it has a mediaType of application/json.
© Copyright 2023 salesforce.com, inc. All rights reserved. 306
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
24.Step to theLogger; you should see the payload now has a mediaType of
application/java and is a LinkedHashMap.
25.Step to the end of the application and switch perspectives.
Customize the transformation input metadata propagated from the
API specification
26.Examine the input section of the Transform Message properties view; note the field
for the optional ID property.
© Copyright 2023 salesforce.com, inc. All rights reserved. 307
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.Return tointerface.xml.
28.In the postFlight Flow Reference properties view, select theMetadatatab.
29.Click theAdd metadatabutton.
30.Ensure the dropdown menu is set toInput: Payloadand click theEditbutton.
31.In theSelectmetadata type dialog box, selectflight_jsonand clickSelect.
32.On the Metadata tab, click theSet metadatabutton.
33.In the Custom metadata dialog box, clickCustomize.
© Copyright 2023 salesforce.com, inc. All rights reserved. 308
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
34.In the Custom Metadata dialog box, locate and expand the expected payload on the
Input Metadata tab; note the absence of the optional ID property.
35.ClickOK.
36.Save and close the file.
37.In the Transform Message properties view for the transformation in postFlight; you
should now see updated metadata for the input.
38.Openapplication-types.xmlinsrc/main/resources.
© Copyright 2023 salesforce.com, inc. All rights reserved. 309
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
39.Review the enrichment elements forflight_json.
40.Close the file.
Preview sample data and sample output
41.In the input section of the Transform Message properties view, right-click the
payload and selectEdit Sample Data; you should seea new tab calledpayloadand
it should contain the sample input of type JSON.
42.Click thePreviewbutton; you should see a new previewsection and it should
contain the sample output of type Java.
NOTE: If sample data doesn't automatically appearin the preview section, click theCreate
required sample datato execute the preview link.
43.Click theSource Onlybutton to the left of thePreviewbutton.
© Copyright 2023 salesforce.com, inc. All rights reserved. 310
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Locate the new sample data file
44.In the Package Explorer, locate the newsample_datafolderinsrc/test/resources.
45.Openjson.json.
46.Review the code and close the file.
Create a second transformation with the same component
47.In the Transform Message properties view, click theAdd new targetbutton.
48.In the Selection dialog box, change the output toVariable.
© Copyright 2023 salesforce.com, inc. All rights reserved. 311
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
49.Set Variable name toDWoutput.
50.ClickOK.
51.Click the dropdown menu for the output; you should see that you can switch
between the two transformations.
52.For the new transformation, set the output type to json and set the expression to
payload.
Test the application
53.Save the file to redeploy the project in debug mode.
© Copyright 2023 salesforce.com, inc. All rights reserved. 312
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
54.In Advanced REST Client, post the same request tohttp://localhost:8081/api/flights.
55.In the Mule Debugger, step to theLogger.
56.ReviewPayload; it should be Java as before.
57.ExpandVariables; you should see the new DWoutputvariable.
58.Step through the rest of the application and switch perspectives.
Review the Transform Message XML code
59.Right-click theTransform Messagecomponent and selectGo to XML.
60.Locate and review the code for both DataWeave transformations.
61.Switch back to theMessage Flowview.
© Copyright 2023 salesforce.com, inc. All rights reserved. 313
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Save a DataWeave script to an external file
62.In the Transform Message Properties view, make sure the payload output expression
is selected.
63.Click theEdit current targetbutton (the pencil)above the code.
64.In the Selection dialog box, change the source code selection frominlinetofile.
65.Set the file name tojson_flight_playground.
66.ClickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 314
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Locate and review the code that uses an external DataWeave script
67.Switch toConfiguration XMLview.
68.Locate the new code for the transformation inpostFlight.
69.In the Package Explorer, expandsrc/main/resources.
70.Openjson_flight_playground.dwl.
71.Review and then close the file.
72.Return toMessage Flowview in implementation.xml.
© Copyright 2023 salesforce.com, inc. All rights reserved. 315
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change the output type to XML and review errors
73.In the Transform Message properties view, select theVariable – DWoutputoutput.
74.Change the output type fromapplication/jsontoapplication/xml.
75.Locate the warning icons indicating that there is a problem.
NOTE: If you do not see the warnings, click the Previewbutton.
76.Mouse over the icon located to the left of the code; you should see a message that
there was an exception trying to output the second root<flightCode>.
77.Click the icon above the code; aList of warningsand errorsdialog box should open.
78.Select and review the first issue.
79.ClickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 316
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: You will learn how to successfully transform to XML in the next walkthrough.
Test the application
80.Save the file to redeploy the project in debug mode.
81.In Advanced REST Client, post the same request tohttp://localhost:8081/api/flights.
82.In the Mule Debugger, step once; you should get an error.
83.Review the error information; you should see there is a DataWeave error when trying
to output the second root.
84.Step to the end of the application and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 317
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 6-2: Transform basic JSON, Java, and XML data
structures
In this walkthrough, you continue to work with the JSON flight data posted to the flow. You
will:
● Write scripts to transform the JSON payload to various JSON and Java structures.
● Write scripts to transform the JSON payload to various XML structures.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Write expressions to transform JSON to various Java structures
1. Return to the Transform Message properties view for the transformation in
postFlight.
2. In the output dropdown menu, make sure thepayloadoutput expressionis
selected.
3. Change the output type fromjavatojson.
© Copyright 2023 salesforce.com, inc. All rights reserved. 318
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. Type a period after payload and double-clickprice(or navigate with row keysand
pressEnter) in the auto-completion menu.
5. Look at the preview.
NOTE: Click the Preview button (Cmd+Shift+PorCtrl+Shift+P)if the preview section is not
displayed.
6. Change the output type fromjsontojava.
7. Change the DataWeave expression todata: payload.price.
© Copyright 2023 salesforce.com, inc. All rights reserved. 319
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. Change the output type fromjavatojson.
9. Change the DataWeave expression to data: payload.
10.Change the output type fromjsontojava.
11.Change the DataWeave expression todata: {}.
© Copyright 2023 salesforce.com, inc. All rights reserved. 320
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
12.Add a field called hub and set it toMUA.
13.Change the output type fromjavatojson.
14.Add a field called code and use auto-completion to set it to thetoAirportCode
property of the payload.
15.Add a field calledairlineand set it to the airlineproperty of the payload.
Write an expression to output data as XML
16.In the output dropdown menu, selectVariable – DWoutput.
17.Change the DataWeave expression todata: payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 321
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
18.Look at the preview; you should now see XML.
NOTE: Click the Preview button (Cmd+Shift+PorCtrl+Shift+P)if the preview section is not
displayed.
19.In the output dropdown menu, selectPayload.
20.Copy the DataWeave expression.
21.Switch back toVariable – DWoutputand replace theDataWeave expression with
the one you just copied.
22.Modify the expression so the code and airline properties are child elements of a new
element calledflight.
© Copyright 2023 salesforce.com, inc. All rights reserved. 322
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Modify the expression so the airline is an attribute of the flight element.
Debug the application
24.In the Logger properties view, set the message to the value of theDWoutput
variable.
25.Save the file to redeploy the project in debug mode.
26.In Advanced REST Client, post the same request tohttp://localhost:8081/api/flights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 323
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.In the Mule Debugger, step to the Logger; you should see the transformed JSON
payload and that the DWoutput variable has a mediaType of application/xml.
28.Step through the application and switch perspectives.
29.Look at the Logger output in the console; you should see the XML.
© Copyright 2023 salesforce.com, inc. All rights reserved. 324
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 6-3: Transform complex data structures with arrays
In this walkthrough, you create a new flow that allows multiple flights to be posted to it, so
you have more complex data with which to work. You will:
● Create a new flow that receives POST requests of a JSON array of flight objects.
● Transform a JSON array of objects to DataWeave, JSON, and Java.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a new flow that receives POST requests of a JSON array of flight
objects
1. Return toimplementation.xml.
2. Drag out anHTTP Listenerfrom the Mule Palette tothe bottom of the canvas.
3. Change the flow name topostMultipleFlights.
4. In the HTTP Listener properties view, set the display name toPOST /multipleflights.
5. Ensure the connector configuration is set to the existing HTTP_Listener_config.
© Copyright 2023 salesforce.com, inc. All rights reserved. 325
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
6. Set the path to/multipleflightsand set the allowed methods to POST.
NOTE: You are bypassing the APIkit router becausea corresponding resource/method pair
is not defined in the API.
7. Add aTransform Messagecomponent to the flow.
8. In the Transform Message properties view, set the expression topayload.
9. Add aLoggerto the flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 326
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add input metadata for the transformation
10.In the Transform Message properties view, clickDefinemetadatain the input
section.
11.In the Select metadata type dialog box, selectflights_jsonand clickSelect.
12.In the Transform Message Properties view, you should now see metadata for the
input.
© Copyright 2023 salesforce.com, inc. All rights reserved. 327
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Preview sample data and sample output
13.In the input section, right-click the payload and selectEdit Sample Datato get
sample input data.
14.Click thePreviewbutton to get sample output data.
NOTE: If sample data doesn't automatically appearin the preview section, click theCreate
required sample data to executepreview link.
15.Look at the preview section; the sample output should be an array of objects.
© Copyright 2023 salesforce.com, inc. All rights reserved. 328
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
16.Change the output type toapplication/dw.
Return values for the first object in the collection
17.Change the DataWeave expression topayload[0].
© Copyright 2023 salesforce.com, inc. All rights reserved. 329
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
18.Change the DataWeave expression topayload[0].price.
19.Change the DataWeave expression topayload[0].*price.
Return collections of values
20.Change the DataWeave expression to return a collection of all the prices.
© Copyright 2023 salesforce.com, inc. All rights reserved. 330
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Change the DataWeave expression to payload.price; you should get the same result.
22.Change the DataWeave expression to return a collection of prices and available
seats.
[payload.price, payload.emptySeats]
Use the map function to return object collections with different data
structures
23.Change the DataWeave expression topayload map $.
© Copyright 2023 salesforce.com, inc. All rights reserved. 331
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
24.Change the DataWeave expression to set a property calledflightfor each object that
is equal to its index value in the collection.
25.Change the DataWeave expression to create a property calleddestinationfor each
object that is equal to the value of the toAirportCode field in the payload collection.
© Copyright 2023 salesforce.com, inc. All rights reserved. 332
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
26.Change the DataWeave expression to dynamically add each of the properties
present on the payload objects.
27.Remove the first flight property assignment.
28.Change the DataWeave expression so the name of each object isflight+indexand
you getflight0andflight1.
© Copyright 2023 salesforce.com, inc. All rights reserved. 333
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Use explicit named parameters with the map function
29.Change the map function so that it uses two parameters calledobjectandindex
and set the field name to just the index value.
30.Change the DataWeave expression so the name of each object isflight+indexand
you get flight0 and flight1.
© Copyright 2023 salesforce.com, inc. All rights reserved. 334
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: If you want to test the application, changethe output type to application/json and
then in Advanced REST Client, make a request to http://localhost:8081/multipleflights and
replace the request body with JSON from the flights-example.json file.
Change the expression to output different data types
31.Change the DataWeave expression output type fromapplication/dwto
application/json.
© Copyright 2023 salesforce.com, inc. All rights reserved. 335
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
32.Change the output type toapplication/java.
33.Change the output type toapplication/xml; you shouldget issues displayed.
© Copyright 2023 salesforce.com, inc. All rights reserved. 336
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
34.Click the warning icon above the code, review the issues, then click OK.
35.Change the DataWeave expression to create a root node calledflights; you should
still get issues.
36.Click the warning icon above the code, review the issues, then clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 337
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
© Copyright 2023 salesforce.com, inc. All rights reserved. 338
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 6-4: Transform to and from XML with repeated
elements
In this walkthrough, you continue to work with the JSON data for multiple flights posted to
the flow. You will:
● Transform a JSON array of objects to XML.
● Replace sample data associated with a transformation.
● Transform XML with repeated elements to different data types.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Transform the JSON array of objects to XML
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 339
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
2. Change the expression to map each item in the input array to an XML element.
flights: {(payload map (object,index) -> {
'flight$(index)': object
}
)}
3. Look at the preview; the JSON should be transformed to XML successfully.
4. Modify the expression so the flights object has a single property calledflight.
© Copyright 2023 salesforce.com, inc. All rights reserved. 340
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change the input metadata to XML
5. In the input section, right-click thepayloadandselectClear Metadata.
6. Click theDefine metadatalink.
7. In the Select metadata type dialog box, selectflights_xmland clickSelect.
8. In the Transform Message Properties view, you should now see new metadata for
the input.
© Copyright 2023 salesforce.com, inc. All rights reserved. 341
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Preview sample data and sample output
9. In the input section, click thexon the payload tabto close it.
10.In the Close Sample Data dialog box, clickClose taband Keep file.
© Copyright 2023 salesforce.com, inc. All rights reserved. 342
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.Right-click the payload and selectEdit Sample Datato get sample input data.
12.Look at the XML sample payload.
13.Look at thesample_datafolder insrc/test/resources.
14.Review the transformation expression; you should see an issue.
© Copyright 2023 salesforce.com, inc. All rights reserved. 343
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: You may see more than one issue. If so, onlyone should be an error, the rest
warnings.
15.Look at the error then clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 344
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Transform XML with repeated elements to a different XML structure
16.In the input section, click on theContexttab tolook at the payload metadata.
17.Change the DataWeave expression so that the map is iterating overpayload..return.
18.Change the DataWeave expression so that the map is iterating over the repeated
return elements of the input.
© Copyright 2023 salesforce.com, inc. All rights reserved. 345
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.Change the DataWeave expression to return flight elements withdestandprice
elements that map to the corresponding destination and price input values.
NOTE: If you want to test the application with AdvancedREST Client, be sure to change the
content-type header to application/xml and replace the request body with XML from the
flights-example.xml file.
Change the expression to output different data types
20.Change the output type fromapplication/xmltoapplication/dw.
© Copyright 2023 salesforce.com, inc. All rights reserved. 346
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Change the output type toapplication/json.
22.Change the output type toapplication/java.
23.In the DataWeave expression, remove the{( )}aroundthe map expression.
© Copyright 2023 salesforce.com, inc. All rights reserved. 347
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
24.In the DataWeave expression, remove the flight property; you should get an object
consisting of an array of five objects.
© Copyright 2023 salesforce.com, inc. All rights reserved. 348
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 6-5: Define and use variables and functions
In this walkthrough, you continue to work with the DataWeave transformation in
postMultipleFlights. You will:
● Define and use a global constant.
● Define and use a global variable that is equal to a lambda expression.
● Define and use a lambda expression assigned to a variable as a function.
● Define and use a local variable.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Define and use a global constant
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
© Copyright 2023 salesforce.com, inc. All rights reserved. 349
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
2. Change the output type toapplication/dw.
3. In the header, define a global variable callednumSeatsthat is equal to400.
var numSeats = 400
4. In the body, add atotalSeatsproperty that is equalto thenumSeatsconstant.
totalSeats: numSeats
5. Look at the preview.
6. Comment out the variable declaration in the header.
//var numSeats = 400
© Copyright 2023 salesforce.com, inc. All rights reserved. 350
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Define and use a global variable that is equal to a lambda expression
that maps to a constant
7. In the header, define a global variable callednumSeatsthat is equal to a lambda
expression with an input parameterx equal to 400.
8. Inside the expression, setnumSeatstox.
var numSeats = (x=400) -> x
9. Add parentheses after numSeats in the totalSeats property assignment.
totalSeats: numSeats()
10.Look at the preview.
Add a plane property to the output
11.Add aplane propertyto the DataWeave expression equalto the value of the input
planeType values.
12.Look at the values of plane type in the preview.
© Copyright 2023 salesforce.com, inc. All rights reserved. 351
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Define and use a global variable that is that is equal to a lambda
expression with input parameters
13.Comment out thenumSeatsvariable declaration in theheader.
14.In the header, define a global variable callednumSeatsthat is equal to a lambda
expression with an input parameter calledplaneTypeof typeString.
var numSeats = (planeType: String) ->
15.Inside the expression, add an if/else block that checks to see if planeType contains
the string 737 and sets numSeats to150 or 300otherwise.
16.Change thetotalSeatsproperty assignment to passthe object’s planeType property
tonumSeats.
totalSeats: numSeats(object.planeType)
17.Force the argument to a String.
© Copyright 2023 salesforce.com, inc. All rights reserved. 352
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
totalSeats: numSeats(object.planeType as String)
18.Look at the preview; you should see values of150and300.
19.Surround the variable declaration in the header with/*and*/to comment it out.
Define and use a lambda expression assigned to a variable as a
function
20.In the header, use thefunkeyword to define a functioncalledgetNumSeatswith a
parameter calledplaneTypeof typeString.
fun getNumSeats(planeType: String)
21.Copy theif/elseexpression in the numSeats declaration.
22.Set thegetNumSeatsfunction equal to theif/elseexpression.
fun getNumSeats(planeType: String) =
if (planeType contains('737'))
© Copyright 2023 salesforce.com, inc. All rights reserved. 353
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
150
else
300
23.In the body, change the totalSeats property to be equal to the result of the
getNumSeats function.
totalSeats: getNumSeats(object.planeType
as
String)
24.Look at the preview.
Create and use a local variable
25.Add adostatement around the definition of thegetNumSeatsfunction.
© Copyright 2023 salesforce.com, inc. All rights reserved. 354
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
26.At the beginning of thedoscope, define a local variable calledmaxSeatsthat is
equal to the if/else block.
27.After the if/else block, add a body separator then set the body of the do scope to the
maxSeatslocal variable.
28.Modify the indentation to your liking.
29.Look at the preview.
© Copyright 2023 salesforce.com, inc. All rights reserved. 355
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 6-6: Coerce and format strings, numbers, and dates
In this walkthrough, you continue to work with the XML flights data posted to the
postMultipleFlights flow. You will:
● Coerce data types.
● Format strings, numbers, and dates.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Format a string
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
2. Use the upper function to return the plane value in uppercase.
3. Coerce the argument to a String.
© Copyright 2023 salesforce.com, inc. All rights reserved. 356
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
plane: upper(object.planeType as String)
4. Look at the preview.
Coerce a string to a number
5. In the preview, look at the data type of the prices; you should see that they are
strings.
6. Change the DataWeave expression to use theaskeywordto return the prices as
numbers.
price: object.price as Number,
7. Look at the preview.
8. Change the output type fromapplication/dwtoapplication/java.
9. Click theTexttab and look at the preview; you shouldsee the prices are now either
integer (Integer objects) or non-integer (Double objects).
© Copyright 2023 salesforce.com, inc. All rights reserved. 357
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
10.Click theTreetab.
Coerce a string to a specific type of number object
11.Change the DataWeave expression to use the class metadata key to coerce the prices
to java.lang.Double objects.
price: object.price as Number {class:"java.lang.Double"},
12.Look at the preview; you should see the prices are now all Double objects
(non-integers).
13.Change the output type from application/java back to application/dw.
© Copyright 2023 salesforce.com, inc. All rights reserved. 358
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Format a number
14.Remove the coercion of the price to a java.lang.Double.
15.Coerce the price to a String and use the format schema property to format the prices
to zero decimal places.
price: object.price as Number as String {format: "###"},
16.Look at the preview; the prices should now be formatted.
17.Change the DataWeave expression to format the prices to two decimal places.
price: object.price as Number as String {format: "###.##"},
18.Look at the preview.
© Copyright 2023 salesforce.com, inc. All rights reserved. 359
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.Change the DataWeave expression to format the prices to two minimal decimal
places.
price: object.price as Number as String {format: "###.00"},
20.Look at the preview; all the prices should now be formatted to two decimal places.
NOTE: If you are not a Java programmer, you may wantto look at the Java documentation
for the DecimalFormatter class to review documentation on DecimalFormat patterns.
https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html
Coerce a string to a date
21.Add a date field to the return object.
date: object.departureDate
22.Look at the preview; you should see the date property is a String.
© Copyright 2023 salesforce.com, inc. All rights reserved. 360
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Change the DataWeave expression to use the as operator to convert departureDate
to a date object; you should get issues displayed.
date: object.departureDate as Date
24.Look at the errors then clickOK.
25.Look at the format of the dates in the preview.
26.Change the DataWeave expression to use the format schema property to specify the
pattern of the input date strings.
© Copyright 2023 salesforce.com, inc. All rights reserved. 361
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
date: object.departureDate as Date {format: "yyyy/MM/dd"}
NOTE: If you are not a Java programmer, you may wantto look at the Java documentation
for the DateTimeFormatter class to review documentation on pattern letters.
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
27.Look at the preview; you should see date is now a Date object.
Format a date
28.Use the as operator to convert the dates to strings, which can then be formatted.
ate: object.departureDate as Date {format: "yyyy/MM/dd"} as
d
String
29.Look at the preview section; the date is again a String – but with a different format.
30.Use the format schema property with any pattern letters and characters to format
the date strings.
date: object.departureDate as Date {format: "yyyy/MM/dd"} as
String {format: "MMM dd, yyyy"}
© Copyright 2023 salesforce.com, inc. All rights reserved. 362
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
31.Look at the preview; the dates should now be formatted according to the pattern.
© Copyright 2023 salesforce.com, inc. All rights reserved. 363
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 6-7: Define and use custom data types
In this walkthrough, you continue to work with the flight JSON posted to the flow. You will:
● Define and use custom data types.
● Transform objects to POJOs.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Define a custom data type
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
2. Select and cut the string formatting expression for the prices.
© Copyright 2023 salesforce.com, inc. All rights reserved. 364
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. In the header section of the expression, define a custom data type calledCurrency.
4. Set it equal to the value you cut.
type Currency = String {format: "###.00"}
Use a custom data type
5. In the DataWeave expression, set the price to be of typecurrency.
price: object.price as Number as Currency,
6. Look at the preview; the prices should still be formatted as strings to two decimal
places.
© Copyright 2023 salesforce.com, inc. All rights reserved. 365
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Transform objects to POJOs
7. Open theFlight.javaclass in the project's src/main/javafolder, look at the names of
the properties then close the file.
8. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
9. In the header section of the expression, define a custom data type calledFlightthat
is of typecom.mulesoft.training.Flight.
type Flight = Object {class: "com.mulesoft.training.Flight"}
10.In the DataWeave expression, set the map objects to be of typeFlight.
© Copyright 2023 salesforce.com, inc. All rights reserved. 366
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.Look at the preview.
NOTE: Click the Preview button (Cmd+Shift+PorCtrl+Shift+P)if the preview section is not
displayed.
12.Change the output type from application/dw to application/java.
13.Look at the issues you get then clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 367
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.Change the name of the dest key to destination.
destination: object.destination,
15.Change the other keys to match the names of theFlightclassproperties:
● plane to planeType
● date to departureDate
16.Comment out thetotalSeatsproperty.
17.Look at the preview.
© Copyright 2023 salesforce.com, inc. All rights reserved. 368
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: If you want to test the application with AdvancedREST Client, be sure to change the
content-type header to application/xml and replace the request body with XML from the
flights-example.xml file.
Walkthrough 6-8: Use DataWeave functions
In this walkthrough, you continue to work with the flights JSON posted to the flow. You will:
● Use functions in the Core module that are imported automatically.
© Copyright 2023 salesforce.com, inc. All rights reserved. 369
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
● Replace data values using pattern matching.
● Order data, remove duplicate data, and filter data.
● Use a function in another module that you must explicitly import into a script to use.
● Dasherize data.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Use the replace function
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
2. Change the output type fromapplication/javatoapplication/dw.
3. Look at the preview and see thatBoeingis misspelled.
© Copyright 2023 salesforce.com, inc. All rights reserved. 370
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. For planeType, use the replace function to replace the stringBoingwithBoeing.
planeType: upper(replace(object.planeType,/(Boing)/) with
"Boeing"),
5. Look at the preview;Boeingshould now be spelledcorrectly.
Use the dasherize function in the Strings module
6. For planeType, replace the upper function with the dasherize function.
planeType: dasherize(replace(object.planeType,/(Boing)/) with
"Boeing"),
7. Look at the error you get then clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 371
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. In the script header, add an import statement to import dasherize from the Strings
module.
import
dasherize
from
dw::core::Strings
9. Look at the preview.
© Copyright 2023 salesforce.com, inc. All rights reserved. 372
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Use the orderBy function
10.In the preview section, look at the flight prices; the flights are not ordered by price.
11.Add parentheses around the value of the flights root node then use the orderBy
function to order the flights by price.
orderBy $.price
12.Look at the preview; the flights should now be ordered by price.
13.Look at the three $283 flights; there is a duplicate and they are not ordered by date.
14.Change the DataWeave expression to sort flights by date and then by price.
orderBy $.departureDate orderBy $.price
© Copyright 2023 salesforce.com, inc. All rights reserved. 373
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.Look at the preview; the flights should now be ordered by price and flights of the
same price should be sorted by date.
Remove duplicate data
16.Use the distinctBy function to first remove any duplicate objects.
distinctBy $ orderBy $.departureDate
orderBy $.price
17.Look at the preview; you should now see only two $283 flights to PDX instead of
three.
18.Add an availableSeats field that is equal to the emptySeats field and coerce it to a
number.
© Copyright 2023 salesforce.com, inc. All rights reserved. 374
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
availableSeats: object.emptySeats as Number
19.Look at the preview; you should get three $283 flights to PDX again.
Use the filter function
20.In the preview, look at the values of theavailableSeatsproperties; you should see
one is equal to zero.
21.Use the filter function to remove any objects that have availableSeats equal to 0.
istinctBy $ filter ($.availableSeats !=0)
d
orderBy $.departureDate orderBy $.price
22.Look at the preview; you should no longer get the flight that had no available seats.
© Copyright 2023 salesforce.com, inc. All rights reserved. 375
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
© Copyright 2023 salesforce.com, inc. All rights reserved. 376
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Module 7: Triggering flows
At the end of this module, you should be able to:
● Read and write files.
● Trigger flows when files are added or updated.
● Trigger flows when new records are added to a database table.
● Schedule flows to run at a certain time or frequency.
● Persist and share data in flows using the Object Store.
● Publish and consume JMS messages.
© Copyright 2023 salesforce.com, inc. All rights reserved. 377
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 7-1: Trigger a flow when a new file is added to a
directory
In this walkthrough, you load data from a local CSV file when a new file is added to a
directory. You will:
● Add and configure a File listener to watch an input directory.
● Restrict the type of file read.
● Rename and move the processed files.
Starting file
If you did not complete walkthrough 2-4, you can get a starting file h
ere. This file is also
located in the solutions folder of the student files ZIP located in the Course Resources.
Locate files and folders
1. In your computer’s file browser, return to the student files for the course.
2. Open the resources folder and locate the accounts.csv file and the input and output
folders.
© Copyright 2023 salesforce.com, inc. All rights reserved. 378
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Leave this folder open.
Add the File module to the project
4. Return to Anypoint Studio and open theapdev-examplesproject.
5. Openaccounts.xml.
6. In the Mule Palette, selectAdd Modules.
7. Select the File connector in the right side of the Mule Palette and drag and drop it
into the left side.
8. If you get a Select module version dialog box, select the latest version and clickAdd.
© Copyright 2023 salesforce.com, inc. All rights reserved. 379
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a flow that monitors a location for new files
9. Locate theOn New or Updated Fileoperation for the File connector in the right side
of the Mule Palette and drag and drop it at the top of the canvas to create a new
flow.
10.Rename the flow togetCSVaccounts.
Configure the File connector
11.Openglobal.xmland switch to the Global Elementsview.
12.ClickCreate.
13.In the Choose Global Type dialog box, selectConnectorConfiguration > File Config
and clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 380
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.In the Global Element Properties dialog box, select theConnectioncheckbox then
click the browse button next to Working Directory.
15.Browse to the student files folder for the course.
16.Select the resources folder and clickOpen.
17.Select and cut the value of the working directory that got populated and replace it
with a property${file.accountsDir}.
18.In the Global Element Properties dialog box, clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 381
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.Openconfig.yamlinsrc/main/resources.
20.Create a new propertyfile.accountsDirand set itequal to the value you cut.
NOTE: Users on all OSs, including Windows, shoulduse forward slash characters as shown.
Configure the On New or Updated File operation
21.Return toaccounts.xml.
22.In the On New or Updated File properties view, change the display name to
accounts.csv.
23.Set the connector configuration to the existing File_Config.
24.In the General section, set the directory toinput.
25.Set the matcher toEdit inline.
26.Set filename pattern to*.csv.
© Copyright 2023 salesforce.com, inc. All rights reserved. 382
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.In the Post processing action section, set the move to directory tooutput.
© Copyright 2023 salesforce.com, inc. All rights reserved. 383
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
28.In the General section, review the default scheduling information; the endpoint
checks for new files every 1000 milliseconds.
Review event metadata in the DataSense Explorer
29.Select theOutputtab in the DataSense Explorer; youshould see no metadata about
the structure of the CSV file.
Display the file contents
30.Add a Logger to the flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 384
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
31.In the Logger properties view, set the display name to payload and the message to
display the payload.
#[payload]
Debug the application
32.Add a breakpoint to the Logger.
33.Save the files and debug the project.
34.In your computer’s file browser, return to the resources folder in student files for the
course.
35.Move theaccounts.csvfile to the input folder.
36.Return to the Mule Debugger and look at the payload.
© Copyright 2023 salesforce.com, inc. All rights reserved. 385
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
37.ExpandAttributesand locate thefileNameandpathattributes.
38.Step to the end of the application.
39.In your computer’s file browser, return to the student files for the course; you should
see accounts.csv has been moved to the output folder.
© Copyright 2023 salesforce.com, inc. All rights reserved. 386
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
40.Return to Anypoint Studio and look at the console; you should see the file contents
displayed.
Rename the file
41.Return to theaccounts.csvproperties view and inthe Post processing action section,
set the Rename to property to an expression that appends.backupto the original
filename.
#[attributes.fileName ++ ".backup"]
Test the application
42.Save the file to redeploy the project.
43.Remove the breakpoint from the Logger.
© Copyright 2023 salesforce.com, inc. All rights reserved. 387
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
44.In your computer’s file explorer, move theaccounts.csvfile from the output folder
back to the input folder; you should see it appear in the output folder with its new
name.
45.Move theaccounts.csv.backupfile from the outputfolder back to the input folder; it
should not be processed and should stay in the input folder.
46.Return to Anypoint Studio and switch perspectives.
47.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 388
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 7-2: Trigger a flow when a new record is added to a
database and use automatic watermarking
In this walkthrough, you work with the accounts table in the training database. You will:
● Add and configure a Database listener to check a table on a set frequency for new
records.
● Use the listener’s automatic watermarking to track the ID of the latest record
retrieved and trigger the flow whenever a new record is added.
● Output new records to a CSV file.
● Use a form to add a new account to the table and see the CSV file updated.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
View accounts data
1. Return to the coursesnippets.txtfile and copy thetext for the MUA Accounts URL.
© Copyright 2023 salesforce.com, inc. All rights reserved. 389
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
2. In a web browser, navigate to theMUA accountsby pasting the URL.
3. Review the data and the names of the columns which match those of a database
table.
Look at the File listener settings for watermarking
4. Return toaccounts.xmlin Anypoint Studio.
5. Return to theaccounts.csvproperties view for thelistener ingetCSVaccounts.
6. Locate the watermark mode setting in the General section and look at its possible
values.
Add the Database module to the project
7. In the Mule Palette, selectAdd Modules.
© Copyright 2023 salesforce.com, inc. All rights reserved. 390
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. Select the Database connector in the right side of the Mule Palette and drag and
drop it into the left side.
9. If you get a Select module version dialog box, select the latest version and clickAdd.
Create a flow to monitor a database
10.Locate the On Table Row operation for the Database connector in the right side of
the Mule Palette and drag and drop it at the top of the canvas to create a new flow.
11.Rename the flow tosyncDBaccountsToCSV.
Configure a Database connector
12.Return to the course snippets.txt file.
13.Locate and copy the MySQL (or Derby) database properties.
© Copyright 2023 salesforce.com, inc. All rights reserved. 391
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.Return toconfig.yamland paste the properties.
NOTE: The database information you see may be differentthan what is shown here; the
values in the snippets file differ for instructor-led and self-study training classes.
15.Save the file.
16.Return toglobal.xmland create a new Database Configthat uses these properties.
NOTE: If necessary, refer to the detailed steps inWalkthrough 4-2 of the Getting Started
with Anypoint Platform course.
17.Add the MySQL (or Derby) JDBC driver.
© Copyright 2023 salesforce.com, inc. All rights reserved. 392
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
18.Test the connection and make sure it is successful.
Configure the Database listener
19.Return toaccounts.xml.
20.In the On Table Row properties view, set the following values:
● Display Name: accounts
© Copyright 2023 salesforce.com, inc. All rights reserved. 393
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
● Connector configuration: Database_Config
● Table: accounts
● Watermark column: accountID
● Id column: accountID
● Frequency: 10
● Time unit: SECONDS
Write new records to a CSV file
21.Add a File Write operation to the flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 394
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
22.In the Write properties view, set the following values:
● Display Name: DBaccounts.csv
● Connector configuration: File_Config
● Path: output/DBaccounts.csv
● Write mode: APPEND
© Copyright 2023 salesforce.com, inc. All rights reserved. 395
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.ExpandPayloadin the Input tab in the DataSense Explorer; you should see the
operation will get an account with account information from the Database
operation.
Transform the records to CSV
24.Add a Transform Message component before the Write operation.
25.Change the display name toJava to CSV.
26.In the Transform Message properties view, change the output type to
application/csvand add a header property equal tofalse.
27.Set the body expression to[payload].
© Copyright 2023 salesforce.com, inc. All rights reserved. 396
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Add a Logger to display the records
28.Add a Logger to the end of the flow.
29.Change the Logger display name topayload.
30.Set the Logger message to display the payload.
Set the application to prompt to clear application data when it starts
31.Add a breakpoint to the Transform Message component.
32.Save all files then, in the main menu, selectRun> Debug Configurations.
33.Selectapdev-examplesin the left menu bar under MuleApplications.
© Copyright 2023 salesforce.com, inc. All rights reserved. 397
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
34.In the Debug Configurations dialog box, locate the Clear Application Data section in
the General tab and change it to Prompt.
NOTE: You need to rerun or debug an application toget the prompt; you cannot just save to
redeploy.
Debug the project
35.ClickDebug.
36.In the Clear Application Data dialog box, clickYes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 398
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
37.After the breakpoint is hit, in the Mule Debugger, expandPayload.
38.ClickResumeand step through several of the records.
© Copyright 2023 salesforce.com, inc. All rights reserved. 399
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
39.Look at the console; you should see the records displayed.
40.Stop the project and switch perspectives.
Clear application data and test the application
41.Run the project.
42.In the Clear Application Data dialog box, clickYes.
43.Look at the console; you should see many records.
44.Stop the project.
45.Return to the resources folder in your computer’s file explorer; you should see a new
DBaccounts.csvfile appear in the output folder.
© Copyright 2023 salesforce.com, inc. All rights reserved. 400
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
46.Open theDBaccounts.csvfile with a text editor; youshould see the records.
47.Close theDBaccounts.csvfile.
Test the application again without clearing application data
48.Return to Anypoint Studio and run the project.
49.In the Clear Application Data dialog box, clickNo.
50.Look at the console; you should see no new records output (unless someone else
just added one!).
Add a new account to the database
51.Return to the MUA Accounts page in the web browser.
52.ClickAdd account.
53.Fill out the form with data and clickSave.
© Copyright 2023 salesforce.com, inc. All rights reserved. 401
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Note:Set the postal code to a specific value. Inthe next walkthrough, you will retrieve only
new records with this specific postal code, so you do not get all of the records.
54.On the MUA accounts page, locate your new account.
55.Return to the console in Anypoint Studio; you should see your new record.
56.Stop the project.
57.Return to your computer’s file explorer; the modified date on the DBAccounts.csv file
should have been updated.
© Copyright 2023 salesforce.com, inc. All rights reserved. 402
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
58.OpenDBaccounts.csvand locate your new record at the end of the file.
59.Close theDBaccounts.csvfile.
© Copyright 2023 salesforce.com, inc. All rights reserved. 403
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 7-3: Schedule a flow and use manual
watermarking
In this walkthrough, you continue to work with the accounts table in the training database.
You will:
● Use the Scheduler component to create a new flow that executes at a specific
frequency.
● Retrieve accounts with a specific postal code from the accounts table.
● Use the Object Store component to store the ID of the latest record and then use it
to only retrieve new records.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a flow that executes at a specific frequency
1. Return toaccounts.xmlin Anypoint Studio.
2. Locate theSchedulercomponent in the Core sectionof the Mule Palette.
© Copyright 2023 salesforce.com, inc. All rights reserved. 404
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Drag aSchedulercomponent from the Mule Palette anddrop it at the top of the
canvas to create a new flow.
4. Change the name of the flow tosyncDBaccountsWithPostal.
5. In the Scheduler properties view, set the frequency to10 seconds.
© Copyright 2023 salesforce.com, inc. All rights reserved. 405
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Retrieve records with a specific postal code from the database
6. From the Mule Palette, drag a Database Select operation and drop it in the flow.
7. In the Select properties view, set the following:
● Display Name: accounts
● Connector configuration: Database_Config
● SQL query text: SELECT * FROM accounts WHERE postal= :postal
8. In the Input Parameters section, use expression mode to create a postal input
parameter with the specific postal code you used in the previous walkthrough.
{ postal:
'yourPostalValue'
}
NOTE: If you want, you can store the postal code asa property in config.yaml and then
reference it here in the DataWeave expression as { postal: p('propertyName')}.
© Copyright 2023 salesforce.com, inc. All rights reserved. 406
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Output the records to a CSV file
9. Copy theWriteoperation insyncDBaccountsToCSVandpaste it at the end of
syncDBaccountsWithPostal.
10.In the properties view for the Write operation, set the following values:
© Copyright 2023 salesforce.com, inc. All rights reserved. 407
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
● Display Name: DBaccountsPostal.csv
● Path: output/DBaccountsPostal.csv
11.Change the content to output the payload asapplication/csvwith a header property
equal tofalse.
output application/csv header=false --- payload
Log the payload
12.Add a Logger at the end of the flow and change the display name toCSV payload.
13.Set the message to the payload as typeapplication/csv.
© Copyright 2023 salesforce.com, inc. All rights reserved. 408
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Stop the syncDBaccountsToCSV flow so it does not run
14.In the properties view for the syncDBaccountsToCSV flow, set the initial state to
stopped.
Test the application
15.Save the file and run the project.
16.In the Clear Application Data dialog box, clickYes.
17.Watch the console, you should see the same records displayed every 10 seconds.
© Copyright 2023 salesforce.com, inc. All rights reserved. 409
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Note:Right now, all records with matching postalcode are retrieved – over and over again.
Next, you will modify this so only new records with the matching postal code are retrieved.
18.Stop the project.
19.Return to the resources folder in your computer’s file browser; you should see the
newDBaccountsPostal.csvfile in the output folder.
20.Open the file, review the contents then close the file.
21.Delete the file.
Add the ObjectStore module to the project
22.Return to Anypoint Studio and in the Mule Palette, selectAdd Modules.
© Copyright 2023 salesforce.com, inc. All rights reserved. 410
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Select the ObjectStore connector in the right side of the Mule Palette and drag and
drop it into the left side.
24.If you get a Select module version dialog box, select the latest version and clickAdd.
Store the ID of the last record retrieved
25.Drag the Store operation for the ObjectStore connector from the Mule Palette and
drop it after the Database Select operation.
26.In the Store properties view, set the display name and key to lastAccountID.
© Copyright 2023 salesforce.com, inc. All rights reserved. 411
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.Set the value to an expression for the maximum value of lastAccountID in the
payload containing the retrieved records.
max(payload.*accountID)
Before the query, retrieve the ID of the last record retrieved
28.Drag theRetrieveoperation for the ObjectStore connectorfrom the Mule Palette
and drop it before theDatabase Selectoperation.
© Copyright 2023 salesforce.com, inc. All rights reserved. 412
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
29.In the Retrieve properties view, set the following values:
● Display Name: lastAccountID
● Key: lastAccountID
● Default value: 0
30.Select theAdvancedtab and set the target variableto lastAccountID so the value is
stored in a variable called lastAccountID.
© Copyright 2023 salesforce.com, inc. All rights reserved. 413
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Modify the query to only retrieve new records with a specific postal
code
31.In the accounts Select properties view, add a second query input parameter called
lastAccountIDthat is equal to the watermark value.
{postal: '
yourValue
', lastAccountID: vars.lastAccountID}
32.Modify the SQL query text to use this parameter to only retrieve new records.
SELECT * FROM accounts WHERE postal = :postal AND accountID >
:lastAccountID
Only store the value if new records were retrieved
33.Add a Choice router after the Select operation.
34.Move theStore,Write, andLoggeroperations intothewhenbranch of the router.
© Copyright 2023 salesforce.com, inc. All rights reserved. 414
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
35.Add aLoggerto the default branch.
36.In the default branch Logger properties view, set the display name and message to
No new records.
© Copyright 2023 salesforce.com, inc. All rights reserved. 415
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
37.In the Choice router, click thewhenscope and in the properties view, add an
expression to route the event when the payload is not empty.
#[not isEmpty(payload)]
Clear the application data and debug the application
38.Add a breakpoint to the Retrieve operation.
39.Save the file and debug the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 416
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
40.In the Clear Application Data dialog box, clickYes.
41.In the Mule Debugger, step to the Select operation; you should see a lastAccountID
variable with a value of 0.
42.Step into the Choice router; you should see record(s) were retrieved from the
database.
© Copyright 2023 salesforce.com, inc. All rights reserved. 417
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
43.ClickResume; the flow should be executed again, andexecution should be stopped
back at the beginning of the flow.
44.Step to the Select operation; you should see the lastAccountID variable now has a
non-zero value.
© Copyright 2023 salesforce.com, inc. All rights reserved. 418
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
45.Step into the Choice router; you should see no records were retrieved from the
database (unless someone else just added one with the same postal code!).
46.Stop the project and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 419
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
47.Return to your computer’s file explorer and locate and open the new
DBaccountsPostal.csv file in the output folder.
NOTE: If you see the same records more than once,it is because during debugging, the flow
was executed again before the watermark was stored.
48.Close theDBaccountsPostal.csvfile.
Debug the application and do not clear application data
49.Return to Anypoint Studio and debug the project.
50.In the Clear Application Data dialog box, clickNo.
51.In the Mule Debugger, step to the Select operation; you should see a lastAccountID
variable with the same non-zero value.
52.Step into the Choice router; no new records should have been returned.
53.Remove the breakpoint from the Retrieve operation.
54.Make sure there are no other breakpoints in the flow then clickResumeto continue
application execution.
© Copyright 2023 salesforce.com, inc. All rights reserved. 420
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: If your application still halts at the Retrieve operation, stop then debug the project
without clearing the application data.
Add a new account to the database
55.Return to the MUA Accounts page in the web browser.
56.ClickAdd account.
57.Fill out the form with data and use the same postal code.
58.ClickSave.
59.You should see your new account on the MUA accounts page.
60.Return to Anypoint Studio; you should see your new record in the console.
© Copyright 2023 salesforce.com, inc. All rights reserved. 421
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
61.Return to your computer’s file explorer; the modified date on the
DBAccountsPostal.csv file should have been updated.
62.OpenDBaccountsPostal.csvand locate your new recordat the end of the file.
63.Close theDBaccountsPostal.csvfile.
64.Return to Anypoint Studio and switch perspectives.
65.Stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 422
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 7-4: Publish and listen for JMS messages
In this walkthrough, you send a JMS message for each new database record so it can be
processed asynchronously. You will:
● Add and configure a JMS connector for ActiveMQ (that uses an in-memory broker).
● Send messages to a JMS queue.
● Listen for and process messages from a JMS queue.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Add the JMS module to the project
1. Return toaccounts.xml.
2. In the Mule Palette, selectAdd Modules.
3. Select theJMS connectorin the right side of theMule Palette and drag and drop it
into the left side.
© Copyright 2023 salesforce.com, inc. All rights reserved. 423
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. If you get a Select module version dialog box, select the latest version and clickAdd.
Configure the JMS connector
5. Return to the Global Elements view of global.xml.
6. ClickCreate.
7. In the Choose Global Type dialog box, selectConnectorConfiguration > JMS Config
and clickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 424
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
8. In the Global Element Properties dialog box, make sure the connection is set to
ActiveMQ Connection.
9. Click theConfigure > Add Mavendependency optionfor the ActiveMQ Broker.
10.In the Maven dependency dialog box, enteractivemq-brokerin the Search Maven
Central field.
11.Select theorg.apache.activemq:activemq-brokerinthe results that are displayed.
12.ClickEdit selected.
13.Enter 5.16.5 in the Version text field.
© Copyright 2023 salesforce.com, inc. All rights reserved. 425
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
© Copyright 2023 salesforce.com, inc. All rights reserved. 426
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
14.ClickFinish.
15.Scroll down and locate theConnection Factorysection.
16.For Factory configuration, selectEdit inline; theBroker url should already be
populated.
17.ClickOK.
© Copyright 2023 salesforce.com, inc. All rights reserved. 427
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Use the JMS Publish operation to send a message to a JMS queue
18.Return toaccounts.xml.
19.Drag out aJMS Publishoperation from the Mule Paletteand drop it after the Write
operation in syncDBaccountsWithPostal.
20.In the Publish properties view, set the following values:
● Display Name: JMS accountsQ
● Connector configuration: JMS_Config
● Destination: accountsQ
● Destination type: QUEUE
© Copyright 2023 salesforce.com, inc. All rights reserved. 428
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Modify the message body to be of typeapplication/json.
output application/json --- payload
22.Scroll down and locate the User Properties field.
23.Use expression mode and set it equal to an object with a key calledpublisherand a
value oftraining.
{"publisher":"training"}
© Copyright 2023 salesforce.com, inc. All rights reserved. 429
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create a flow to listen to a JMS topic
24.Drag out theJMS On New Messageoperation from theMule Palette and drop it in
the canvas to create a new flow.
25.Give the flow a new name ofreceiveJMSMessages.
26.In the On New Message properties view, set the following values:
● Display Name: JMS accountsQ
● Connector configuration: JMS_Config
● Destination: accountsQ
● Consumer type: Queue consumer
© Copyright 2023 salesforce.com, inc. All rights reserved. 430
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.Add a Logger to the flow.
28.Set its display name topayloadand its message to#[payload].
Clear application data and debug the application
29.Add a breakpoint to the Logger in receiveJMSmessages.
30.Save the files and debug the project.
31.In the Clear Application Data dialog box, clickYes.
© Copyright 2023 salesforce.com, inc. All rights reserved. 431
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
32.Wait until the project deploys; application execution should stop in
receiveJMSMessages.
33.In the Mule Debugger view, look at the value of the payload.
34.Expand theAttributesand locate the publisher propertyin the userProperties.
© Copyright 2023 salesforce.com, inc. All rights reserved. 432
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
35.Step through the rest of the application; you should see the JSON message in the
console.
NOTE: If you want to test further, return to the MUAAccounts in the web browser and add a
new record with the same postal code.
36.Stop the project and switch perspectives.
© Copyright 2023 salesforce.com, inc. All rights reserved. 433
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Module 8: Processing records
At the end of this module, you should be able to:
● Process items in a collection using the For Each scope.
● Process records using the Batch Job scope.
● Use filtering and aggregation in a batch step.
© Copyright 2023 salesforce.com, inc. All rights reserved. 434
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 8-1: Process items in a collection using the For Each
scope
In this walkthrough, you split a collection and process each item in it. You will:
● Use the For Each scope element to process each item in a collection individually.
● Change the value of an item inside the scope.
● Examine the payload before, during, and after the scope.
● Look at the thread used to process each item.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Stop the syncDBaccountsWithPostal flow so it does not run
1. Return toaccounts.xml.
2. In the properties view for the syncDBaccountsWithPostal flow, set the initial state to
stopped.
© Copyright 2023 salesforce.com, inc. All rights reserved. 435
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. Right-click in the canvas and selectCollapse All.
Add a For Each scope
4. ExpandgetCSVaccounts.
5. In the Mule Palette, selectCore.
6. Locate the For Each scope and drag and drop it before the Logger.
Transform the input to a collection
7. Add a Transform Message component before the For Each scope.
8. Set its display name toCSV to Java.
© Copyright 2023 salesforce.com, inc. All rights reserved. 436
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
9. In the Transform Message properties view, leave the output type set tojavaand set
the expression topayload.
Process each element in the For Each scope
10.Add aSet Payloadtransformer and a Logger to theFor Each scope.
11.In the Set Payload properties view, set the display name and value to processed.
© Copyright 2023 salesforce.com, inc. All rights reserved. 437
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
12.Set the Logger display name to payload and have it display the payload.
Change the File listener so it does not rename files
13.In the accounts.csv properties view, delete theRenameto value.
© Copyright 2023 salesforce.com, inc. All rights reserved. 438
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Debug the application
14.Add a breakpoint to the Transform Message component.
15.Save the file, debug the project, and do not clear application data.
16.Return to the student files in your computer’s file browser.
17.Renameaccounts.csv.backuptoaccounts.csvin theinput folder.
18.Return to Anypoint Studio; application execution should have stopped at the
Transform Message component.
© Copyright 2023 salesforce.com, inc. All rights reserved. 439
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
19.In the Mule Debugger view, look at the payload type and value.
20.Step to the For Each scope; the payload should now be an ArrayList of
LinkedHashMaps.
© Copyright 2023 salesforce.com, inc. All rights reserved. 440
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
21.Step into the Set Payload in the For Each scope; the payload should now be a
LinkedHashMap.
22.ExpandVariables; you should see a counter variable.
© Copyright 2023 salesforce.com, inc. All rights reserved. 441
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
23.Step again; you should see the payload for this record inside the scope has been set
to the string, processed.
© Copyright 2023 salesforce.com, inc. All rights reserved. 442
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
24.Step again and look at the payload and counter for the second record.
25.Step through the application to the Logger after the For Each scope; the payload
should be equal to the original ArrayList of LinkedHashMaps and not a list of
processed strings.
© Copyright 2023 salesforce.com, inc. All rights reserved. 443
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
26.Step to the end of the application.
27.Stop the project and switch perspectives.
Look at the processing threads
28.In the console, locate the thread number used to process each item in the
collection; the same thread should be used for each:cpuIntensive.01in the
following screenshot.
© Copyright 2023 salesforce.com, inc. All rights reserved. 444
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 8-2: Process records using the Batch Job scope
In this walkthrough, you create a batch job to process the records in a CSV file. You will:
● Use the Batch Job scope to process items in a collection.
● Examine the payload as it moves through the batch job.
● Explore variable persistence across batch steps and phases.
● Examine the payload that contains information about the job in the On
Complete phase.
● Look at the threads used to process the records in each step.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a new flow to read CSV files
1. Return toaccounts.xml.
2. Drag a Flow scope from the Mule Palette and drop it above getCSVaccounts.
3. Change the flow name tobatchProcessCSVaccounts.
© Copyright 2023 salesforce.com, inc. All rights reserved. 445
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
4. Select the On New or Updated File operation in getCSVaccounts and copy it.
5. Click the Source section of batchProcessCSVaccounts and paste it.
6. Add a Transform Message component to the flow.
7. Set the display name toCSV to Java.
8. In the Transform Message properties view, change the body expression topayload.
Add a Batch Job scope
9. In the Mule Palette, selectCoreand locate theBatchelements.
10.Drag aBatch Jobscope and drop it after theTransformMessagecomponent.
© Copyright 2023 salesforce.com, inc. All rights reserved. 446
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Set a variable before the Batch Job scope
11.Add aSet Variabletransformer before theBatch Jobscope.
12.In the Set Variable properties view, set the following:
● Display Name: size
● Name: size
● Value: #[sizeOf(payload)]
Set a variable inside the Batch Job scope
13.Add aSet Variabletransformer to theprocessorsphaseof the batch step.
14.Add aLoggercomponent after theSet Variabletransformer.
© Copyright 2023 salesforce.com, inc. All rights reserved. 447
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.In the Set Variable properties view, set the following:
● Display Name: cname
● Name: cname
● Value: #[payload.Name]
Create a second batch step
16.Drag aBatch Stepscope from the Mule Palette anddrop it in the process records
phase of the Batch Job scope after the first batch step.
17.Add aLoggerto the processors phase of the secondbatch step.
18.Add aLoggerto theOn Completephase.
© Copyright 2023 salesforce.com, inc. All rights reserved. 448
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Stop the other flow watching the same file directory from being
executed
19.In the properties view for the getCSVaccounts flow, set the initial state tostopped.
Debug the application
20.In batchProcessCSVaccounts, add a breakpoint to the Transform Message
component.
21.Save the file, debug the project, and do not clear application data.
22.Return to the student files in your computer’s file browser and move accounts.csv
from the output folder to the input folder.
23.In the Mule Debugger view, watch the payload as you step to the Batch Job scope; it
should go from CSV to an ArrayList.
24.In the Mule Debugger view, expandVariables; you shouldsee the size variable.
© Copyright 2023 salesforce.com, inc. All rights reserved. 449
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
25.Step to the Logger in the first batch step.
26.In the Mule Debugger view, look at the value of the payload; it should be a
HashMap.
© Copyright 2023 salesforce.com, inc. All rights reserved. 450
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
27.ExpandVariables; you should see thesizevariable and thecnamevariable specific
for that record.
28.Step through the rest of the records in the first batch step and watch thepayload
and thecnamevariable change.
© Copyright 2023 salesforce.com, inc. All rights reserved. 451
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
29.Step into the second batch step and look at thepayloadand thecnamevariable;
you should see the cname variable is defined and has a value.
30.Step through the rest of the records in the second batch step and watch the value of
cname.
31.Step into the On Complete phase; you should see the payload is an
ImmutableBatchJobResult.
32.Expand the payload and locate the values fortotalRecords,successfulRecords, and
failedRecords.
© Copyright 2023 salesforce.com, inc. All rights reserved. 452
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
33.Step through the rest of the application and switch perspectives.
34.Stop the project.
Look at the processing threads
35.In the console, locate the thread number used to process each record in the
collection in each step of the batch process; you should see more than one thread
used.
© Copyright 2023 salesforce.com, inc. All rights reserved. 453
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
© Copyright 2023 salesforce.com, inc. All rights reserved. 454
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Walkthrough 8-3: Use filtering and aggregation in a batch step
In this walkthrough, you use a batch job to synchronize account database records to
Salesforce. You will:
● Use a batch job to synchronize database records (with your postal code) to
Salesforce.
● In a first batch step, check to see if the record already exists in Salesforce.
● In a second batch step, add the record to Salesforce.
● Use a batch step filter so the second batch step is only executed for specific records.
● Use a Batch Aggregator scope to commit records in batches.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Look at existing Salesforce account data
1. In a web browser, navigate tohttp://login.salesforce.com/and log in with your
Salesforce Developer account.
2. Click theApp Launcher, clickView All, then clicktheAccountslink.
© Copyright 2023 salesforce.com, inc. All rights reserved. 455
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
3. In the view drop-down menu, selectAll Accounts.
4. Look at the existing account data; a Salesforce Developer account is populated with
some sample data.
5. Notice that countries and postal codes are not displayed by default.
6. In the List View Controls dropdown menu, selectNew.
© Copyright 2023 salesforce.com, inc. All rights reserved. 456
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
7. In the New List View dialog box, set the list name toAll Accounts with Postal Code.
8. SelectAll users can see this list view.
9. ClickSave.
10.In the List View Controls dropdown menu, selectSelectFields to Display.
© Copyright 2023 salesforce.com, inc. All rights reserved. 457
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
11.In the Select Fields to Display dialog box, selectBilling Zip/Postal Codeas the
available field and click theMove selection to VisibleFieldsbutton.
12.SelectBilling Countryas the available field andclick theMove selection to Visible
Fieldsbutton.
13.Use theUpandDownbuttons to order the fields asyou prefer.
14.ClickSave; you should now see all the accounts withpostal codes and countries.
© Copyright 2023 salesforce.com, inc. All rights reserved. 458
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
15.Adjust the column widths as you prefer.
Add an account to Salesforce with a name matching one of the
database records
16.Click theNewbutton.
17.In the New Account dialog box, enter an account name (one that matches one of
the accounts you added with your postal code to the database) and clickSave.
© Copyright 2023 salesforce.com, inc. All rights reserved. 459
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
18.Leave this browser tab open.
Add a Batch Job scope to the receiveJMSmessages flow
19.Return toaccounts.xmlin Anypoint Studio.
20.Drag a Batch Job scope from the Mule Palette and drop it before the Logger in the
receiveJMSmessages flow.
21.Change the display name of the batch job tosyncWithSalesforce.
© Copyright 2023 salesforce.com, inc. All rights reserved. 460
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Query Salesforce to see if an account already exists
22.Change the name of the batch step inside the batch job toisAccountInSalesforce.
23.Drag aSalesforce Queryoperation from the Mule Paletteand drop it in the
processorsphase in the batch step.
24.In the Query properties view, set the following values:
● Display Name: Account
● Connector configuration: Salesforce_Config
● Salesforce query: SELECT Name FROM Account
© Copyright 2023 salesforce.com, inc. All rights reserved. 461
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
NOTE: You will add to this query shortly.
Transform the input JSON data to Salesforce Account objects
25.Add aTransform Messagecomponent before theBatchJob.
26.Change the display name toJSON to Accounts.
27.In the Transform Message properties view, look at the metadata in the input section.
© Copyright 2023 salesforce.com, inc. All rights reserved. 462
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
28.Right-clickPayloadand selectSet Metadata.
29.Create a new metadata type with the following information:
● Type id: accounts_json
● Type: JSON
● Example: Use the accounts.json file in the resources/examplesfolder of
the student files
© Copyright 2023 salesforce.com, inc. All rights reserved. 463
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
30. In the Transform Message properties view, click the Show Graphics button and map
the following fields:
● name: Name
● street: BillingStreet
● city: BillingCity
● state: BillingState
● postal: BillingPostalCode
● country: BillingCountry
NOTE: If you do not get Salesforce metadata for theAccount object, you can copy the
DataWeave transformation from the course snippets.txt file.
Finish the batch step to check if an account already exists in Salesforce
31.In the Query properties view, add an input parameter namedcname.
32.Set the parameter value topayload.Name, ensure itis aString, and give it a default
value.
payload.Name default "" as String
© Copyright 2023 salesforce.com, inc. All rights reserved. 464
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
33.Modify the Salesforce query to look for accounts with this name.
SELECT Name FROM Account
WHERE Name= ':cname'
Store the result in a variable instead of overriding the payload
34.Select theAdvancedtab.
35.Set the target variable toexists.
36.Set the target value to:
#[(sizeOf(payload as Array) > 0)]
37.Add aLoggerafter theQueryoperation.
38.Add aLoggerto theOn Completephase.
© Copyright 2023 salesforce.com, inc. All rights reserved. 465
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Change the initial state of the flow
39.In the properties view for the syncDBaccountsWithPostal flow, change the initial
state tostarted.
Debug the application
40.In the receiveJMSmessages flow, add a breakpoint to the Transform Message
component before the batch job.
41.Save the file and debug the project.
42.Clear the application data.
43.In the Mule Debugger, wait until application execution stops in the
receiveJMSmessages flow.
© Copyright 2023 salesforce.com, inc. All rights reserved. 466
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
44.Step to the Logger in the first batch step and expand Variables; you should see the
existsvariable set totrue or false.
45.Step through the application; you should see theexistsvariable set to false for
records with names that don’t exist in Salesforce and true for those that do.
46.Stop the project and switch perspectives.
Set a filter for the insertion step
47.Add a second batch step to the batch job.
48.Change its display name towriteToSalesforce.
© Copyright 2023 salesforce.com, inc. All rights reserved. 467
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
49.In the properties view for the second batch step, set the accept expression so that
only records that have the variable exists set to false are processed.
#[not vars.exists]
Use the Salesforce Create operation to add new account records to
Salesforce
50.Add aSalesforce Createoperation to the second batchstep in the processors phase.
© Copyright 2023 salesforce.com, inc. All rights reserved. 468
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
51.In the Create properties view, set the following:
● Display Name: Accounts
● Connector configuration: Salesforce_Config
● Type: Account
● Records: payload
52.Select theInputtab in the DataSense Explorer; youshould see this operation
expects an Array of Account objects – not just one.
© Copyright 2023 salesforce.com, inc. All rights reserved. 469
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Create the Array of objects that the operation is expecting
53.Drag aBatch Aggregatorscope from the Mule Paletteand drop it in the aggregator
phase of the second batch step.
54.Move theSalesforce Createoperation into theBatchAggregator.
55.In the Batch Aggregator properties view, set the aggregator size to 3.
56.Add aLoggerafter theCreateoperation.
© Copyright 2023 salesforce.com, inc. All rights reserved. 470
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Test the application
57.Save the file, debug the project, and clear the application data.
58.Step through the application until you step into the Batch Aggregator.
59.ExpandPayload.
60.Step through the rest of the flow.
61.Return to Salesforce and look at the accounts; you should see the records from the
legacy MySQL database are now in Salesforce.
NOTE: You could also check for the records by makinga request to
http://localhost:8081/sfdc.
© Copyright 2023 salesforce.com, inc. All rights reserved. 471
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
62.Stop the application then run it again but do not clear the application data; no
records should be processed.
63.Return to salesforce.com and locate your new record(s); they should have been
inserted only once.
64.Return to Anypoint Studio and stop the project.
© Copyright 2023 salesforce.com, inc. All rights reserved. 472