<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ángel Alberto Mata on Medium]]></title>
        <description><![CDATA[Stories by Ángel Alberto Mata on Medium]]></description>
        <link>https://medium.com/@alberto-mata?source=rss-8e8d4e8bc6df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MzH7tWrp-i46Ww1CosozOQ.jpeg</url>
            <title>Stories by Ángel Alberto Mata on Medium</title>
            <link>https://medium.com/@alberto-mata?source=rss-8e8d4e8bc6df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 14:02:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alberto-mata/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Structured CLI Output: A Best Practice for DevOps Teams]]></title>
            <link>https://medium.com/metasintaxis/structured-cli-output-a-best-practice-for-devops-teams-5d0d6c1d71f5?source=rss-8e8d4e8bc6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d0d6c1d71f5</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ángel Alberto Mata]]></dc:creator>
            <pubDate>Thu, 18 Sep 2025 21:39:32 GMT</pubDate>
            <atom:updated>2025-09-20T05:34:35.547Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*AQ0gy1JGzpvBnYHjldj6ew.png" /></figure><p>Every DevOps engineer has been there: staring at logs from multiple commands, each with its own way of speaking. One tool dumps JSON only, another prints human-readable text with no structure, and a third mixes debug messages and results in the same stream: no timestamps, no error codes, no consistent schema.</p><p>This lack of consistency renders reading logs a matter of guesswork, rather than engineering. Debugging slows down, automation becomes fragile, and teams struggle to trust their own scripts.</p><p>The solution is to define a <strong>CLI output standard</strong> that balances three things:</p><ol><li>A <strong>clear intention</strong> behind what gets printed and where.</li><li>A <strong>consistent format</strong> for both human and machine readability.</li><li>Basic <strong>signal handling</strong> ensures scripts shut down cleanly and continue to report meaningful results.</li></ol><h4>Why it matters</h4><p>Without a standard, output from scripts is:</p><ul><li>Hard to parse programmatically.</li><li>Missing timestamps and error codes needed for debugging.</li><li>Inconsistent between human-readable and machine-readable modes.</li><li>Silent or abrupt when interrupted (no graceful signal handling).</li></ul><p>By enforcing structure and conventions, you unlock:</p><ul><li><strong>Consistent parsing</strong> across scripts and tools.</li><li><strong>Traceable debugging</strong> with error codes, timestamps, and context fields.</li><li><strong>Dual formats</strong> that serve humans in terminals and machines in pipelines.</li><li><strong>Graceful termination</strong> on signals like SIGINT or SIGTERM.</li></ul><h3>The core principles of a standard</h3><p>To solve the chaos of inconsistent CLI outputs, we need a schema that is <strong>predictable, portable, and easy to adopt</strong>. That means aiming for <strong>POSIX compatibility</strong>, so scripts behave consistently across environments without relying on shell-specific quirks.</p><p>At its core, every output should include:</p><p><strong>Standard fields</strong></p><ul><li>status: outcome of the operation (OK, WARNING, ERROR).</li><li>message: human-readable summary.</li><li>timestamp: always in UTC, ISO 8601 format for traceability.</li><li>detail: optional container for results, external command output, or extra context.</li><li>errorCode: optional identifier for failures, replacing vague exit codes.</li><li>line, script, function: optional traceability fields for debugging.</li></ul><p><strong>Field detail as a container</strong></p><ul><li>Instead of throwing raw command output directly at the user, please place it in the detail field.</li><li>This makes it easy to embed structured JSON, logs, or command results inside a predictable wrapper.</li></ul><p><strong>Error codes as part of the schema</strong></p><ul><li>Don&#39;t rely on inconsistent Unix exit codes alone.</li><li>Provide explicit errorCode values in the output so automation and operators can act deterministically.</li></ul><p><strong>Timestamps everywhere</strong></p><ul><li>Always in UTC and ISO 8601.</li><li>Essential for correlating events across distributed systems, CI/CD pipelines, or log aggregators.</li></ul><p><strong>Dual formats</strong></p><ul><li><strong>Human-readable block format</strong> for interactive use, where indentation and separators aid readability.</li><li><strong>JSON format</strong> for machine parsing in pipelines, log shipping, and automation. Both should contain the same information.</li></ul><p><strong>POSIX compatibility</strong></p><ul><li><strong>stdout</strong>: final results only (block or JSON).</li><li><strong>stderr</strong>: diagnostics, progress messages, warnings.</li><li>Exit codes follow POSIX conventions (0 = success, 1 = generic error, 2 = misuse of shell builtins, 126/127 for permission or not found).</li><li>Optional signal handling (e.g., SIGINT, SIGTERM) should emit a final structured message before exiting.</li></ul><p>Now let&#39;s see how these principles look in practice.</p><h4>A proposal for a portable schema</h4><p>Here&#39;s a baseline schema you can adopt today. It&#39;s simple enough for daily scripting, yet extensible for enterprise use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6212b17028332857bd37aa703530a4f/href">https://medium.com/media/b6212b17028332857bd37aa703530a4f/href</a></iframe><p><strong>Human-Readable Block Format</strong></p><p><em>Success example:</em></p><pre>Timestamp : 2025-09-18T16:00:00Z<br>Status    : OK<br>Message   : Operation completed<br>Detail    : 42<br>-------------------------------</pre><p><em>Error example:</em></p><pre>Timestamp : 2025-09-18T16:05:23Z<br>Status    : ERROR<br>Message   : Invalid input<br>Detail    : Missing &#39;name&#39; field<br>Error Code: E001<br>Line      : 42<br>Script    : my-script.sh<br>Function  : validate_args<br>-------------------------------</pre><p><strong>JSON Format</strong></p><p>Ideal for automation, pipelines, and log shippers:</p><p><em>Success example:</em></p><pre>{<br>  &quot;status&quot;: &quot;OK&quot;,<br>  &quot;message&quot;: &quot;Operation completed&quot;,<br>  &quot;detail&quot;: 42,<br>  &quot;timestamp&quot;: &quot;2025-09-18T16:00:00Z&quot;<br>}</pre><p><em>Error example:</em></p><pre>{<br>  &quot;status&quot;: &quot;ERROR&quot;,<br>  &quot;message&quot;: &quot;Invalid input&quot;,<br>  &quot;detail&quot;: &quot;Missing &#39;name&#39; field&quot;,<br>  &quot;timestamp&quot;: &quot;2025-09-18T16:05:23Z&quot;,<br>  &quot;errorCode&quot;: &quot;E001&quot;,<br>  &quot;line&quot;: 42,<br>  &quot;script&quot;: &quot;my-script.sh&quot;,<br>  &quot;function&quot;: &quot;validate_args&quot;<br>}</pre><h3>Adoption: How to Get Started</h3><p>Standards only work if you apply them consistently. Here&#39;s a practical way to roll this out:</p><ol><li><strong>Start small.</strong> Pick one script in your pipeline and migrate its output to the schema.</li><li><strong>Validate in CI/CD.</strong> Add checks to ensure JSON output is always valid and includes required fields.</li><li><strong>Expand gradually.</strong> Apply the schema to other scripts over time until your toolchain is consistent.</li><li><strong>Align your team.</strong> Document the schema in your repo and make it the default for new scripts.</li><li><strong>Contribute back.</strong> The specification is open and versioned — propose extensions or refinements through the <a href="https://github.com/metasintaxis/cli-output-specification">CLI Output Specification repository</a>.</li></ol><h3>Final Thoughts</h3><p>CLI scripts may look small, but their outputs live in the critical path of debugging, automation, and compliance. By adopting a consistent standard — with clear fields, timestamps, error codes, and POSIX alignment — you turn noisy logs into reliable signals.</p><p>This article introduced the motivation, the principles, and a baseline schema you can start with. The <strong>full specification</strong>, including versioning, POSIX exit codes, and signal handling, is published in the <a href="https://github.com/metasintaxis/cli-output-specification">CLI Output Specification repository</a>. That repo will always contain the latest, canonical version.</p><p>The next step is simple: pick one script, adopt the schema, and see how much smoother debugging and automation become. From there, scale it across your pipelines. Standards don&#39;t just make logs prettier — they make your DevOps more predictable, traceable, and trustworthy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d0d6c1d71f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/metasintaxis/structured-cli-output-a-best-practice-for-devops-teams-5d0d6c1d71f5">Structured CLI Output: A Best Practice for DevOps Teams</a> was originally published in <a href="https://medium.com/metasintaxis">metasintaxis</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Removing Deprecated Metadata Using The Salesforce CLI]]></title>
            <link>https://alberto-mata.medium.com/removing-deprecated-metadata-using-the-salesforce-cli-e434c268f257?source=rss-8e8d4e8bc6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/e434c268f257</guid>
            <category><![CDATA[continous-integration]]></category>
            <category><![CDATA[salesforce-developer]]></category>
            <category><![CDATA[metadata-api]]></category>
            <category><![CDATA[sfdx-cli]]></category>
            <category><![CDATA[salesforce-tools]]></category>
            <dc:creator><![CDATA[Ángel Alberto Mata]]></dc:creator>
            <pubDate>Thu, 03 Jun 2021 12:02:49 GMT</pubDate>
            <atom:updated>2021-06-10T05:49:22.576Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>When we start working in an old infrastructure, we need to figure out the components that source our features or (possibly) bugs. If the entire codebase has been migrated to a VCS, we have an advantage because it’s easier to understand the dependency tree of every functionality. However, these repositories are repleted by old metadata that is no longer needed but keeps affecting our development cycle. Wouldn’t it be necessary to execute a process to remove these components from our organization? Well, thanks to the Salesforce CLI, now that’s possible.</p><h3>The weight of legacy metadata</h3><p>There are a couple of reasons to remove deprecated components from our instances. The first one is that these components tend to increase debugging time. Let’s suppose we have to apply a critical update for Apex. To find all the affected classes for this update, we will encounter code that is not functional anymore. However, we will spend a couple of hours discarding them from the code refactoring, and these scenarios will be more common as the codebase grows.</p><p>The second reason is that old components will affect our CI integration. Let’s suppose we have a Lightning controller written in Apex designed to update the account object. If the controller gets deprecated, we are not going to support this code in subsequent sprints. However, if we add some new mandatory fields to the account object and the unit test for the controller does not contain this definition, it will break our deployments. In this case, either we remove the controller class and its test from our organization or keep updating them.</p><p>Nevertheless, our dependency tree for deprecated code is way more complex than that. It includes summary fields, Visualforce pages, and triggers, and we cannot even deactivate triggers in production environments using declarative tools. Keep in mind that it would be a questionable practice to remove the classes only from our repositories. So, what is needed to keep our codebase clean?</p><h3>Track everything in your organization</h3><p>The first step to ease our deployments is to track all the components in our Salesforce instances. The right way to do it is to migrate all your metadata to a VCS, like git. This way, the dependency tree will be more readable for all our team members, and you can easily keep an eye on how your changes affect other projects.</p><p>This principle also applies to deprecated metadata. If we track the dependencies between all these components, we will know how to remove them from our organization. As you may notice, if you version your projects initially, <em>identifying deprecated metadata is reduced to the simple task of taking a subset of these components</em>.</p><h3>Deploying destructive changes</h3><p>Creating Salesforce DX projects and tracking them using git are topics that would take another two articles. However, <a href="https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_create_new.htm">many documents cover these subjects</a>. In this case, we will take for granted the use of these tools and focus on how to remove metadata components from our Salesforce environments using the CLI.</p><p>The first thing that we need to understand is that deleting metadata is not different from deploying it. That’s because some options of the Salesforce CLI are mapped directly to the Metadata API. <a href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_deleting_files.htm">The API has a method that is identical to the one that we are going to use here</a>, but sfdx has the advantage that we can integrate it into a shell script.</p><h4>1. Creating a new Salesforce DX project</h4><p>Although it’s unnecessary to retrieve the metadata we will delete<em>, it’s a good practice to create a backup</em>. If we already installed the sfdx-cli package in our local environments, we can invoke the sfdx command to execute all the tasks. Let’s first create a project directory called TestingComponentsDeletion:</p><pre>sfdx force:project:create --projectname TestingComponentsDeletion</pre><p>The directory structure should be something similar to this:</p><pre>TestingComponentsDeletion<br>├── README.md<br>├── config<br>│   └── project-scratch-def.json<br>├── force-app<br>│   └── main<br>│       └── default<br>│           ├── applications<br>│           ├── aura<br>│           ├── classes<br>│           ├── contentassets<br>│           ├── flexipages<br>│           ├── layouts<br>│           ├── lwc<br>│           ├── objects<br>│           ├── permissionsets<br>│           ├── staticresources<br>│           ├── tabs<br>│           └── triggers<br>├── jest.config.js<br>├── package.json<br>├── scripts<br>│   ├── apex<br>│   │   └── hello.apex<br>│   └── soql<br>│       └── account.soql<br>└── sfdx-project.json</pre><h4>2. Fetching deprecated metadata</h4><p>Either you can fetch your components from your instance or copy them from other repositories you have. Let’s suppose we need to remove four objects; an object called TestingObject__c; a field ExtraField__c that is member of an object we want to preserve called ExtraObject__c; and two classes that depend on these objects, TestingObjectController and TestingObjectControllerTest. First, we need to fetch them from our instances with the following command:</p><pre>sfdx force:source:retrieve --metadata \<br>ApexClass:TestingObjectController,\<br>ApexClass:TestingObjectControllerTest,\<br>CustomObject:TestingObject__c,\<br>CustomField:ExtraObject__c.ExtraField__c</pre><p>As you may notice, you need to put the metadata type before every component’s name. But is more important to note that it’s possible to retrieve even individual fields without affecting the object definition or other fields.</p><h4>3. Listing components on manifest files</h4><p>We need two create two manifest files just as the official documentation specifies. Let’s first make a directory called deprecationManifests. Then we will add a package.xml file containing only the API version for our deployment and another file called destructiveChanges.xml, where our components will be listed.</p><p><strong>deprecationManifests</strong></p><pre>deprecationManifests<br>├── destructiveChanges.xml<br>└── package.xml</pre><p><strong>package.xml</strong></p><pre>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot; standalone=”yes”?&gt;<br>&lt;Package xmlns=”<a href="http://soap.sforce.com/2006/04/metadata">http://soap.sforce.com/2006/04/metadata</a>&quot;&gt;<br> &lt;version&gt;51.0&lt;/version&gt;<br>&lt;/Package&gt;</pre><p><strong>destructiveChanges.xml</strong></p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot; ?&gt;<br>&lt;Package xmlns=&quot;<a href="http://soap.sforce.com/2006/04/metadata">http://soap.sforce.com/2006/04/metadata</a>&quot;&gt;<br>    &lt;types&gt;<br>        &lt;members&gt;TestingObjectController&lt;/members&gt;<br>        &lt;members&gt;TestingObjectControllerTest&lt;/members&gt;<br>        &lt;name&gt;ApexClass&lt;/name&gt;<br>    &lt;/types&gt;<br>    &lt;types&gt;<br>        &lt;members&gt;ExtraObject__c.ExtraField__c&lt;/members&gt;<br>        &lt;name&gt;CustomField&lt;/name&gt;<br>    &lt;/types&gt;<br>    &lt;types&gt;<br>        &lt;members&gt;TestingObject__c&lt;/members&gt;<br>        &lt;name&gt;CustomObject&lt;/name&gt;<br>    &lt;/types&gt;<br>    &lt;version&gt;51.0&lt;/version&gt;<br>&lt;/Package&gt;</pre><p>You can always go to the Metadata API documentation to read the proper way to list your components.</p><h4>4. Deploying changes</h4><p>Once we have everything set up, the last part is to deploy the manifest files to our environment:</p><pre>sfdx force:mdapi:deploy --deploydir deprecationManifests \<br>--targetusername developer-org \<br>--testlevel RunSpecifiedTests \<br>--runtests MOCKED -w 3</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6oxcENWCyS07cjjxG0wWOA.gif" /><figcaption>Deploying destructive changes</figcaption></figure><p>Since the sfdx command does not allow us to deploy anything to production environments without specifying a test run, we added a placeholder string MOCKED to satisfy the command requirements. However, you can use any word you want. The reasons why that workaround does its job are not evident, but we can assume that since we are not creating or updating any Apex class, the API does not check for code coverage. Yet, I have tested this <em>feature</em> only on versions sfdx-cli/7.103.0 darwin-x64 node-v14.17.0 and sfdx-cli/7.99.0 wsl-x64 node-v12.22.0.</p><p>However, don’t forget that the ideal scenario is to execute all tests in the organization after every deployment, and that’s because Salesforce enforces a test-driven development methodology. If our deployment affects code coverage, there is a sign that we probably are missing something. The capacity to execute all tests in our organization at once will lead us to a seamless continuous integration process.</p><h4>References</h4><ul><li><a href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_deleting_files.htm">Deleting Components from an Organization | Metadata API Developer Guide | Salesforce Developers</a></li><li><a href="https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_create_new.htm">Create a Salesforce DX Project | Salesforce DX Developer Guide | Salesforce Developers</a></li></ul><p>I created a repository with the components listed in this article if you want an out-of-the-box testing experience:</p><p><a href="https://github.com/AlbertoMata/testing-components-deletion">AlbertoMata/testing-components-deletion</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e434c268f257" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dynamic User Interfaces  with Lightning Aura Components]]></title>
            <link>https://alberto-mata.medium.com/dynamic-user-interfaces-with-lightning-aura-components-6a5ee89a361c?source=rss-8e8d4e8bc6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a5ee89a361c</guid>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[lightning-components]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Ángel Alberto Mata]]></dc:creator>
            <pubDate>Sat, 20 Apr 2019 04:33:24 GMT</pubDate>
            <atom:updated>2019-05-02T00:08:08.578Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dynamic User Interfaces with Lightning Aura Components : Synchronizing the DOM with the Application State</h3><p>As Salesforce developers, we have to extend the implementation of the company we work to provide a customized experience for our co-workers in other areas. As time passes, I notice that Salesforce interfaces, especially in its classic version, are just a collection of web forms to insert records in the database. However, the requirements we face for the front end usually describe applications with highly interactive behavior, and the solutions should be implemented using the Salesforce toolset; how do we do that?</p><p>The ancient Visualforce does well its job with static web forms, but just like any other page-centered framework, it was not primarily designed to support dynamic contexts. Although there are some <a href="https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_components_intro.htm">workarounds</a> for this, everything keeps running on the server side, increasing the application response time. To manage Visualforce as a client-side application, we need to manipulate the raw DOM after a page returns to the browser, turning our <em>apex page</em> into a JavaScript application.</p><p>The Aura framework, on the other hand, is already integrated with JavaScript, allowing developers to run applications on the browser without tricky hacks. It imposes a composition architecture and provides data bindings to make cleaner the data flow across components. The programming model is pretty different compared with Visualforce, but it also represents a considerable improvement as a web framework.</p><p>In this article, I’ll try to build the context to develop interactive interfaces with Aura. While it’s not intended to introduce beginners to the framework’s syntax, it gives some hints to compare standard JavaScript with modern web frameworks. The syntax topics are covered by the official documentation and the well-known Trailhead courses.</p><h3>The basic problem</h3><p>With vanilla HTML and JavaScript coding, developers have to implement their own sequences <em>to turn data into a particular look of the interface</em>. If this data change either by user input or other kinds of events, the interface should change accordingly. Managing this task is somewhat easy for small pages, but as web applications become more complex, implementing that logic using linear sequences for every event handler is hard to follow and maintain in the long term.</p><p>Let’s look at the simplest case, the task of projecting user input back to the screen. With the help of jQuery, the code looks something like this:</p><pre>&lt;!-- string_projection.html--&gt;<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;</pre><pre>  &lt;head&gt;<br>    &lt;meta charset=&quot;utf-8&quot;&gt;<br>    &lt;script src=&quot;jquery-3.3.1.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;string_projection.js&quot;&gt;&lt;/script&gt;<br>  &lt;/head&gt;</pre><pre>  &lt;body&gt;<br>    &lt;input id=&quot;input_field&quot; type=&quot;text&quot; /&gt;<br>    &lt;div id=&quot;output_field&quot;&gt; &lt;/div&gt;<br>  &lt;/body&gt;</pre><pre>&lt;/html&gt;</pre><pre>// string_projection.js<br>$(function () {</pre><pre>  //DOM ready<br>  var str = &quot;&quot;;<br>  var input_field  = $(&#39;#input_field&#39;);<br>  var output_field = $(&#39;#output_field&#39;);</pre><pre>  input_field.on ( &#39;input&#39;, project_input_to_output );</pre><pre>  function project_input_to_output () {<br>    str = input_field.val();<br>    output_field.val(str);<br>  }</pre><pre>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*kBHtvHLSrqL-EjUuABQ14A.gif" /><figcaption>Output changes as fast as input comes in.</figcaption></figure><p>In this simple case, the str variable is unnecessary to link both tags. However, when several DOM sections react to other sources, either to server communication or new input events, variables like str serve us as a bridge between those events and the user interface. In this context, these variables represent the <em>application state</em>, and this structure is central for managing the logic of the view. It is not trivial that from the <a href="https://teropa.info/blog/2015/03/02/change-and-its-detection-in-javascript-frameworks.html">very beginning of .js frameworks</a>, the main goal of these solutions has been to develop a layer of abstraction to synchronize this state with the DOM, making the application’s behavior more organic.</p><p>Now, to extend our previous example, we could program a sequence for each event that modifies the state and to wrap some redundancies in shared functions, keeping a linear path for every event that reaches the DOM. For complex projects, however, the data flow can be difficult to follow and maintain, since the number of sequences could get overwhelming. Another approach, of course, is to code our own implementation of an <a href="https://www.oreilly.com/library/view/learning-javascript-design/9781449334840/ch09s05.html">observer</a> pattern to notify fields when the state has changed, and that’s not a trivial solution these days.</p><p>We do have better alternatives. JavaScript has evolved over the years encapsulating generic solutions using higher levels of abstraction. jQuery was a big improvement in terms of readability and portability, but it was just a wrapper library; like a series of macros for JavaScript. Modern web frameworks offer features taken from desktop platforms to run dynamic applications on the browser. They represent better architectures and developers can exploit them to build robust systems. Following this path and trying to replace Visualforce, Salesforce gave customers a solution that could compete with these new frameworks: the Lightning Aura.</p><h3>The Salesforce’s .js Solution</h3><p>The first thing we note from this framework is its composition architecture. Applications should be divided into significant parts and they must do what they were designed for and nothing more. This simplifies the general structure of the project and allows us to reuse components.</p><p>Let’s replicate our previous JavaScript application on this framework to illustrate some points:</p><pre>&lt;aura:application&gt;</pre><pre>    &lt;!-- Component state --&gt;<br>    &lt;aura:attribute name=&quot;str&quot; type=&quot;String&quot; /&gt;</pre><pre>    &lt;!-- Markup --&gt;<br>    &lt;lightning:input value=&quot;{!v.str}&quot; /&gt;</pre><pre>    &lt;div class=&quot;slds-m-around_small&quot;&gt;<br>        &lt;span&gt;{!v.str}&lt;/span&gt;<br>    &lt;/div&gt;</pre><pre>&lt;/aura:application&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*Rgnr61VpSGdAT_4VdkY7aQ.gif" /><figcaption>As fast as data the value of <strong>str</strong> is changed, the framework automatically updates the DOM.</figcaption></figure><p>The most remarkable thing of this textbook example is the lack of JavaScript code to project data back to the output. That’s possible thanks to expressions like {!v.[ATTRIBUTE_NAME]}. They are expanded in every place where they appear and their changes are synchronized with the DOM. In general terminology, these expressions are called <em>data bindings </em>and represent an essential tool of every modern web framework. Inside Aura, they are a communication channel in the parent-child component hierarchy.</p><p>Next, we have the &lt;lightning:input/&gt; tag. This section is not a simple input field but a custom component that encapsulates the HTML markup, its style definition and the routines needed to update str. The value of this attribute is shared with the field as a reference, which means that other child components can manipulate it and still maintain the same state across all of them. That way, the data flow in the hierarchy of components is <em>bidirectional, </em>and should be intuitive how to develop web forms using this programming model.</p><p>Some developers point out that this kind of data flow is hard to debug, but I found that works perfectly in some cases. The key idea is to track how far and attribute will affect the component tree. While some attributes are local to one component, others affect larger branches. However, only the root of the tree or one of its subsections should have the authority to update the rest of the hierarchy. We always should be able to track state changes to avoid unexpected behavior or another sort of errors. Anyway, expressions like {#v.[ATTRIBUTE_NAME]} (with the hash instead of the exclamation mark), allow us to enforce a <em>unidirectional data flow, </em>which seems to be less error prone but force us to use JavaScript code with simple cases.</p><p>There is a question remaining: how do aura components like aura:if or aura:iteration know when its local state has been modified? The key is a method handler named change. This handler detects transformations in the value of a single attribute and triggers a function to manage them. Doing so, we move code routines from reacting to application events to managing changes of the whole state. DOM events are just handled to update this structure and the rest is responsibility of a centralized sequence that updates the entire component; just like a simplified version of an observer pattern.</p><h3>The List Example</h3><p>Most frameworks show an elemental example of a list of items to introduce beginners into the basic syntax. The following <a href="https://github.com/AlbertoMata/lead_list_example">git repo</a> contains that basic example with a hard-coded list of leads. While it could be simpler, it tries to show the most common scenarios for an Aura application. It contains an example of custom events, data bindings, and conditional styling. Also, the directory is a Salesforce DX project, which simplifies the task of migrating the components between orgs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*16dMTkbHE5TbeQe3RJurTw.gif" /><figcaption>A simple list of leads ordered by priority (Icons courtesy of <a href="https://www.freepik.com/">Freepik</a> from <a href="https://www.flaticon.com/">Flaticon</a>).</figcaption></figure><h3>Other perspectives and the future</h3><p>When data bindings are not enough for the project, we could implement our own state handler <a href="https://developer.salesforce.com/blogs/developer-relations/2016/12/lightning-components-code-sharing.html">as a JavaScript library</a>. Another approach is the<a href="https://youtu.be/94ZkxJX3w_0"> use of Redux</a>, a library that promotes a <em>one-way data flow. </em>Although it was primarily designed for React.js, it can be also used with Aura.</p><p><a href="https://developer.salesforce.com/blogs/2018/12/introducing-lightning-web-components.html">With the launch of the Lightning Web Components this year,</a> Salesforce pretends to embrace the new HTML and JavaScript standards. As developers, we have to take the decision of migrating or not Aura applications into these new components. However, what’s the point of using a lower-level and probably more complex syntax for something that Aura does in a decent way?</p><p>Of course, the framework has its own issues in terms of efficiency and consistency, but do the general solutions of these problems matter the cost of adapting our developments to HTML templates? I hope this model allow us to choose our own set of JavaScript tools for the front end because that would be a giant step in order to open Salesforce for every developer.</p><h3>References</h3><ul><li><a href="https://teropa.info/blog/2015/03/02/change-and-its-detection-in-javascript-frameworks.html">Change And Its Detection In JavaScript Frameworks</a></li><li><a href="https://www.oreilly.com/library/view/learning-javascript-design/9781449334840/ch09s05.html">Learning JavaScript Design Patterns</a></li><li><a href="https://medium.com/dailyjs/when-do-i-know-im-ready-for-redux-f34da253c85f">When do I know I’m ready for Redux?</a></li><li><a href="https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_components_intro.htm">Dynamic Visualforce Components | Visualforce Developer Guide | Salesforce Developers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a5ee89a361c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>