0
public class UpdateSkillsOfAgents {
    public List<ServiceResourceSkill> ServiceResourceSkillList;
    public List<ServiceResource> ServiceResourceList{get;set;}
    public Map<Id, List<ServiceResourceSkill>> serviceResourceIdSRSkillMap{get; set;}
    public Map<Id, List<ServiceResource>> serviceResourceMap{get; set;}
    public Set<Id> keyValues {get; set;}
    public Set<Id> serviceResourceSkillIdSet = new Set<Id>();
    public UpdateSkillsOfAgents (){
        updateSkills();
    }
    public void updateSkills() {
        ServiceResourceList = [SELECT Id,Name,RelatedRecord.Name,RelatedRecordId FROM ServiceResource];
        System.debug('ServiceResourceList'+ServiceResourceList);
        for(ServiceResource sr: ServiceResourceList){
            serviceResourceSkillIdSet.add(sr.Id);
            serviceResourceMap.put(sr.Id,ServiceResourceList);
            System.debug('serviceResourceMap'+serviceResourceMap);
        }
        System.debug('serviceResourceSkillIdSet'+serviceResourceSkillIdSet);
        for(ServiceResourceSkill srSkill : [SELECT Id, ServiceResourceId,SkillId, Skill.DeveloperName FROM ServiceResourceSkill WHERE ServiceResourceId IN:serviceResourceSkillIdSet]) {
            List<ServiceResourceSkill> newSrSkillList = new List<ServiceResourceSkill>();
            newSrSkillList.add(srSkill);
            ServiceResourceSkillList.add(srSkill);
            serviceResourceIdSRSkillMap.put(srSkill.ServiceResourceId, newSrSkillList); 
            keyValues = serviceResourceIdSRSkillMap.keySet();
            System.debug('serviceResourceIdSRSkillMap'+serviceResourceIdSRSkillMap);
        }
        
    }    
    public PageReference updateAgentSkills(){  
        try{
            ServiceResourceSkillList = [SELECT Id,ServiceResourceId,SkillId FROM ServiceResourceSkill WHERE ServiceResourceId IN: serviceResourceSkillIdSet ];
            update ServiceResourceSkillList;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);
        }
        updateSkills();
        return null;
    }
}

I am getting an error

FATAL_ERROR System.NullPointerException: Attempt to de-reference a null object.

at the line
serviceResourceIdSRSkillMap.put(srSkill.ServiceResourceId, newSrSkillList);
and
ServiceResourceSkillList.add(srSkill);serviceResourceIdSRSkillMap.put(srSkill.ServiceResourceId, newSrSkillList);

Please help me with some ideas.

Thank you in Advance!!

1 Answer 1

0

You haven't initialized serviceResourceIdSRSkillMap. It is null. You always must initialize collections and other variables in Apex before you reference them.

More broadly, this is an exception you can resolve in your own code simply by tracing the source of the null value. It's impossible for srSkill to be null because it is a query result. It's impossible for ServiceResourceSkillList to be null because it is explicitly initialized. That only leaves one potential culprit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .