+ Start a Discussion
ALAL 

Matching Account and Lead Name - Sharing Rule

Hello, our Organization-wide default settings for accounts and leads is private. I would like to create a solution where if the Account Name matches the Lead Company name, then the Account Owner can edit that lead record. I've tried using code that I found on this forum to update a custom checkbox field if the Account Name and Lead Company match. The issue I'm running into is when I create the Lead sharing rule in settings, I can't specify record access by user, but rather only by group. Is there a way to specify it by Account owner? Thank you

trigger LeadMatch on Lead (before insert,before update) {
    
    List<Account> accList = [Select Id,Name from Account];
    
    for(Lead lead : trigger.new){
        lead.LeadAccountMatch__c = false;
        for(Account acc: accList){
            if(lead.Company == acc.Name && lead.OwnerId != acc.OwnerId){
                lead.LeadAccountMatch__c = true;
                break;
            }
        }        
    }
Best Answer chosen by AL
Aparna Hegde 1Aparna Hegde 1
Hi AL,

Since lead is a stand alone object not related to anything (until its converted) there is no way you can allow account owner to edit lead if company name on lead = account name.
However, I came across this blog https://automationchampion.com/tag/flow-based-record-sharing-in-salesforce/, may be you can just check if you can tweak it a little bit to suit your requirement.

Cheers,
Aparna Hegde

All Answers

Aparna Hegde 1Aparna Hegde 1
Hi AL,

Since lead is a stand alone object not related to anything (until its converted) there is no way you can allow account owner to edit lead if company name on lead = account name.
However, I came across this blog https://automationchampion.com/tag/flow-based-record-sharing-in-salesforce/, may be you can just check if you can tweak it a little bit to suit your requirement.

Cheers,
Aparna Hegde
This was selected as the best answer
ALAL
Thank you Aparna. This was helpful.