MuleSoft for Salesforce Developers A practitioner’s guide to deploying MuleSoft APIs and integrations for Salesforce enterprise solutions Arul Christhuraj Alphonse Alexandra Martinez Akshata Sawant BIRMINGHAM—MUMBAI MuleSoft for Salesforce Developers Copyright © 2022 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capital. However, Packt Publishing cannot guarantee the accuracy of this information. Group Product Manager: Alok Dhuri Publishing Product Manager: Harshal Gundetty Senior Editor: Nisha Cleetus Business Development Executive: Uzma Sheerin Technical Editor: Maran Fernandes Copy Editor: Safis Editing Project Coordinator: Manisha Singh Proofreader: Safis Editing Indexer: Subalakshmi Govindhan Production Designer: Prashant Ghare Marketing Coordinator: Rayyan khan and Deepak Kumar First published: September 2022 Production reference: 1090922 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-80107-960-0 www.packt.com To the memory of my father, Alphonse, and to my mother, Esther RajaRathinam, for their sacrifices and love. – Arul Christhuraj Alphonse To my wife, Ana, for being my biggest supporter, my best friend, and the best life partner I could’ve asked for. To my aunts, Elia and Vero, for believing in me unconditionally and for all of your love. To my mom, Lulu, for all your sacrifices, your long nights when I was sick, your hugs, your tears, your smiles, your warmth, and everything you gave me. Las amo, siempre. – Alexandra Martinez To my parents, I truly appreciate your efforts in bringing me up to be a better individual. To my best friend and my favorite human, Dan! I love you! To my little bro, Shubham, for being so mature and supportive. – Akshata Sawant Co n t r i b u t o r s About the authors Arul Christhuraj Alphonse works as a senior integration architect at Cognizant. Before working at Cognizant, he also worked at Akmin Technologies, Quinnox, IBM, and TCS. He has over 18 years of experience in the integration and API domain and has designed over 1,000 integrations. His educational qualifications include Master of Computer Applications and Master of Business Administration degrees, and his professional qualifications include MuleSoft Mentor, MuleSoft Certified Integration Architect, MuleSoft Certified Platform Architect, MuleSoft Certified Developer Level 1, and SoftwareAG webMethods Certified Professional. He was born and raised in Thoothukudi, Tamil Nadu, India, and currently lives in Singapore. He shares his knowledge through Udemy and the Tech Lightning YouTube channel. I thank God because without God I wouldn’t be able to do any of this. I would like to thank my loving and understanding wife, Sahaya Divya, my son, Rithwin, my daughter, Riya, and also my family for their continuous support, patience, and encouragement throughout the long process of writing this book. Big thanks to my team at Cognizant and DFS for being supportive. Alexandra Martinez is a developer advocate at MuleSoft, creating technical content to enable developers and architects to get started with MuleSoft’s products. Before this, Alex worked as a MuleSoft developer and was part of the MuleSoft community as an Ambassadress and meetup leader for the Toronto, Online Spanish, and Women Who Mule chapters. Alex has more than 10 years of experience in technology and has developed software in other languages, such as Java, Python, and PHP. Born and raised in Monterrey, Mexico, Alexandra’s MuleSoft career was key to moving to a different country, and she currently lives in Niagara Falls, Canada. Alex volunteers at organizations such as Women Who Code and Olascoaga MX to help close the gender gap in STEM careers. I want to thank my dream team at MuleSoft: Mariana Lemus, Sabrina Marechal, Sabrina Hockett, Isabella Navarro, David Norris, and Meghan Murphy. You have helped me in more ways than you’ll ever know and I really appreciate it. I also want to thank Bits In Glass for changing my life, especially Aaron Wentzell and Graham Fraser for mentoring me. Akshata Sawant is a developer advocate at MuleSoft. She’s been evangelizing MuleSoft through her blogs, videos, and training sessions. She has around five years of experience as a MuleSoft developer. Apart from this, she's also a MuleSoft Certified Developer and an architect. Akshata has been an active member of the MuleSoft community and is also a former MuleSoft Ambassadress and a meetup leader for the London, Mumbai, and Manchester regions. Her roots go back to Mumbai but she’s currently living her London dream. She’s been a global speaker and mentors women in the integration ecosystem. I would like to thank my parents, Dan, Shubham, Chetan Parekh Sir, family, and my mentors at Apisero and EPAM for always motivating me. Thanks to all my friends for their honest reviews on my content. Thanks to everyone at Packt for being so patient and Uzma Sherin for trusting me with this book. To my team at MuleSoft and my amazing MuleSoft Community, a big thank you from the bottom of my heart! Ambadnya! A b o u t t h e r e v i e we r s Gaurav Kheterpal is a well-known name in the Salesforce ecosystem, a Salesforce MVP since 2016, and he holds 40 Salesforce Certifications, 21 Salesforce AP Credentials and 5 MuleSoft Certifications – he is ranked among the top 3 globally certified experts in Salesforce & Mulesoft ecosystems. Gaurav has been recognized by Salesforce as a Developer Success Story and a Trailblazer. He has delivered several sessions at leading events such as Dreamforce, TrailheaDX, Salesforce World Tour, London’s Calling, and several others. Gaurav is passionate about evangelizing Salesforce and MuleSoft platforms in the broader community. D Rajesh Kumar is a Lead MuleSoft Integration Architect with 17+ years of extensive experience in the IT industry. For the last 8 years, he has been working on the MuleSoft platform in various domains for end-to-end platform setups, architecture, design and Center for Enablement (C4E) setups and execution. He is a MuleSoft Certified Architect and a MuleSoft Ambassador recognized by MuleSoft for his expertise in Mule. He is currently working for TCS as Solution Architect and previously worked for Infosys, HCL, and Jamcracker. Table of Contents Preface xv Part 1: Getting Started with MuleSoft 1 Introduction to APIs and MuleSoft 3 Understanding the need for an Understanding why MuleSoft is useful 15 integration tool 4 Analyzing how MuleSoft helps Salesforce developers 17 Introducing no-code and low-code technologies 4 Analyzing integrations 6 Exploring application networks and the API-led connectivity approach 18 Understanding APIs 8 Understanding what application networks are 18 Reviewing the restaurant analogy 8 Analyzing the API-led connectivity approach 19 Exploring an API example 9 Analyzing API components 11 Summary 22 Listing the benefits of using APIs 12 Questions 23 Introducing MuleSoft 12 Answers 23 Listing MuleSoft’s products 13 2 Designing Your API 27 Understanding an API life cycle 28 Getting started with OAS and RAML 31 Introducing REST, HTTP, and SOAP 29 OAS 31 REST 29 RAML 32 HTTP/HTTPS 29 Getting started with API design 32 SOAP 31 URI parameter 39 viii Table of Contents Query parameter 40 Summary 52 API mocking 47 Assignments 53 Best practices and tips 51 Questions 53 API design naming convention 51 Answers 54 Optimizing your API design 52 3 Exploring Anypoint Studio 55 Technical requirements 55 Running the Mule application 73 Downloading and installing Testing the Mule application 75 Anypoint Studio 56 Exporting and importing Mule files 77 Downloading Anypoint Studio 56 Exporting a Mule application as a JAR file 78 Installing Anypoint Studio 57 Exporting a Mule application as a filesystem 79 Launching Anypoint Studio 58 Importing a Mule application from a JAR file 80 Introducing the Mule Palette 59 Importing a Mule application from the filesystem 81 Exploring the Mule project structure 60 Updating the theme in Anypoint Introducing Mule views and Studio 83 perspectives 62 Installing software updates in Views 62 Anypoint Studio 85 Building, running, and testing a Summary 87 Mule application 63 Questions 87 Building the Mule application 63 Answers 88 4 Introduction to Core Components 89 Technical requirements 89 Batch 98 Getting familiar with a Mule flow 90 Features of the Batch scope 98 Exploring the types of Mule flow 91 The batch processing stages 98 Understanding the Mule event structure 93 A batch step 98 The batch aggregator 99 Core components 96 The batch job 100 Table of Contents ix Components 102 Round Robin 120 Custom Business Event 102 Scatter-Gather 121 Dynamic Evaluate 103 Scopes 123 Idempotent Message Validator 104 Async 124 Invalidate Cache 105 Cache 124 Invalidate Key 106 Flow 125 Logger 107 For Each 125 Parse Template 108 Parallel For Each 126 Set Transaction Id 109 Sub Flow 127 Transform Message 110 Try 127 Endpoints 110 Until Successful 128 A Scheduler 111 Transformers 129 Error handling 112 Set Variable 130 On Error Continue 113 Remove Variable 130 On Error Propagate 114 Set Payload 131 Raise Error 115 Summary 133 Error Handler 116 Assignments 133 Flow control 118 Questions 133 Choice 118 Answers 134 First Successful 119 5 All About Anypoint Platform 135 Technical requirements 135 Anypoint VPC – virtual private cloud 162 Introducing Anypoint Platform 136 Load balancer 164 Getting started with Design Center 136 Introducing API Manager 164 API Designer 136 Exploring Anypoint Monitoring 164 Flow Designer 140 Alerts 165 Introducing Exchange 145 Log Management 166 The public portal 148 Introducing Anypoint Visualizer 166 Exploring Runtime Manager 150 Exploring Access Management 167 Deploying a Mule application into CloudHub 152 Organization and business groups 167 Managing a Mule application 155 Invite user 167 Runtime Manager alerts 159 Roles 168 Environments 169