Update Records Element

 

  • Update Records Element

        • Updating Records
        • We must have the recordId to update a record

  • Update Records Element


    Once again the name of this element is pretty obvious what it does.

    In this example, we are updating the address on Contact records where it is blank - by using the address of the related account.

    • Step 1: Start with Get the Account record (only one).
    • Step 2: Get all the related Contact records (multiple).
    • Step 3-5: Loop through each contact record and if the Mail Address is blank, assign the Account Address.
    • Step 6: Add the current contact record to a collection variable for later updating (rc_ContactsToUpdate).
      • Continue through the loop until all contacts are done.
    • Step 7: Update all the selected Contact records with the new address.

     

    When we have exercises where you are creating a flow like this, you will be provided with all of the detailed steps. For now, we just want to introduce the concepts.





    We cover loops in more details in other parts of the course, the important part here is the Update Records element. 

    It is pretty simple because we followed the best practice and did this outside the loop.

    All we need to do is provide the name of our record collection: rc_ContactsToUpdate.

    This is a variable that contains all the records that we need updated.


Exercise: Update Records


Update Records

Before you can update a record, you need to get the record, display it and allow the user to make the changes.

Create a new Screen flow, when you have finished, it will have all these elements:



First, you will need to add a Screen element and in this element, add a Lookup component so you can search for the contact to update.

You may find the configuration of this component a little strange as you will be using the CampaignMember object for the lookup.

What? Why you ask?

Ok, the lookup component needs to use an object that has the contact field as a lookup field.



Take a look at the contact object:



Ideally, you would want to use Name but as that is not a lookup field it will not work for this example as it is not a lookup type field.

Take a look at the Campaign Member object, it has a field named Contact (ContactId) that is a Lookup on contact, exactly what you need!

You don't need to populate any records on the Campaign Member object, you are simply using that relationship for your search. (a neat trick!).



Configuring the lookup component then becomes simple once you understand how we are using the Lookup relationship:

  1. Give our field an API Name: contact
  2. The field we want to search by is ContactId (the lookup field)
  3. The label on the screen will be Contact
  4. The object we are searching via is CampaignMember



Once you have selected the contact record you wish to update, the next thing to do is to get the record so you can display the fields.

Add a Get Records component and configure as follows:

The value of contact > Record Id comes from the record you selected in your lookup in the previous screen.

Note: You only need to get one record (the contact you wish to update).



Next, add another Screen component to display the contact record and add the three components shown:



Configure the Name component:



Configure the Phone component:



Configure the Email component:



Next, you need to create a record variable that you can copy the values from the input screen, before updating the record.

Create a new variable as follows:

Note: You only need to store a single record, not multiple values.



Add a new Assignment element and assign the values from the input form to the new record (r_contact):

Note: You must pass Contact ID to the update records element (next). You can get the value of that from the get record you did earlier.



Now you have assigned the updated record values to r_contact, it's time to update the record.

Add an Update Records element and configure as follows:

All we need to pass to this is the r_contact record.


Ok, the configuration is complete!


Save, activate and click debug.

Search for a contact record and click Next to select it:



Update the First Name and Last Name. (email and phone too if you wish):

Click Next to Save the updated record.



Return to your Sales App and open the contact record to confirm your changes have been made:






Congratulations! cool

No comments: