How to Modify a SOQL Query with Two Objects

A SOQL query pulls certain records and fields into Apex Code. This post explains a SOQL query that includes Contacts and their related Opportunities from the Year End Tax Receipt app, but I aim to help you understand SOQL in general.

For those of you that want to modify the Year End Tax Receipt for your specific donors:

  • Follow along with this post to modify which records will be displayed in the table of gifts last year. We’ll look at an example of only included gifts marked tax deductible.
  • Look at the original post to learn how to modify which columns appear in the gift table.

Understand the SOQL

Here’s my SOQL query. This is how I get the records and fields that I’m going to do something with later on in the code.

1 [SELECT LastName, id,Gifts_Last_Year__c, 

2 (SELECT Id, CloseDate, Amount FROM Opportunities 
                                                                                  
3 WHERE CALENDAR_YEAR(CloseDate) =:year 

4 AND IsWon = True 

5 ORDER BY CloseDate) 

6 FROM Contact WHERE npo02__OppAmountLastYear__c > 0 

7 WITH SECURITY_ENFORCED]          
    
Continue reading How to Modify a SOQL Query with Two Objects

Flow Loops Just Got Simpler

Actually, I don’t know when this change happened, but I just noticed that Flow loops now only have four steps instead of five. The two assignments can now be consolidated into one.

You still have to add the record to a collection, but you can use the same assignment element.

Example 1: Update the record currently in the loop.

  1. Use a Get Records element to create a collection of records to loop through.
  2. Add a loop element
  3. Add ONE assignment element
    • Update field values for record currently in the loop.
    • Create a new record collection variable to hold the records you want to update.
    • Use the same assignment element to add the record currently in the loop to the new collection.
  4. Add an Update Records element to update the records in your new collection.

Follow my blog to keep up to date on Flow and Salesforce


Example 2: Create new records.

  1. Use a Get Records element to create a collection of records to loop through.
  2. Add a loop element
  3. Add ONE assignment element
    • Create a new record variable (not collection) to hold the values of the new record you want to create.
    • Assign field values to your new record variable.
    • Create a new record collection variable to hold your records that you want to create.
    • Use the same assignment element to add the record currently in the loop to the new collection.
    • Close the loop.
  4. Add a Create Records element to create the records in your new collection.

Previously step 3 involved two assignment elements!

Watch this recording on Flow loops.

This is how you would combine steps 3 and 4 into one assignment!

Live Flow Loops Training 9/14 10:30am PT/ 1:30pm ET

Join me TOMORROW on Automate This, the Salesforce Admins series hosted by Jennifer W. Lee. Follow along with the written instructions as I show you how to build a flow loop!

Open this YouTube link up tomorrow at the right time and watch LIVE!

Log Email Sent Through Flow on a Contact Record

Shows the activity timeline of a contact record with one email message stored there sent at 2:46pm today with subject "Welcome to the family, Jemma!"
Log an email message on the contact record like this one.

When sending email from a contact record, it magically logs the message to your activity log. In classic, emails were/are automatically logged to the Activities related list. Well, flow doesn’t do that for you. Let me show you how to log it so you and your colleagues know when an email was sent to a contact.

After you add a “Send Email” action to your flow, add two more Create Records elements to the canvas. You will create records of these objects:

Continue reading Log Email Sent Through Flow on a Contact Record

Visual Studio Code: An Adventurous Admin’s Way to Move Metadata to Another Org

A few weeks ago I shared how to use a package to move metadata between unrelated orgs. That solution is perfect for sharing something you built with other people.

See you later, deployment fish!

When you’re moving metadata between orgs that you control (related or not), try Visual Studio Code! Don’t worry about the “Code” part. You don’t have to read it or write it to use VS Code.

VS Code has lots of benefits that I don’t understand yet (somehow you can use it to move profiles and FLS). I will now teach you all I know. 1) How to deploy between two orgs. 2) How to paste in some code to deploy sections in Flows.

Huge thanks to Brian Ricter for teaching me how to do this!

Prerequisites:

  • Install Visual Studio Code. It’s free!
  • Install the Command Line Interface
  • Install the Salesforce Extension Pack

If you haven’t done any of those yet, complete this really helpful trailhead Quick Start.

Continue reading Visual Studio Code: An Adventurous Admin’s Way to Move Metadata to Another Org

10 Steps to Get Started with Salesforce Flow

Here’s my ordered list to help you get started learning Flow. It includes short and long videos, Trailhead modules and projects, hands-on training and “your turn” challenges to help you stretch what you’ve learned.

Starred items I had a role in creating.

1. Watch 4 Short Videos*

Get a very basic understanding of flow and some of the more difficult to grasp concepts. (Watch the first 4 and come back to the loops video later).

2. Complete the trail Build Flows with Flow Builder

This gets you started in Flow Builder and applies concepts you learned in the videos.

Continue reading 10 Steps to Get Started with Salesforce Flow

Understand Tricky Flow Concepts

Head on over to the Salesforce Admins blog to watch 5 new videos that I helped create that explain some tricky flow concepts with fun metaphors and images!

“Get Records” is like a big claw that grabs records from your database and
pulls them into Flow as variables!

Are you wondering…

  1. What are the most common types of flow?
  2. Why do I need to store information in variables?
  3. What is a record variable?
  4. Why on earth do I need to “Get Records?” Shouldn’t the records already be there?
  5. What does it mean for a variable to store multiple records?
  6. What are loops?
  7. What are Create Records, Update Records, and Delete Records?

Then these 5 new videos can help!

Year End Tax Receipt for Donors

UPDATE 1/13/23: If you’re installing today from AppExchange, it’s a new version 1.4 that you can run by running a flow called Year End Tax Flow. New detailed instructions below. To install the new version, please uninstall the old version first! Go to Setup, search for “Installed Packages,” find “Year End Tax” and uninstall that.

Easy peasy list of all last year’s donations

Send your donors (contact records only) a tax receipt at the beginning of the new year listing all of last year’s donations. For Salesforce Nonprofit Success Pack users, this unmanaged package will generate a table for each donor listing the gifts they made last year. Use your own email to send a tax receipt by email. The table lists the amount, date and, optionally, the campaign name of each donation.

Package includes this sample template.

Thanks for the great app, just in time…Simple, easy, elegant, and just what we needed.

David, Eaglesrest.org
Continue reading Year End Tax Receipt for Donors

Flow: Display Photo or Upload Photo

The flow will display either a photo or remind you to upload one. On any object!

How It Works:

The Flow looks for a file attached to that record with the title “SalesforcePhoto” (or another phrase of your choosing).

The File gets the title from the name of the file when you upload it. If you upload SalesforcePhoto.jpg, the title becomes “SalesforcePhoto.” You could also open the File details in Salesforce and change the title.

If that file is found, it’s previewed thanks to the work of Narender Singh, (of course)!

If not found, it asks you to upload a file from your computer named SalesforcePhoto and attaches it to that record. From then on the, the flow displays the photo!

We are using the app because constituents and donors are more than just a record, and seeing their faces humanizes the data.

Donna, Vote Solar
Continue reading Flow: Display Photo or Upload Photo