You need to sign in to do that
Don't have an account?
JuuanGallegos
How can I retrieve the accounts values related with the orders, in the if condition, the value that I´m getting is null, and I expecting to receive false or true, but I´m getting null,
public void checkOrderTypeBeforeCreateUserPortal() {
String permissionId = [Select id from PermissionSet where Name ='PatientPortal' limit 1].Id;
for(Order o : (List<Order>) Trigger.newMap){
if((o.Secondary_Order_Type__c != 'HVK' || o.Secondary_Order_Type__c != 'HHW') && o.Account.GCE_Registered_for_Patient_Portal__c == true) {
try {
CtrlCommunityUserMagmt.ctrl_setPermission(permissionId,
o.Account.HealthCloudGA__PrimaryContact__c,
'',
'PatientPortal',
true,
'GCE Customer Community User');
}
catch (Exception e){
system.debug('### Error ' + e);
}
}
}
String permissionId = [Select id from PermissionSet where Name ='PatientPortal' limit 1].Id;
for(Order o : (List<Order>) Trigger.newMap){
if((o.Secondary_Order_Type__c != 'HVK' || o.Secondary_Order_Type__c != 'HHW') && o.Account.GCE_Registered_for_Patient_Portal__c == true) {
try {
CtrlCommunityUserMagmt.ctrl_setPermission(permissionId,
o.Account.HealthCloudGA__PrimaryContact__c,
'',
'PatientPortal',
true,
'GCE Customer Community User');
}
catch (Exception e){
system.debug('### Error ' + e);
}
}
}
Trigger.newmap will not allow you access the related record values. It will holds only the current record details. So you have to query the parent records details from Server.
public void checkOrderTypeBeforeCreateUserPortal() {
String permissionId = [Select id from PermissionSet where Name ='PatientPortal' limit 1].Id;
Set<Id> accountIds = new set<Id>();
Map<Id,Account> accMap;
for(Order ord : (List<Order>) Trigger.newMap){
accountIds.add(ord.AccountId);
}
if(!accountIds.IsEmpty())
{
accMap = new Map<Id,Account>([Select id,GCE_Registered_for_Patient_Portal__c from Account where Id in: accountIds]);
}
for(Order o : (List<Order>) Trigger.newMap){
if((o.Secondary_Order_Type__c != 'HVK' || o.Secondary_Order_Type__c != 'HHW')
&& accMap.contaiskey(o.AccountId) && accMap.get(o.AccountId).GCE_Registered_for_Patient_Portal__c == true)
{
try {
CtrlCommunityUserMagmt.ctrl_setPermission(permissionId,
o.Account.HealthCloudGA__PrimaryContact__c,
'',
'PatientPortal',
true,
'GCE Customer Community User');
}
catch (Exception e){
system.debug('### Error ' + e);
}
}
}
Thanks,
Maharajan.C