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();

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';
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

  • 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, 2015 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, 2015 at 19:44
  • Keith: its failing on 'update Employees'
    – Nick
    Jun 9, 2015 at 19:46
  • Crop: I am not sure I understand
    – Nick
    Jun 9, 2015 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, 2015 at 20:18

1 Answer 1


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.

You must log in to answer this question.

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