Loading
Feature degradation | Gmail Email delivery failureRead More
Public Sector Documentation
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Create an Apex Class to Identify Incomes of Removed Household Members

          Create an Apex Class to Identify Incomes of Removed Household Members

          When recertifying for a benefit or reporting a change of circumstances, if constituents remove members from their household, the incomes of the removed members must be omitted from the household income. The TransformIncomeRecords Apex class finds and flags the incomes of removed members in the household income details that the applicant previously declared. The UpdateHouseholdIncomeList Integration Procedure calls the Apex class and uses the flags to create a list of incomes of existing members and a list of incomes of removed members. The guided flow shows the two lists to the applicant so that they can review the information.

          Required Editions

          View supported product editions.
          User Permissions Needed
          To create an Apex class: Author Apex
          1. From Setup, in the Quick Find box, enter Apex, and then select Apex Classes.
          2. Click New.
          3. Paste this class definition into the text box.
            global with sharing class TransformIncomeRecords implements Callable {
                
                /*
                * @description      : In a JSON object that has the incomes of all household members, finds and flags incomes of removed members. The flag helps display a list of incomes of existing members and a list of incomes of removed members to the applicant.
                * @return output    : Object containing updated member income details
                */
                global Object call(String action, Map<String, Object> args) {
                    Map<String, Object> input = (Map<String, Object>)args.get('input');
                    Map<String, Object> output = (Map<String, Object>)args.get('output');
                    
                    Object incomeDetailsObj = input.get('PSS_BM_v5_HouseholdIncomeDetails');
                    // Null check for Household Income
                    if(incomeDetailsObj == null || incomeDetailsObj instanceof String) {
                        return output.put('PSS_BM_v5_HouseholdIncomeDetails', incomeDetailsObj);
                    }
                    
                    List<Object> incomedetails = new List<Object>();
                    
                    if(String.valueOf(incomeDetailsObj).substring(0, 1).equals('{')) {
                        incomedetails.add(incomeDetailsObj);
                    } else {
                        incomeDetails = (List<Object>)(input.get('PSS_BM_v5_HouseholdIncomeDetails'));
                    }
                    
                    Object memberListObj = input.get('MemberList');
                    // Null check for Household Member List
                    if(memberListObj == null || memberListObj instanceof String) {
                        return output.put('PSS_BM_v5_HouseholdIncomeDetails', incomedetails);
                    }
                    
                    List<Object> memberList = new List<Object>();
                    
                    if(String.valueOf(memberListObj).substring(0, 1).equals('{')) {
                        memberList.add(memberListObj);
                    } else {
                        memberList = (List<Object>)(input.get('MemberList'));
                    }
                        
                    List<Object> result = new List<Object>();
                    
                    // To store name list of removed household members 
                    Set<String> removedMembers = new Set<String>();
                    
                    // Removed household members have AQ 'PSS_BM_v5_MemberSectionAction' set to Remove member, 
                    // add those member names to removed member list
                    for(Object member : memberList) {
                        Map<String,Object> memberDetails = (Map<String, Object>) member;
                        if(memberDetails.containsKey('PSS_BM_v5_MemberSectionAction') && memberDetails.get('PSS_BM_v5_MemberSectionAction').equals('Remove member')) {
                            removedMembers.add((String) memberDetails.get('PSS_BM_v5_HouseholdMemberName'));
                        }
                    }
                    
                    // Insert removed income flag to income details of removed members
                    for(Object income : incomedetails) {
                        insertIncomeRemovedFlag(result, income, removedMembers);
                    }                
                    
                    return output.put('PSS_BM_v5_HouseholdIncomeDetails', result);
                }
            
                /*
                * @description          : Inserts the MemberRemoved flag in income details object for removed household members
                * @param result         : Updated Income Details List
                * @param income         : Income detail object
                * @param removedMembers : List of names of removed members
                * @return void
                */
                global void insertIncomeRemovedFlag(List<Object> result, Object income, Set<String> removedMembers) {
                    Map<String,Object> incomeDetails = (Map<String, Object>)income;
                    String name = (String) incomeDetails.get('PSS_BM_v5_ExistingIncomeHouseholdMemberName');
                    if(removedMembers.contains(name)) {
                        // Insert MemberRemoved flag
                        incomeDetails.put('MemberRemoved', 'Yes');
                    }
                    result.add(incomeDetails);
                }
                  
            }
          4. Save your changes.
           
          Loading
          Salesforce Help | Article