There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was:

Apex trigger updatequotestatus caused an unexpected exception, contact your administrator: updatequotestatus: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.updatequotestatus line 5, column 1.

Error Occured at Line:

if((t.what.getsobjecttype() == quote__c.sobjecttype) && (t.subject.substring(0,5) == 'Email')

trigger updatequotestatus on task (after insert, after update){
    Set<Id> quoteIds = new Set<Id>();
    List<quote__c> quotes = new List<quote__c>();

    for(task t:trigger.new){
            if((t.what.getsobjecttype() == quote__c.sobjecttype) && (t.subject.substring(0,5) == 'Email')){

    for(quote__c q:[select StageName__c from quote__c where Id IN : quoteIds]){
        quote__c qt = new quote__c();
        qt.Id = q.Id;
        qt.StageName__c = 'Proposal Sent';

        update quotes;
  • 4
    NullPointerExceptions are pretty straightforward. You are referencing a variable that is not initialised or has been set to null. There are not many variables in if((t.what.getsobjecttype()==quote__c.sobjecttype) && (t.subject.substring(0,5)=='Email') so I suggest you do some debugging (e.g. printout the value of t.what) to see what is null in that line
    – BarCotter
    Commented Jun 9, 2014 at 12:59

1 Answer 1


T.what is null, because you haven't queried for it, and the relationships passed into a trigger are always null. Instead, you can call getSobjectType on WhatId directly:

if(t.WhatId != NULL && t.WhatId.getSobjectType() == Quote__c.SobjectType ...

Bonus: Also, since you aren't checking for any of the data from the query, there's strictly no reason to waste a query here:

for(Id quoteId: quoteIds) {
    Quote__c q = new Quote__c(Id=quoteId);
  • where i have to change my trigger any suggestions plz..
    – Sathya
    Commented Jun 9, 2014 at 13:33
  • @Sathya As the answer says, change t.what.get... to t.whatid.get...
    – sfdcfox
    Commented Jun 9, 2014 at 13:35

You must log in to answer this question.

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