Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

            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;
share|improve this question
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 Jun 9 '14 at 12:59
up vote 7 down vote accepted

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);
share|improve this answer
where i have to change my trigger any suggestions plz.. – Sathya Jun 9 '14 at 13:33
@Sathya As the answer says, change t.what.get... to t.whatid.get... – sfdcfox Jun 9 '14 at 13:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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