[SalesForce] How to i implement SOQL query in workflow process

Below is an excerpt from the documentation:

When you add or update an account or lead, a D&B Company record is created and linked to that account or lead via the D&B Company field. Click the link in the D&B Company field to access the associated D&B Company record.

Let's say a D&B company record was just created or updated because I updated (or added) a DUNS number field under an account record (let's call this account1). Inside of this newly created D&B company record, there is a parent company DUNS number field.

If our salesforce org has an existing account2 with DUNS number that matches above parent DUNS number, the account2's 18 digit account ID must be added to the account1's parentID field.

If I were to use SQL that might look something like:

SELECT
account1.18_digit_ID,
account2.18_digit_ID as 'parentAccountID'
FROM d&bcompany
JOIN account1 on d&b_company.DUNSnumber = account1.dunsnumber
JOIN account2 on d&b_company.parentDUNSnumber = account2.dunsnumber

If I were to use this query, account1's parent field must be updated to the values under 'parentAccountID' column.

I was able to successfully set critiera and conditions using the process builder. the final step is to update or insert account1's parent field to an account number SF was able to find based on the parent DUNS number.

  1. Is there a way to implement the SOQL query while using the workflow (whether it be process builder or flow)? if so, can you walk me through where to query in the workflow process? Is Process Builder the right tool in this scenario?
  2. Or Do I have to use APEX? if so, can you briefly explain the process?
  3. Or Is there other better way to tackle this case?

Best Answer

The simple approach is you have to use Flow to manage you logic. Use Flow to find the parent DUNS number and the use another record lookup element to find account2 for parent DUNS.

Once you have the account2 id use record update element to update parent field on account1.

Related Topic