You need to sign in to do that
Don't have an account?
Krishna Sahu 1
Hi friends i want writa a trigger to create a new team member but i getting a issue while i am changing the implating physician field value it not going right please help me on this
public static void PhysicianOnCareTeamAfterOrderStatusUpdate(map<Id, Order> newMap, map<Id, Order> oldMap){
List<CareTeam__c> mapCaseTeam = new List<CareTeam__c>();
Set<Id> setOfPhysicianId = new Set<Id>();
Map<Id, User> mapOfUserId = new Map<Id, User>();
for(Order objOrder : newMap.values())
{
setOfPhysicianId.add(objOrder.implanting_physician__c);
}
for(User user : [SELECT Id, Name, ContactId FROM User WHERE ContactId =: setOfPhysicianId]){
mapOfUserId.put(user.ContactId, user);
}
for(Order objOrder : newMap.values())
{
// for permanent type
if(objOrder.implanting_physician__c != null && objOrder.Type == 'NROP'){
mapCaseTeam.add(new CareTeam__c(Patient__c = objOrder.patient_account__c,
Member__c = mapOfUserId.get(objOrder.implanting_physician__c).Id,
Roles__c = 'Implanting Physician',
Status__c = 'Active'));
}
// for replacement physician
else if(objOrder.implanting_physician__c != null && objOrder.Type == 'NREP'){
mapCaseTeam.add(new CareTeam__c(Patient__c = objOrder.patient_account__c,
Member__c = mapOfUserId.get(objOrder.implanting_physician__c).Id,
Roles__c = 'Replacement Physician',
Status__c = 'Active'));
}
}
if(!mapCaseTeam.isEmpty()){
insert mapCaseTeam;
}
}
List<CareTeam__c> mapCaseTeam = new List<CareTeam__c>();
Set<Id> setOfPhysicianId = new Set<Id>();
Map<Id, User> mapOfUserId = new Map<Id, User>();
for(Order objOrder : newMap.values())
{
setOfPhysicianId.add(objOrder.implanting_physician__c);
}
for(User user : [SELECT Id, Name, ContactId FROM User WHERE ContactId =: setOfPhysicianId]){
mapOfUserId.put(user.ContactId, user);
}
for(Order objOrder : newMap.values())
{
// for permanent type
if(objOrder.implanting_physician__c != null && objOrder.Type == 'NROP'){
mapCaseTeam.add(new CareTeam__c(Patient__c = objOrder.patient_account__c,
Member__c = mapOfUserId.get(objOrder.implanting_physician__c).Id,
Roles__c = 'Implanting Physician',
Status__c = 'Active'));
}
// for replacement physician
else if(objOrder.implanting_physician__c != null && objOrder.Type == 'NREP'){
mapCaseTeam.add(new CareTeam__c(Patient__c = objOrder.patient_account__c,
Member__c = mapOfUserId.get(objOrder.implanting_physician__c).Id,
Roles__c = 'Replacement Physician',
Status__c = 'Active'));
}
}
if(!mapCaseTeam.isEmpty()){
insert mapCaseTeam;
}
}
Can you provide additional details about the issue you are facing while implementing the trigger?
List<User> userlist = [SELECT Id, Name, ContactId FROM User WHERE ContactId IN :setOfPhysicianId];
for(User user :userlist) {
mapOfUserId.put(user.ContactId, user);
}