Flow Action – Get/Search with APEX

What does it do?

It allows you to run a SOQL or SOSL query to retrieve a collection of records. This means you can select records using powerful and robust SOQL queries, or leverage the same search Salesforce offers in the Omnisearch bar, complete with fuzzy logic and incomplete words.

 

It can:

 

  • Work with any object
  • Get records without sharing. eg. moving a community user to an account they don’t yet have access to
  • Use IN statements – If you provide a list of Ids
  • Use Salesforce’s powerful search language to search all fields (with phonetic matching)
  • Stop using multiple get statements to find things
  • Advance where statements. Use OR logic in gets

 

Install

Version 0.1

 

How to use

1/ Add an “action” to your flow and search for “Get/Search with APEX”

2/ Select the object name

3/ Add in the fields to find and the rest of the input fields

4/ Define a collection variable for the record output

5/ Then loop through each record and do as you like

 

Add Search queries

If you’re using a search query, you’ll need to add them to a list. This is done by setting up a text type collection variable and then using an assignment. Remember that this will do a search across most fields and you don’t need to tell it which field to look in.

Field Definitions

 

Input Description Example
FieldApiINames – to return Comma-separated list of field API names. ID,Name,Primary_contact__c
Where Clause A text value defining the where clause. You must not SOQL to add this.
You should be able to add nested statements and do fun advance things here like normal apex.
createddate = Last_N_Years:2
Object APi Name The name of the Object Account
List of Ids You load a number of Ids into this variable and then it will return all of these.
This uses the Id IN :IdsList ability in Apex to find them all in one go.
Must be this type
– Allow multiple must be checked.
Bypass Sharing We used this for checking for duplicate records before inserting. Or if you want to move a contact to an account that the user doesn’t have access yet. {!$GlobalConstant.True}
Search Queries Collection of values to search Must be this type
– Allow multiple must be checked.
Search Scope

The scope of the SOSL search (default ALL FIELDS)

see more.

ALL FIELDS
     
outputCollection The records being returned Create a record variable-Allow multiple must be checked.

 

 

Acknowledgements

 

 

Lightning Navigation Button

Declaratively add buttons to lightning flows, screens or communities

We created the Advanced Navigation button to fill a need in the user base.  Salesforce is fantastic out of the box but there are limitations in particular with buttons.  This managed package looks to meet some of those needs using clicks and not code.

The Advanced Navigation button, dubbed the “Magic button” by some, can be used for a variety of uses:

  1. Add bespoke navigation options in a flow. For example, replace the “Next” button with a “Save and View” button.
  2. Launch new record or edit page. For example, launch the create new account page with a specific record type.
  3. Auto launch a quick action. For example, automatically launch the new opportunity quick action when an account with the type “prospect” is created.
  4. Navigate to another page. For example, auto navigate to another record page when a certain status is reached.

Design

The Advanced Navigation button allows the user to change the appearance and text on the button.

“Button Style”

Preset styles shown below, an easy way to style up a simple button without any further work required. See documentation.

“Button Label”

Choose what text should appear in the button itself.  Text choices on buttons have traditionally been limited in Salesforce, and this removes that limitation to an extent.  You can choose to have “Save”, “Apply”, “Click this here”, “You are wonderful”, whatever text you deem suitable.

“Button CSS style”

Specify the style using CSS if using “text”.  If text is not used i specifieds the style of the div containing the button.  At present it is not yet possible to add styles directly to the button.

Utility Actions

“Auto Start without button press”

Exactly as the name states.  It will auto-launch your chosen functionality, eg: flow or redirect without any user interaction.  You can have this on a page where you want an action to kick off as soon as the page launches to streamline processes.

“Navigate to URL”

This nifty action will guide the user to the specified URL/page when they click on the button.  Say you want the finish action to take them to a specific website or another record page, this is a really easy way to do it.

“Launch a quick action”

This is an extremely useful functionality where you can use the button to launch a quick action: For example: add a task on a new opportunity, or create an invoice on a won opportunity.  The quick action does need to be on the page layout for this to work, and this needs to be populated with the API name of the quick action

“Flow action”

Expands your choices beyond the standard Flow buttons. You can turn them off and use the Navigation Button to set the flow action to either: next, back, pause, or finish.  See docs.

“Output: Button Clicked?”

Use this to ascertain if a button is clicked in a flow. When the button is clicked it will set the variable here to true. This is useful if you have multiple buttons on the page to see which button was clicked on the flow screen.  

“New Record:Object Name”

If you want to launch the create a record screen enter the object name here.

“New Record:Recordtype ID”

Only populate if you want to create a record. Enter the record ID to use. This alters picklist values and page layout choices.

“New Record:Predefined Variables”

You can prefill fields on the page. To do so add in the values in a JSON style format. Field:Value. “APiFieldName:Value,APiFieldName:Value”

For example, “FirstName:Ben” or “FirstName,Ben,LastName:Smith”

“Edit: Specific record Id to edit”

If you want to edit you can pass a specific record ID through to edit that record. For example a related record.
If blank it uses the recordId from the page it is on

“Edit:Do you want to edit a record?”

Mark as true if you want to launch the edit record page.

Send email-alerts and log the email.

Use process build, flow or apex to send an email

See the sent email in the activity feed

 

 

We strongly recommend using Flows to send emails – they are better than process builders and easier to debug.

 

#1 Install

  • Upvote the idea for Salesforce to make this standard.
  • Install the package – this only works on Enterprise edition and up as it requires apex code. Or view in GitHub.
  • Open a process builder (or flow)
  • On the actions select the “Apex Class” option

#2 Select the recipients

  • Related To ID – the ID of the record you want to relate this to (eg. account or opportunity). Not a contact, lead or user
  • Contact/Lead ID – Required if you use an email template
  • ‘To – To Addresses’– enter a comma-separated list of email address. Eg. dan@salesforce.com, bob@smith.com
  • ‘To – bcc Email Addresses’– comma-separated list of email addresses to go into the BCC field
  • ‘To – cc Email Addresses’ – comma-separated list of email addresses to go into the CC field
  • ‘TreatTargetObjectAsRecipient’ – true or false – if false it won’t send the email to the contact or lead

#3 Enter the email content

  • ‘Body – Template Id’  – the id of the email template. eg. 00X600000012maf
  • Or instead, use ‘Body – Template Unique Name’ with the unique name (API name) of the email template. eg. “Email_template_name”

Or write your own content. You cannot use custom content with an email template due to a limitation in Salesforce Apex:

  • Subject – specify the subject
  • ‘Body – Plain Text ‘ – enter a plain text body
  • ‘Body – Html’ – or an HTML body
  • ‘Body – Use Signature’ – include the user’s standard signature

#4 Attachments

  • ‘Attachment – ContentDocument – Comma Separated Ids’ — This is the ContentDocumentId of the document you want to attach. It will take the latest ContentVerion.
  • ‘Attachment – ContentVersion – Comma Seperated Ids’ to specify a specific ContentVersionId
  • ‘Attachment – Comma Separated Ids’ – List of Attachment Ids

#5 Optional Extras

  • ‘From – Org Wide Email Address’ – Specify a specific from address. This must be an org wide email address.
  • ‘Setting – Save As Activity’ – You decide if you want to log the email as an activity or not. Defaults to True
  • ‘Setting – Apex Error Email’ – Send an email to the specified address containing all errors
  • ‘Setting – email Opt Out Policy’- this helps define what you do if a user has opted out of receiving email

Limitations

  • You cannot use Email Templates without a Lead or Contact Id. This is a limitation of Salesforce Apex code. One workaround is to create a dummy contact. We know this is not ideal
  • Apex email sends have a limit of 5000 per day across your org. Note that all recipients in the to, cc and bcc fields count against this limit  An example being an email with 2 addresses in the “to” field and 1 address in the “cc” field would count as 3 calls against the limit.

Demo

The Ultimate Free Salesforce Admin Tools

Pragmatic Solutions while we wait on Salesforce Ideas

We love Salesforce and love the flexibility it gives us. There are times where functionality isn’t quite released yet. So this page contains a list of tools you can use until the functionality is released. They are all designed for admins to be fired from process builder.

We operated on the following principles:

  • Avoid replicating standard functionality
  • Build everything declaratively is possible (then anyone can understand and tailor it)
  • Avoid Apex – it is slow to develop on, harder to change, hard to delete and requires testing.
  • Use process builder and not triggers
  • Easily removable – we don’t want to install multiple features at once as we are planning for Salesforce to remove the need for workarounds with standard features.
Process_Builder_v637dz

Launch with Process Builder

Add Opportunity Contact Roles

A flow that checks if an opportunity contact already exists before adding one. Inputs: Contact ID and Opportunity ID. Unmanaged Package Idea to upvote

Add/update Campaign Members

Checks where a campaign member exists and then adds one. If you add straight from process builder you will get a flow error on duplicates. You can optionally choose to overwrite the status by entering a status and marking ‘OverrideStatus’ as true

Install Link. Idea to upvote

Delete Anything

Not supported by us as you can do it in flows and it’s a rare business case. There is this github package that can do it for you though: https://github.com/mshanemc/processBuilderBlocks 

Idea to upvote.

Auto Convert leads

Convert Leads into Accounts, Contacts, and (optional) Opportunities on-demand according to your criteria. This solution includes one apex class and its unit test. See instructions in stall link for setting this up with Process Builder or Flow to automate your lead conversion needs.

Install Link. Idea to upvote.

Credit: Doug Ayers

Convert Contact to Person Account

Made with in process builder to work on professional edition. For lot’s of our client’s, it’s an all or nothing switch to person accounts. Data gets messy when you have contacts and person accounts in the same org. Unfortunatly, at present you cannot create a person account from a contact lookup, only contacts. So this tool in the background converts the contacts to a person account.

You will need to create a process builder to trigger this flow. Make the criteria a contact with no account. Launch this flow as the immediate action. Enter the record types and names. Mailing addresses are copied to billing and shipping.

Install Link. Idea to upvote.

Campaign Activator

Campaigns need to be active to work in Salesforce lookups. This simple process build will activate the campaign on the start date and deactivate the campaign a day after the end date.

Install Link. Idea to upvote .

Better Chatter Posts

We cannot post to related records in process builder. Use this flow to specify the record, message and anybody you want to mention (only one user).

Install Link. Idea to upvote.

 

If you need more advance features like rich text chatter posts or choosing the post is posted by see: https://github.com/DouglasCAyers/salesforce-chatter-bot-feeds

NPSP Process BuilderTools

Add/Update Relationships

You can create relationships with process builder. But, if the relationship already exists it will create a duplicate. Use this flow to check for an existing relationship and then only create a new one if the contacts are not already linked.

Install Link. Idea to upvote.

Add/Update Affiliations

You can create Affiliations with process builder. But, if the Affiliations already exists it will create a duplicate. Use this flow to check for existing affiliations and then only create a new one if the contact and accounts are not already linked.

Install Link. Idea to upvote.

Applications and Triggers

Rollup Anything (Declarative Rollups for Lookups)

A comprehensive and must use tool! Perform rollups on schedules or in real time from any lookup. It’s free and better than roll up helper or the built in roll-ups (which have major limitations)

Install Link. Idea to upvote.

Credit: Andy Fawcett

Declarative Scheduler (and add campaign members automatically)

Run monthly, daily, hourly schedules the declarative way. This tool utilises Salesforce’s report engine to select the records and fields you want to update. Then this tool changes a datetime field to trigger a process builder

Instructions. Idea to upvote.

Opportunity Primary Contact Role Trigger

So we can’t do anything with opportunity contact roles as they are a second class object. No triggers or process builders. So when a contact is added as the primary role we want to have access to that contact on the opportunity. To install: create a field called Primary_Contact__c on the opportunity. Now whenever, you edit the opportunity and there is no primary contact then this trigger will populate it will the primary contact in the opportunity contact roles.

Unmanaged Package (this could be built with process builder and flows, however, we wanted it to not have any dependencies on any fields as many of you will already have a primary contact field)

Idea to upvote

Preserve Related Files on Account, Contact, or Lead Merge

Apparently, you lose related files when you merge accounts, contacts or leads. That’s terrible. It’s not a known problem for most of our client’s but we install this fix so it never needs to be.

Install Link. Idea to upvote.

Credit: Doug Ayers

Campaign list builder

The Campaign List Builder is a tool to help you quickly build complex mailing lists based on multiple Campaigns. Using a series of filters, you decide who should be part of the Campaign list.

Install Link. Idea to upvote.

Opportunity Stage Insert

Opportunities are fussy as they always require a stage and close date. This simple trigger allows you to specify the stage to use for each record type and if a close date is missing it adds in today’s date:

Install Link. Idea to upvote.

Custom Fields to Quote Lines

When a Quote is created or is syncing and you create an OpportunityLineItem then Salesforce automatically copies and syncs the OpportunityLineItem standard fields to the QuoteLineItem standard fields. Custom fields are ignored.

This project allows you to define via custom setting which OpportunityLineItem custom fields you want copied down to the newly created QuoteLineItem custom fields.

Please note that this project currently does not handle syncing.

Install Link. Idea to upvote.

Credit: Doug Ayers

Even Lead Assignment

Lead Assigner allows Admins to distribute leads evenly among its sales representatives. Admins can configure rules for lead assignment and select users to whom leads need to be routed. It also provides the capability to assign leads to only logged in users.

Install Link. Idea to upvote.

Other Admin and Development Tools

Bulk Field Level Security Editor

Edit all of your profiles on all or your objects at once. A dream come true.

Install Link. Idea to upvote.

Bulk adding fields

Schema Builder – there is a lot of talk about bulk creating tools. We have tried a few approaches. But this standard feature is just as quick as anything. It gives FLS to everyone and doesn’t add it to the page layout. It’s not good for adding formulas or roll ups, but those shouldn’t be added on mass as they need consideration.

Trailhead Link

Skyvia Data Loader

dataloader.io was a go to, but the free version has more limits now. Skyvia allows you to set constants and formulas on import which is great for set statuses or record types. You can also import child objects of the same row. Skyvia will import the parent object and then get the ID and add it to the child object in one go

Link

Mass Switching validation rules, workflows, triggers and process builder.

An awesome tool to be able to toggl on and off all validation rules and workflows. Great for apex deployment are importing records.

Install Link. 

Credit: Ben Edwards

Declarative Scheduler Tool

Credit – I need to give ample credit and then some more to Doug Ayers. The original version was inspired by some of his work and then in version 2 it is literally copied off his work. His schedule adding campaign members is built into the tool

Sample user cases

  • A report of all leads over 4 days that have been stuck on a status for 4 days
  • Create a task to follow up on all opportunities that have a closed date in the past and no follow up tasks and haven’t been modified in the last 7 days
  • Send an email on a contacts birthday
  • Process mass updates to all data (create a workflow to fire when the triggering field change and then to do the function you want)
  • Delay bulk workflow actions into a nightly job
  • Backdate workflow processing – when you created a workflow/process build you can trigger it to run on all of the existing records 🙂
  • Trigger a contract to renew on a certain date or create a new opportunity
  • Let me know yours…

Notes: – It works off batch apex so you can change the batch size on each record. This stops any soql 101 or timeout process builder/flow errors – Has been tested to work on reports of up to 50,000 records. It’s built to be generic so works across all obejects – but you should add in your own datetime field.

Instructions

 

  1. Set up a report 
    1. Include an ID field of the record to update
    2. Include a datetime field that can be changed by the tool
    3. Add in report filters to limit the number of records to update
  2. Add a “Scheduled Report” record
    1. Select the record type “Update Field on Records”
    2. Select the frequency of the update. This tool will run every hour and detects if any “Scheduled Report” records are due to be updated.
    3. Look up the report in the drop down boxes at the bottom. Select the Id and datetime fields
    4. Click save –
    5. WARNING: saving the report selection schedules the tool to fire in one minutes time. If your record meets the condition then it will fire straight away. Make sure no other records are going to be scheduled at the same time.
  3. Set up a process builder to fire when the datetime field is changed:

Right click on the image to save it to your computer.

Installation

Managed Package (sandbox)

View the code on GitHub

 

Troubleshooting steps

  • Check the scheduled report logs for error messages
  • Reduce the batch size
  • Try and manually change the datetime field – might by another validation rule or flow in place causing problems
  • Leave an issue on the github page

Declarative Scheduler Tool for Salesforce admins – use the reporting engine and subscribe feature to update records in report on a daily/weekly/monthly schedule

  • Create a report with the record id in column 1 and a datetime field in column 2
  • Add the filters you like
  • Click subscribe. Then select a custom action. Then Declarative Scheduler (make sure to turn off the salesforce1 notification
  • Set up when you would like these records to update and then schedule away
  • On the scheduled time the datetime field will be updated. So set up a process builder to fire when that field changes. And voilla you have a repeating schedule.

Sample user cases

  • A report of all leads over 4 days that have been stuck on a status for 4 days
  • Create a task to follow up on all opportunities that have a closed date in the past and no follow up tasks and haven’t been modified in the last 7 days
  • Send an email on a contacts birthday
  • Process mass updates to all data (create a workflow to fire when the triggering field change and then to do the function you want)
  • Delay bulk workflow actions into a nightly job
  • Backdate workflow processing – when you created a workflow/process build you can trigger it to run on all of the existing records 🙂
  • Let me know yours…

Notes: – It works off super batch apex so you can change the batch size in custom settings. This stops any soql 101 or timeout process builder/flow errors – Has been tested to work on reports of up to 50,000 records. Don’t go larger of Salesforce CPU times out – It’s built to be generic so works across all obejects – but you should add in your own datetime field.
Todo: – Proper test classes – Instructions – Testing – Guidelines and examples

Instructions

Install the package below.
Right click on the image to save it to your computer.

Right click on the image to save it to your computer.

Right click on the image to save it to your computer.

 

View the code and download the package at GitHub