Pages

Sunday, March 26, 2017

Pass Collection to Visual Workflow, parse and save case records

Use Case

Business has a requirement to update multiple cases from List view. User will save multiple field values taking an input from screen and finally save those records.


User will click on "Update Field Values" button and following fields will be displayed on the screen.



User will enter Due Date and Status and finally save collection of records.

Solution

If the user wants to update single field then that can be achievable by inline editing. But if there are more than one fields to update then that can be achieved by using flow.

Create a List View Custom button and use this code to pass parameters to the flow.
vSelectedCaseIds which contains case ids collection which can be found from {!GETRECORDIDS($ObjectType.Case)}.
vCaseCount which contains number of selected case id count.
retURL where it will be landed after completion.




 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
{!RequireScript("/soap/ajax/29.0/connection.js")}

var caseObj = new sforce.SObject("Case");
var selectedCases = {!GETRECORDIDS($ObjectType.Case)}; //chosen records from list view checkboxes

//check at-least one record is selected
if (selectedCases[0] == null) {
   alert("You must select at least one record");
} else 
{
    var serverUrl = '{!$Api.Partner_Server_URL_260}';
    var position = {!FIND( '/services', $Api.Partner_Server_URL_260)};
    var base = serverUrl.substring(0,position-1);

    var url = base +encodeURI('/flow/Update_Field_Values?vSelectedCaseIds=' + selectedCases +  '&vCaseCount=' + selectedCases.length +  '&retURL=/500/o');

    window.open(url, '_self');
}

The complete flow will look like this:




Step by step implementation:

1. Screen


2. Decision - check counter size


3. Assignment - Retrieve Single Case Id from param


caseIdFormula:

LEFT({!vRemainingCaseIds}, 15)



4. Assignment - Assign values to Case Object



Where varSObjectCase is SObject input and output variable.

5. Assignment - Add All Case Objects



Where All_Case_Sobjects is SObject Collection variable


6. Assignment - Retrieve Remaining CaseIds



Remaining_CaseIds - Formula


TRIM(
RIGHT({!vRemainingCaseIds}, (LEN({!vRemainingCaseIds})-16))
)

7. Decision - If Counter less than vCaseCount


8. Fast Update



9. Success






Conclusion

I have tried to put a solution through flow instead of using visualforce page.

Since this type of complete implement is not readily available at google, that's why I have tried my best put it in a proper way.

Have fun and if it is helpful then share with your friends.

No comments:

Post a Comment