function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JuuanGallegosJuuanGallegos 

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);
                }
            }
        }
Maharajan CMaharajan C
Hi Juuan,

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