updateMembersWithPlans(membersWithPlansInputRepresentation, censusId)

Update a family of group census members and their insurance plans in a group census in a single request.

API Version 

68.0

Requires Chatter 

No

Signature 

public static ConnectApi.MembersWithPlansRepresentation updateMembersWithPlans(ConnectApi.MembersWithPlansInputRepresentation membersWithPlansInputRepresentation, String censusId)

Parameters 

membersWithPlansInputRepresentation

censusId

  • Type: String
  • ID of the group census that the members belong to.

Return Value 

Type: ConnectApi.MembersWithPlansRepresentation

Usage 

Use this method to update a family of group census members, along with the insurance plans for each member, in a single call. Specify the group census in censusId and the members in the members property of the input representation.

Each member must specify the id of an existing GroupCensusMember record. Specify plan changes in addedPlans to add plans, in upsertedPlans to add or update plans, and in deletedPlans to remove plans by GroupCensusMemberPlan ID. The groupCensusMemberPlans property applies only when you add members with addMembersWithPlans(membersWithPlansInputRepresentation, censusId).

For each plan that you add or update, specify either contractGroupPlanId for a plan on the census’s contract, or productCode and rootProductCode for an off-contract coverage.

Check the isSuccess property of the response to determine whether the operation succeeded. Request-level errors are in the top-level errors property, which is empty when isSuccess is true. Member-specific errors are in the errors property of each item in members.

Example 

Here’s an example of how to update a group census member and the member’s insurance plans from Apex code. Identify each member by its id property, and specify plan changes in addedPlans, upsertedPlans, and deletedPlans rather than in groupCensusMemberPlans.

1// Update group census members and their insurance plans in a single request.
2
3final String CENSUS_ID = '0rfxx000000022IAAQ';
4final String CGP_TO_UPSERT = '0rgxx00000001W3AAI';
5final String CGP_TO_ADD = '0rgxx00000001W4AAI';
6
7// 1) Locate the member to update.
8List<GroupCensusMember> found = [
9    SELECT Id FROM GroupCensusMember
10    WHERE GroupCensusId = :CENSUS_ID
11      AND FirstName = 'ApexAdd' AND Lastname = 'Primary'
12    ORDER BY CreatedDate DESC LIMIT 1
13];
14if (found.isEmpty()) {
15    System.debug('No matching group census member found.');
16    return;
17}
18String memberId = found[0].Id;
19
20// 2) Collect the member plans to remove.
21List<String> plansToDelete = new List<String>();
22for (GroupCensusMemberPlan plan : [
23    SELECT Id FROM GroupCensusMemberPlan
24    WHERE GroupCensusMemberId = :memberId LIMIT 1
25]) {
26    plansToDelete.add(plan.Id);
27}
28
29// 3) Build the plans to add or update.
30ConnectApi.MemberPlanInputRepresentation upsertedPlan = new ConnectApi.MemberPlanInputRepresentation();
31upsertedPlan.contractGroupPlanId = CGP_TO_UPSERT;
32
33ConnectApi.MemberPlanInputRepresentation addedPlan = new ConnectApi.MemberPlanInputRepresentation();
34addedPlan.contractGroupPlanId = CGP_TO_ADD;
35
36// 4) Update the member details and the member's plans.
37ConnectApi.MemberWithPlansInputRepresentation member = new ConnectApi.MemberWithPlansInputRepresentation();
38member.id = memberId;
39member.email = 'apexupdate.primary@example.com';
40member.city = 'San Francisco';
41member.state = 'CA';
42member.postalCode = '94105';
43member.annualEligibleSalary = 125000.00;
44member.smokerStatus = 'Non-Smoker';
45member.upsertedPlans = new List<ConnectApi.MemberPlanInputRepresentation>{ upsertedPlan };
46member.addedPlans = new List<ConnectApi.MemberPlanInputRepresentation>{ addedPlan };
47member.deletedPlans = plansToDelete;
48
49ConnectApi.MembersWithPlansInputRepresentation input = new ConnectApi.MembersWithPlansInputRepresentation();
50input.members = new List<ConnectApi.MemberWithPlansInputRepresentation>{ member };
51
52try {
53    ConnectApi.MembersWithPlansRepresentation result =
54        ConnectApi.GroupBenefitsApi.updateMembersWithPlans(input, CENSUS_ID);
55
56    System.debug('isSuccess: ' + result.isSuccess);
57    for (ConnectApi.MemberWithPlansRepresentation updated : result.members) {
58        System.debug('memberId: ' + updated.memberId
59            + ', memberPlans: ' + updated.memberPlans
60            + ', errors: ' + updated.errors);
61    }
62} catch (Exception e) {
63    System.debug('Error while updating members with plans: ' + e.getMessage());
64}