Loading
Slack 관련 문의처가 Salesforce Help로 통합 및 변경됩니다.더 많이 읽기
리드 가시성을 유지하기 위한 트리거 만들기

리드 가시성을 유지하기 위한 트리거 만들기

더 이상 리드의 소유자가 아니더라도 리드를 만든 사람에게 공유 액세스 권한을 부여하는 트리거를 추가합니다. 공유 액세스 권한을 부여하면 리드의 작성자가 기회로 변환된 후 추천을 추적할 수 있습니다.

필수 Edition

지원 제품: Lightning Experience

지원 제품: Health Cloud Enterprise 및 Unlimited Edition

중요
중요 리드 및 기회 개체를 사용하여 위탁을 관리하는 대신 FHIR R4 지정 임상 데이터 모델을 위해 구축된 임상 서비스 요청 개체 및 자동화 도구를 사용합니다. 향후 신규 및 향상된 위탁 관리 기능을 활용하려면 임상 데이터 모델의 개체를 사용해야 합니다.

LeadShare 및 OpportunityShare 개체에 액세스하려면 리드 및 기회 개체에 대한 공유를 비공개 또는 공용 읽기 전용으로 설정해야 합니다.

  1. 설정에서 사용자 정의를 선택한 다음, 리드 를 클릭합니다.
  2. 트리거를 클릭한 다음, 새로 만들기를 클릭합니다.
  3. 트리거를 정의하려면 이 샘플 코드와 유사한 Apex 코드를 입력합니다.
    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());
            }
        }  
    }
 
로드 중
Salesforce Help | Article