• GONZALO PIZARRO RIVERA 6
  • NEWBIE
  • 10 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello, I am trying to get the User->Id field using a custom field (Id_SAP__c) that i have in the user object. 
To do this i have created a map with those two fields in order to get the id of the user but i am receiving an error and i dont know how to solve it.
Please, can anyone help me?

This my code:

public static void fillOwnerField(List<Promoci_n__c> lstPromociones){
        Set<String> setResources = new Set<String>();
        for(Promoci_n__c p :lstPromociones){
            if(p.Comercial_Id_SAP__c != null){
                setResources.add(p.Comercial_Id_SAP__c);
            }   
        }
        System.debug('***setResources = '+setResources);
        if(setResources.size() > 0){
            Map<Id, User> mapSR = new Map<Id, User>([Select Id, Id_SAP__c From User where Id_SAP__c in: setResources]);
            System.debug('***mapSR = '+mapSR);
            for(Promoci_n__c p :lstPromociones){
                System.debug('***p.Comercial_Id_SAP__c = '+p.Comercial_Id_SAP__c);
                System.debug('***Comercial_Asignado__c = '+mapSR.values());
                System.debug('***Comercial_Asignado__c = '+mapSR.get(p.Comercial_Id_SAP__c).Id_SAP__c);
                p.Comercial_Asignado__c = mapSR.get(p.Comercial_Id_SAP__c).Id_SAP__c;
            }

        }
    }

I get the error in line

System.debug('***Comercial_Asignado__c = '+mapSR.get(p.Comercial_Id_SAP__c).Id_SAP__c);

thank you in advance
Hello, I am trying to get the User->Id field using a custom field (Id_SAP__c) that i have in the user object. 
To do this i have created a map with those two fields in order to get the id of the user but i am receiving an error and i dont know how to solve it.
Please, can anyone help me?

This my code:

public static void fillOwnerField(List<Promoci_n__c> lstPromociones){
        Set<String> setResources = new Set<String>();
        for(Promoci_n__c p :lstPromociones){
            if(p.Comercial_Id_SAP__c != null){
                setResources.add(p.Comercial_Id_SAP__c);
            }   
        }
        System.debug('***setResources = '+setResources);
        if(setResources.size() > 0){
            Map<Id, User> mapSR = new Map<Id, User>([Select Id, Id_SAP__c From User where Id_SAP__c in: setResources]);
            System.debug('***mapSR = '+mapSR);
            for(Promoci_n__c p :lstPromociones){
                System.debug('***p.Comercial_Id_SAP__c = '+p.Comercial_Id_SAP__c);
                System.debug('***Comercial_Asignado__c = '+mapSR.values());
                System.debug('***Comercial_Asignado__c = '+mapSR.get(p.Comercial_Id_SAP__c).Id_SAP__c);
                p.Comercial_Asignado__c = mapSR.get(p.Comercial_Id_SAP__c).Id_SAP__c;
            }

        }
    }

I get the error in line

System.debug('***Comercial_Asignado__c = '+mapSR.get(p.Comercial_Id_SAP__c).Id_SAP__c);

thank you in advance