0

I got stuck and now sure what I'm doing wrong here:

here is my trigger:

trigger EmployeeTrigger on Employee__c (after insert, before update) 
{
    EmployeeController mr = new EmployeeController();
    mr.EmployeeController(Trigger.new);
}

Apex class:

List<Employee__c> Employees = new List<Employee__c>();
List<Employee__c> empList = [SELECT Id, Name, Employee_Name__c
                                     FROM Employee__c 
                                     WHERE Employee_Id__c = 123456 ];

for(Employee__c pm : empList)
{
   pm.Current_City__c = 'timbaktu';
   Employees.Add(pm);
}
update Employees;

Review all error messages below to correct your data. Apex trigger EmployeeTrigger caused an unexpected exception, contact your administrator: EmployeeTrigger: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Class.EmployeeController.EmployeeController: line 147, column 1

8
  • 1
    You should identify which line is line 147 in your question. I don't see anything in the code you posted that would cause an NPE. – Keith C Jun 9 '15 at 19:44
  • triggers invoking controllers ...not best practice - there is no VF context when calling a VF controller object from a trigger – cropredy Jun 9 '15 at 19:44
  • Keith: its failing on 'update Employees' – Nick Kahn Jun 9 '15 at 19:46
  • Crop: I am not sure I understand – Nick Kahn Jun 9 '15 at 19:47
  • ... are you sure there isn't any logic that could set Employees to null between where you declare and initialise it and the update? – Keith C Jun 9 '15 at 20:18
0

If line 147 has pm.Current_City__c = 'timbaktu';, then you probably have this issue because the field Current_City__c was not included in the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.