Loading
Criar um acionador para manter a visibilidade do lead

Criar um acionador para manter a visibilidade do lead

Adicione um acionador que conceda acesso de compartilhamento à pessoa que criou o lead mesmo quando ela não for mais o proprietário do lead. Conceder acesso de compartilhamento permite que o criador do lead rastreie o encaminhamento depois de ele ser convertido em uma oportunidade.

Edições obrigatórias

Disponível em: Lightning Experience

Disponível em: Edições Enterprise e Unlimited com o Health Cloud

Importante
Importante Em vez de usar os objetos Lead e Oportunidade para gerenciar indicações, use o objeto Solicitação de serviço clínico e as ferramentas de automação criadas para o Modelo de dados clínicos alinhado ao FHIR R4. Para se beneficiar de recursos novos e aprimorados de gerenciamento de indicações no futuro, você deve usar objetos no Modelo de dados clínicos.

Para acessar os objetos LeadShare e OpportunityShare, o compartilhamento para os objetos Lead e Oportunidade deve ser definido como Privado ou Somente leitura pública.

  1. Em Configuração, selecione Personalizar e clique em Lead.
  2. Clique em Acionadores e em Novo.
  3. Para definir seu acionador, insira um Apex code semelhante a este código de exemplo.
    trigger ReferralShare on Lead (after update) {
        for(Lead lead : Trigger.new){
            try{
                Lead oldLead = Trigger.oldMap.get(lead.Id);
                // find the Group that the Lead creator is part of
                Group grp = [SELECT Id FROM Group WHERE Type='RoleAndSubordinates' 
                                AND RelatedId in (select UserRoleId from User where Id= :lead.CreatedById)];
                // Lead trigger sharing example - if the owner changed and the owner is different than the creator, 
                // share the Lead with the Group of the user that created the Lead
                if (lead.CreatedById!=lead.OwnerId && lead.OwnerId!=oldLead.OwnerId){
                    // create a new LeadShare record for the creator's Group
                    LeadShare leadShare = new LeadShare(LeadId=lead.Id, UserOrGroupId=grp.Id, LeadAccessLevel='Read', RowCause='Manual');
                    Database.SaveResult save = Database.insert(leadShare,false);
                    if (save.isSuccess()){
                        System.debug(LoggingLevel.ERROR, 'SAVE RESULT SUCCESS');
                    }
                    else {
                        for(Database.Error err : save.getErrors()){
                            System.debug(LoggingLevel.ERROR, 'SAVE RESULT ERROR: ' + err.getMessage());
                        }
                    }
                }
                // Opportunity sharing example - on Lead conversion, add an Opportunity sharing record for the Group of
                // the user that created the Lead
                if (lead.IsConverted){
                    // create a new OpportunityShare record for the creator's Group
                    OpportunityShare opptyShare = new OpportunityShare(OpportunityId=lead.ConvertedOpportunityId, UserOrGroupId=grp.Id, 
                                                                       OpportunityAccessLevel='Read', RowCause='Manual');
                    Database.SaveResult save = Database.insert(opptyShare,false);
                    if (save.isSuccess()){
                        System.debug(LoggingLevel.ERROR, 'SAVE RESULT SUCCESS');
                    }
                    else {
                        for(Database.Error err : save.getErrors()){
                            System.debug(LoggingLevel.ERROR, 'SAVE RESULT ERROR: ' + err.getMessage());
                        }
                    }
                }
            }
            catch(Exception ex){
                System.debug(LoggingLevel.ERROR, 'EXCEPTION: ' + ex.getMessage());
            }
        }  
    }
 
Carregando
Salesforce Help | Article