function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SewaltherSewalther 

Visual Workflow: Flow is not creating all the records

I have created a visual workflow to find the opty team members on a related opty (Previous Year Opty) and add them to the current opportunity being created. When I tested the flow, it only created 1 of 3 opty team records I assumed it would. When reviewing my debug logs, I see that it looped through all three, but only one created.  Any help would be appreciated. My Flow is below. Any help is appreciated! Thank you!  

User-added image
User-added image
User-added imageUser-added imageUser-added image
Best Answer chosen by Sewalther
Gaurav HandooGaurav Handoo
Hi Sewalther

Reason for your flow not working:
  1. Record Create element is used to create a single record and not multiple records in bulk.
  2. Your Record Create is not pointing back to Loop element. This means that your flow stops after the Record Create element
Flaw in your flow is that you are trying to create record within a loop, which is not a recommended approach as you might end up hitting Too Many SOQL error and/or Too many DML operations or both through this approach.

Solution:
All you would need to do is add 2 assignment steps inside your loop:
  1. Assign the values from Sobj of Loop to additional Sobj
  2. Assign the new Sobj to a Sobj collection (ensure you link this back to loop element)
Above two steps would replicate the data in a temporary Sobj Collection, which acts as a replica of bulk values of object itself and do ensure that End of Loop would point to Fast create element (not the Record Create) of OpportunityTeams to create records.

Hope this helps. Please mark as best answer if it does.

Cheers!!

Gaurav

All Answers

Alain CabonAlain Cabon
Hi,

Could you export the metadata definition of your flow?

The steps you need to follow are explained here (packflow.xml): https://developer.salesforce.com/forums/ForumsMain?id=9060G0000005W9uQAE
 
SewaltherSewalther
Hi, Alain.

Thank you for teaching me how to retrieve the metadata from Workbench. Here is my flow metadata. Thank you!

<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <interviewLabel>Add OpportunityTeam to Renewal {!$Flow.CurrentDateTime}</interviewLabel>
    <label>Add Opty Team to Renewal</label>
    <loops>
        <name>Loop_Through_Previous_Year_Opty_Team</name>
        <label>Loop Through Previous Year Opty Team</label>
        <locationX>285</locationX>
        <locationY>370</locationY>
        <assignNextValueToReference>PreviousYearOptyTeamMember</assignNextValueToReference>
        <collectionReference>PreviousYearOptyTeamMembers</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>AddOptyTeamMember</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Update_Opty</targetReference>
        </noMoreValuesConnector>
    </loops>
    <processType>AutoLaunchedFlow</processType>
    <recordCreates>
        <name>AddOptyTeamMember</name>
        <label>AddOptyTeamMember</label>
        <locationX>288</locationX>
        <locationY>508</locationY>
        <inputAssignments>
            <field>CurrencyIsoCode</field>
            <value>
                <elementReference>PreviousYearOptyTeamMember.CurrencyIsoCode</elementReference>
            </value>
        </inputAssignments>
        <inputAssignments>
            <field>OpportunityAccessLevel</field>
            <value>
                <stringValue>All</stringValue>
            </value>
        </inputAssignments>
        <inputAssignments>
            <field>OpportunityId</field>
            <value>
                <elementReference>varCurrentOptyID</elementReference>
            </value>
        </inputAssignments>
        <inputAssignments>
            <field>TeamMemberRole</field>
            <value>
                <elementReference>PreviousYearOptyTeamMember.TeamMemberRole</elementReference>
            </value>
        </inputAssignments>
        <inputAssignments>
            <field>UserId</field>
            <value>
                <elementReference>PreviousYearOptyTeamMember.UserId</elementReference>
            </value>
        </inputAssignments>
        <object>OpportunityTeamMember</object>
    </recordCreates>
    <recordLookups>
        <name>FindPreviousYearOpty</name>
        <label>FindPreviousYearOpty</label>
        <locationX>284</locationX>
        <locationY>135</locationY>
        <assignNullValuesIfNoRecordsFound>true</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>FindPreviousYearOptyMemberFast</targetReference>
        </connector>
        <filters>
            <field>Id</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>varCurrentOptyID</elementReference>
            </value>
        </filters>
        <object>Opportunity</object>
        <outputAssignments>
            <assignToReference>varPreviousYearOptyID</assignToReference>
            <field>Previous_Year_Opportunity_ID__c</field>
        </outputAssignments>
    </recordLookups>
    <recordLookups>
        <name>FindPreviousYearOptyMemberFast</name>
        <label>FindPreviousYearOptyMemberFast</label>
        <locationX>280</locationX>
        <locationY>252</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Loop_Through_Previous_Year_Opty_Team</targetReference>
        </connector>
        <filters>
            <field>OpportunityId</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>varPreviousYearOptyID</elementReference>
            </value>
        </filters>
        <object>OpportunityTeamMember</object>
        <outputReference>PreviousYearOptyTeamMembers</outputReference>
        <queriedFields>OpportunityId</queriedFields>
        <queriedFields>CurrencyIsoCode</queriedFields>
        <queriedFields>TeamMemberRole</queriedFields>
        <queriedFields>OpportunityAccessLevel</queriedFields>
        <queriedFields>UserId</queriedFields>
        <sortField>TeamMemberRole</sortField>
        <sortOrder>Asc</sortOrder>
    </recordLookups>
    <recordUpdates>
        <name>Update_Opty</name>
        <label>Update Opty</label>
        <locationX>508</locationX>
        <locationY>373</locationY>
        <filters>
            <field>Id</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>varCurrentOptyID</elementReference>
            </value>
        </filters>
        <inputAssignments>
            <field>RFP_Status__c</field>
            <value>
                <stringValue>Not Started</stringValue>
            </value>
        </inputAssignments>
        <object>Opportunity</object>
    </recordUpdates>
    <startElementReference>FindPreviousYearOpty</startElementReference>
    <variables>
        <name>PreviousYearOptyTeamMember</name>
        <dataType>SObject</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>OpportunityTeamMember</objectType>
    </variables>
    <variables>
        <name>PreviousYearOptyTeamMembers</name>
        <dataType>SObject</dataType>
        <isCollection>true</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>OpportunityTeamMember</objectType>
    </variables>
    <variables>
        <name>varCurrentOptyID</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
    </variables>
    <variables>
        <name>varPreviousYearOptyID</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
    </variables>
</Flow>
Alain CabonAlain Cabon
Hi,

Your workflow is deployed in my free org. Now, I can have access to all the details without asking you and even test it with exactly all your parameters.
User-added image

User-added image


 
Alain CabonAlain Cabon
Here is a first "solution".

User-added image
 
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <assignments>
        <name>Add_Current_OppMember</name>
        <label>Add Current OppMember</label>
        <locationX>520</locationX>
        <locationY>512</locationY>
        <assignmentItems>
            <assignToReference>CurrentYearOptyTeamMembers</assignToReference>
            <operator>Add</operator>
            <value>
                <elementReference>CurrentYearOptyTeamMember</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Loop_Through_Previous_Year_Opty_Team</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Change_Oppty_ID</name>
        <label>Change Oppty ID</label>
        <locationX>523</locationX>
        <locationY>384</locationY>
        <assignmentItems>
            <assignToReference>CurrentYearOptyTeamMember.CurrencyIsoCode</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>PreviousYearOptyTeamMember.CurrencyIsoCode</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>CurrentYearOptyTeamMember.OpportunityAccessLevel</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>PreviousYearOptyTeamMember.OpportunityAccessLevel</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>CurrentYearOptyTeamMember.TeamMemberRole</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>PreviousYearOptyTeamMember.TeamMemberRole</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>CurrentYearOptyTeamMember.UserId</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>PreviousYearOptyTeamMember.UserId</elementReference>
            </value>
        </assignmentItems>
        <assignmentItems>
            <assignToReference>CurrentYearOptyTeamMember.OpportunityId</assignToReference>
            <operator>Assign</operator>
            <value>
                <elementReference>varCurrentOptyID</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Add_Current_OppMember</targetReference>
        </connector>
    </assignments>
    <interviewLabel>Add OpportunityTeam to Renewal {!$Flow.CurrentDateTime}</interviewLabel>
    <label>Add Opty Team to Renewal</label>
    <loops>
        <name>Loop_Through_Previous_Year_Opty_Team</name>
        <label>Loop Through Previous Year Opty Team</label>
        <locationX>281</locationX>
        <locationY>389</locationY>
        <assignNextValueToReference>PreviousYearOptyTeamMember</assignNextValueToReference>
        <collectionReference>PreviousYearOptyTeamMembers</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>Change_Oppty_ID</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Create_Opp_Members</targetReference>
        </noMoreValuesConnector>
    </loops>
    <processType>AutoLaunchedFlow</processType>
    <recordCreates>
        <name>Create_Opp_Members</name>
        <label>Create Opp Members</label>
        <locationX>285</locationX>
        <locationY>552</locationY>
        <connector>
            <targetReference>Update_Opty</targetReference>
        </connector>
        <inputReference>CurrentYearOptyTeamMembers</inputReference>
    </recordCreates>
    <recordLookups>
        <name>FindPreviousYearOpty</name>
        <label>FindPreviousYearOpty</label>
        <locationX>285</locationX>
        <locationY>135</locationY>
        <assignNullValuesIfNoRecordsFound>true</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>FindPreviousYearOptyMemberFast</targetReference>
        </connector>
        <filters>
            <field>Id</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>varCurrentOptyID</elementReference>
            </value>
        </filters>
        <object>Opportunity</object>
        <outputAssignments>
            <assignToReference>varPreviousYearOptyID</assignToReference>
            <field>Previous_Year_Opportunity_ID__c</field>
        </outputAssignments>
    </recordLookups>
    <recordLookups>
        <name>FindPreviousYearOptyMemberFast</name>
        <label>FindPreviousYearOptyMemberFast</label>
        <locationX>284</locationX>
        <locationY>263</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Loop_Through_Previous_Year_Opty_Team</targetReference>
        </connector>
        <filters>
            <field>OpportunityId</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>varPreviousYearOptyID</elementReference>
            </value>
        </filters>
        <object>OpportunityTeamMember</object>
        <outputReference>PreviousYearOptyTeamMembers</outputReference>
        <queriedFields>OpportunityId</queriedFields>
        <queriedFields>CurrencyIsoCode</queriedFields>
        <queriedFields>TeamMemberRole</queriedFields>
        <queriedFields>OpportunityAccessLevel</queriedFields>
        <queriedFields>UserId</queriedFields>
        <sortField>TeamMemberRole</sortField>
        <sortOrder>Asc</sortOrder>
    </recordLookups>
    <recordUpdates>
        <name>Update_Opty</name>
        <label>Update Opty</label>
        <locationX>280</locationX>
        <locationY>686</locationY>
        <filters>
            <field>Id</field>
            <operator>EqualTo</operator>
            <value>
                <elementReference>varCurrentOptyID</elementReference>
            </value>
        </filters>
        <inputAssignments>
            <field>RFP_Status__c</field>
            <value>
                <stringValue>Not Started</stringValue>
            </value>
        </inputAssignments>
        <object>Opportunity</object>
    </recordUpdates>
    <startElementReference>FindPreviousYearOpty</startElementReference>
    <variables>
        <name>CurrentYearOptyTeamMember</name>
        <dataType>SObject</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
        <objectType>OpportunityTeamMember</objectType>
    </variables>
    <variables>
        <name>CurrentYearOptyTeamMembers</name>
        <dataType>SObject</dataType>
        <isCollection>true</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
        <objectType>OpportunityTeamMember</objectType>
    </variables>
    <variables>
        <name>PreviousYearOptyTeamMember</name>
        <dataType>SObject</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>OpportunityTeamMember</objectType>
    </variables>
    <variables>
        <name>PreviousYearOptyTeamMembers</name>
        <dataType>SObject</dataType>
        <isCollection>true</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
        <objectType>OpportunityTeamMember</objectType>
    </variables>
    <variables>
        <name>varCurrentOptyID</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
    </variables>
    <variables>
        <name>varPreviousYearOptyID</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>true</isInput>
        <isOutput>true</isOutput>
    </variables>
</Flow>

The next post will explain how you can deploy the solution.
 
Alain CabonAlain Cabon
If you want to deploy the solution above, you just need to replace the source code in your previous exported flows 

User-added image

1) Modify the  filepackage.xml

Add_Opty_Team_to_Renewal-2 where 2 is the version and can be changed
the file Add_Opty_Team_to_Renewal-2.flow must exist into the folder: flows (only this file)
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Add_Opty_Team_to_Renewal-2</members>
        <name>Flow</name>
    </types>
    <version>41.0</version>
</Package>

2) the folder : "flows" contains now only: Add_Opty_Team_to_Renewal-2.flow (with the source code above)

3) Make a zip file named package.zip with: package.xml and the folder "flows"  (reverse operation)

3) Workbench  migration > deploy :  https://workbench.developerforce.com/metadataDeploy.php

Select the file: package.zip + checkbox: Single Package + button: Next  + button: Deploy
User-added image


User-added image


User-added image

That's all and you will have a new version of the flow.
 
Alain CabonAlain Cabon
Hi,

Did you try the "solution" ? You have probably improve it and it is always interesting to have a feed-back.

Thanks

Alain
Gaurav HandooGaurav Handoo
Hi Sewalther

Reason for your flow not working:
  1. Record Create element is used to create a single record and not multiple records in bulk.
  2. Your Record Create is not pointing back to Loop element. This means that your flow stops after the Record Create element
Flaw in your flow is that you are trying to create record within a loop, which is not a recommended approach as you might end up hitting Too Many SOQL error and/or Too many DML operations or both through this approach.

Solution:
All you would need to do is add 2 assignment steps inside your loop:
  1. Assign the values from Sobj of Loop to additional Sobj
  2. Assign the new Sobj to a Sobj collection (ensure you link this back to loop element)
Above two steps would replicate the data in a temporary Sobj Collection, which acts as a replica of bulk values of object itself and do ensure that End of Loop would point to Fast create element (not the Record Create) of OpportunityTeams to create records.

Hope this helps. Please mark as best answer if it does.

Cheers!!

Gaurav
This was selected as the best answer
SewaltherSewalther
Thank you both for helping me. I am working on modifying my flow, as well as undertanding it, and will come back to select best answer! Thank you ! Sara
Gaurav HandooGaurav Handoo
Thanks for the update Sara, in case you face any challenge, feel free to get in touch with me at gaurav.handoo@gmail.com

Cheers!!

Gaurav