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
Sudeep SinghSudeep Singh 

In MemberPlan if a insurance is marked as primary then it should get updated in the Account lookup custom field with that primary marked lookup

In MemberPlan if a insurance is marked as primary then it should get updated in the Account lookup custom field (Insurance) with that primary marked lookup.

Primary is the custom field in MemberPlan standard object
Insurance is lookup with MemberPlan.

Any MemberPlan which is marked primary that must get displayed in the Insurance field of Account

Thanks
Best Answer chosen by Sudeep Singh
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sudeep,

You can use recordtriggered flow on Memberplan object as below. I dont see Primary standard field so created custom field.



Start condition:

OR(AND(ISNEW(), Primary__c), ISCHANGED(Primary__c))

User-added image
Decision condition:

User-added image
Update record element to make insurance field.

User-added imageUpdate record if primary false to null.

User-added image
The entire flow will be as below:

User-added imageLet me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
 

All Answers

Shri RajShri Raj

Here's how you can do this with a Workflow:
Go to Setup and then click on Workflow Rules.
Create a new Workflow Rule and select MemberPlan as the object.
Give the Workflow Rule a name, for example, "Update Account Insurance Lookup".
Add a new Criteria to start the Workflow when the "Primary" field equals "True".
Add a new action of type "Field Update" to update the Account object.
In the "Field to Update" section, select the "Insurance" lookup field.
In the "New Value" section, select the MemberPlan as the value.
Save and activate the Workflow.

OR a trigger
 

trigger MemberPlanTrigger on MemberPlan (after update) {
    Set<Id> accountIds = new Set<Id>();
    
    // Loop through all MemberPlan records that have been updated
    for (MemberPlan mp : Trigger.new) {
        // Check if the Primary field is set to "True"
        if (mp.Primary__c == true) {
            // Add the Account Id to the set
            accountIds.add(mp.Account__c);
        }
    }
    
    // Retrieve the Accounts that were associated with the updated MemberPlans
    List<Account> accounts = [SELECT Id, Insurance__c FROM Account WHERE Id IN :accountIds];
    
    // Loop through the Accounts and update the Insurance field with the MemberPlan record
    for (Account a : accounts) {
        for (MemberPlan mp : Trigger.new) {
            // Check if the Primary field is set to "True" and the Account Id matches the Account Id on the MemberPlan
            if (mp.Primary__c == true && mp.Account__c == a.Id) {
                // Update the Insurance field on the Account with the MemberPlan record
                a.Insurance__c = mp.Id;
            }
        }
    }
    
    // Update the Accounts
    update accounts;
}
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

Can you confirm if insurance is custom object and primary field is on Insurance object?

Thanks,
 
Sudeep SinghSudeep Singh
Hi Sai,
Insurance field is MemberPlan Object which is standard and I had created Primary Checkbox field in MemberPlan

Thanks
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

I dont see Insurance or Primary checkbox on Memberplan object. Are you using Memberplan object of healthcloud?

https://developer.salesforce.com/docs/atlas.en-us.health_cloud_object_reference.meta/health_cloud_object_reference/sforce_api_objects_memberplan.htm

Thanks,
 
Sudeep SinghSudeep Singh
Hi Sai,

MemberPlan is the standard object
Primary checkbox field is in Memberplan.

And made a lookup field in account named as Insurance.

Ya it is healthcloud

thanks
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Sudeep,

You can use recordtriggered flow on Memberplan object as below. I dont see Primary standard field so created custom field.



Start condition:

OR(AND(ISNEW(), Primary__c), ISCHANGED(Primary__c))

User-added image
Decision condition:

User-added image
Update record element to make insurance field.

User-added imageUpdate record if primary false to null.

User-added image
The entire flow will be as below:

User-added imageLet me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
 
This was selected as the best answer