즐겨찾기Samsudeen Ameen (digiAppForce) 님이 Advanced Administrator Study Group에 글을 올렸습니다 (최초 질문자: Samsudeen Ameen)2021년 11월 19일 오후 2:02Samsudeen AmeenError not firingI am sure someone here can help me figure out what I am doing wrong here. We have an opportunity record type where partner portal users (they are also contact) have to select a lookup field called "Study" that looks up to a custom object called Project__c when creating oppty. However, Project__c also has another child-related object called Nurse_Training_Session__c. Nurse_Training_Session__c has a field that looks up to Contact called HcP__c and another lookup field called Project__c. Now, HcP__c is used to track contacts who have been assigned to work on a project (Project__c). When they log in to the portal to create an opportunity, we want to throw an error if they select a study they have not been assigned. @TestVisibleprivate static final String UNALLOCATED_STUDY_ERROR_MSG = 'You have not been allocated to work on this study. Please select the correct study'; public void beforeInsert(List<Opportunity> newList){ Set<Id> projIds = new Set<Id>(); // Store Project__r.Id Id nurseSuppliesRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Nurse_Supplies').getRecordTypeId(); Id curUserId = userinfo.getUserId(); // Get current logged in user User curUser = [SELECT Id, ContactId FROM User WHERE Id = :curUserId AND ContactId != null]; Contact contId = [SELECT Id FROM Contact WHERE Id = :curUser.ContactId]; List<Nurse_Training_Session__c> lstHcps = [SELECT Id, HcP__r.Id, Project__r.Id FROM Nurse_Training_Session__c WHERE HcP__r.Id = :contId.Id]; If(curUser != null && !lstHcps.isEmpty()){ for(Nurse_Training_Session__c hcp: lstHcps){ projIds.add(hcp.Project__r.Id); } for(Opportunity op: newList){ if(op.RecordTypeId == nurseSuppliesRecordTypeId && op.Study__c != null && !projIds.contains(op.Study__r.Id)) { op.Study__c.addError(UNALLOCATED_STUDY_ERROR_MSG); } } } } 더 보기댓글 1개Ricardo Costa (Ricardo)2025년 4월 14일 오전 6:15Check the procedures thet envolve the code댓글 추가댓글을 작성하세요...굵은 글꼴기울인 글꼴밑줄취소선불릿 기호 목록번호가 지정된 목록링크 추가코드 블록이미지 삽입파일 첨부링크 URL취소저장0/9000답글 쓰기
Samsudeen AmeenError not firingI am sure someone here can help me figure out what I am doing wrong here. We have an opportunity record type where partner portal users (they are also contact) have to select a lookup field called "Study" that looks up to a custom object called Project__c when creating oppty. However, Project__c also has another child-related object called Nurse_Training_Session__c. Nurse_Training_Session__c has a field that looks up to Contact called HcP__c and another lookup field called Project__c. Now, HcP__c is used to track contacts who have been assigned to work on a project (Project__c). When they log in to the portal to create an opportunity, we want to throw an error if they select a study they have not been assigned. @TestVisibleprivate static final String UNALLOCATED_STUDY_ERROR_MSG = 'You have not been allocated to work on this study. Please select the correct study'; public void beforeInsert(List<Opportunity> newList){ Set<Id> projIds = new Set<Id>(); // Store Project__r.Id Id nurseSuppliesRecordTypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByDeveloperName().get('Nurse_Supplies').getRecordTypeId(); Id curUserId = userinfo.getUserId(); // Get current logged in user User curUser = [SELECT Id, ContactId FROM User WHERE Id = :curUserId AND ContactId != null]; Contact contId = [SELECT Id FROM Contact WHERE Id = :curUser.ContactId]; List<Nurse_Training_Session__c> lstHcps = [SELECT Id, HcP__r.Id, Project__r.Id FROM Nurse_Training_Session__c WHERE HcP__r.Id = :contId.Id]; If(curUser != null && !lstHcps.isEmpty()){ for(Nurse_Training_Session__c hcp: lstHcps){ projIds.add(hcp.Project__r.Id); } for(Opportunity op: newList){ if(op.RecordTypeId == nurseSuppliesRecordTypeId && op.Study__c != null && !projIds.contains(op.Study__r.Id)) { op.Study__c.addError(UNALLOCATED_STUDY_ERROR_MSG); } } } } 더 보기