+ Start a Discussion
Jim MontgomeryJim Montgomery 

attempt to de-reference a null object error adding fields together

trigger OutsourceOrderTotal on Apttus_Proposal__Proposal__c (after update) {    
    
  
       for(apttus_proposal__proposal__c p : trigger.new)
           if(p.os_offshore_1040_1041_dollars__c == null 
              && p.os_offshore_business_dollars__c == null 
              && p.os_offshore_charter_dollars__c == null 
              && p.os_onshore_1040_1041_dollars__c == null 
             && p.os_onshore_business_dollars__c == null
             &&p.os_onshore_charter_dollars__c == null)
           {
        p.os_order_total_trigger__c = 0;
    }
    else
         {             
            p.os_order_total_trigger__c = p.os_offshore_1040_1041_dollars__c +  p.os_offshore_business_dollars__c + p.os_offshore_charter_dollars__c
             + p.os_onshore_1040_1041_dollars__c + p.os_onshore_business_dollars__c + p.os_onshore_charter_dollars__c;
           }  
    
       
}
Best Answer chosen by Jim Montgomery
{!Piyush_soni__c}{!Piyush_soni__c}
try below code :
trigger OutsourceOrderTotal on Apttus_Proposal__Proposal__c (before update) {    
   Integer oTotal = 0;
       for(apttus_proposal__proposal__c p : trigger.new){
           if(p.os_offshore_1040_1041_dollars__c == null && p.os_offshore_business_dollars__c == null && p.os_offshore_charter_dollars__c == null && p.os_onshore_1040_1041_dollars__c == null && p.os_onshore_business_dollars__c == null && p.os_onshore_charter_dollars__c == null){
              p.os_order_total_trigger__c = 0;
           }else{ 
		     if(p.os_offshore_1040_1041_dollars__c != null){
				oTotal +=  p.os_offshore_1040_1041_dollars__c;
			 }
			 if(p.os_offshore_business_dollars__c != null){
				oTotal +=  p.os_offshore_1040_1041_dollars__c; 
			 }
			 if(p.os_offshore_charter_dollars__c != null){
				oTotal +=  p.os_offshore_charter_dollars__c; 
			 }
			 if(p.os_onshore_1040_1041_dollars__c != null){
				oTotal +=  p.os_onshore_1040_1041_dollars__c; 
			 }
			 if(p.os_onshore_business_dollars__c != null){
				oTotal +=  p.os_onshore_business_dollars__c; 
			 }
			 if(p.os_onshore_charter_dollars__c != null){
				oTotal +=  p.os_onshore_charter_dollars__c; 
			 }
               
			   p.os_order_total_trigger__c = oTotal;
           }  
    }
}
Thanks let me know if it helps you
 

All Answers

{!Piyush_soni__c}{!Piyush_soni__c}
hi jlm, write trigger on before insert not after insert, use below code
trigger OutsourceOrderTotal on Apttus_Proposal__Proposal__c (before update) {    
  
       for(apttus_proposal__proposal__c p : trigger.new){
           if(p.os_offshore_1040_1041_dollars__c == null 
              && p.os_offshore_business_dollars__c == null 
              && p.os_offshore_charter_dollars__c == null 
              && p.os_onshore_1040_1041_dollars__c == null 
             && p.os_onshore_business_dollars__c == null
             &&p.os_onshore_charter_dollars__c == null){
             p.os_order_total_trigger__c = 0;
           }
         else{             
            p.os_order_total_trigger__c = p.os_offshore_1040_1041_dollars__c +  p.os_offshore_business_dollars__c + p.os_offshore_charter_dollars__c
             + p.os_onshore_1040_1041_dollars__c + p.os_onshore_business_dollars__c + p.os_onshore_charter_dollars__c;
           }  
    }
}
i hope it helps you.
      Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
    thanks
sfdcmonkey.com
 
Jim MontgomeryJim Montgomery
I tried before update and before insert and still get the same error. Jim Montgomery Manager, Sales Intelligence Operations North America Tax & Accounting 20101 Hamilton Ave. Torrance, CA 90502 877-346-7148 jim.montgomery@wolterskluwer.com [wklogo] Confidentiality Notice: This email and any attachments may contain confidential or privileged information that is intended for the addressee only. If you are not an intended recipient of the original sender (or responsible for delivering the message to such person), you are hereby notified that any review, disclosure, copying, distribution or the taking of any action in reliance of the contents of and attachments to this email is strictly prohibited. If you have received this email in error, please immediately notify the sender at the address shown herein and permanently delete any copies of this email (digital or paper) in your possession. Wolters Kluwer shall not be liable for the incorrect or incomplete transmission of this email or any attachments, nor for unauthorized use by its employees.
{!Piyush_soni__c}{!Piyush_soni__c}
try below code :
trigger OutsourceOrderTotal on Apttus_Proposal__Proposal__c (before update) {    
   Integer oTotal = 0;
       for(apttus_proposal__proposal__c p : trigger.new){
           if(p.os_offshore_1040_1041_dollars__c == null && p.os_offshore_business_dollars__c == null && p.os_offshore_charter_dollars__c == null && p.os_onshore_1040_1041_dollars__c == null && p.os_onshore_business_dollars__c == null && p.os_onshore_charter_dollars__c == null){
              p.os_order_total_trigger__c = 0;
           }else{ 
		     if(p.os_offshore_1040_1041_dollars__c != null){
				oTotal +=  p.os_offshore_1040_1041_dollars__c;
			 }
			 if(p.os_offshore_business_dollars__c != null){
				oTotal +=  p.os_offshore_1040_1041_dollars__c; 
			 }
			 if(p.os_offshore_charter_dollars__c != null){
				oTotal +=  p.os_offshore_charter_dollars__c; 
			 }
			 if(p.os_onshore_1040_1041_dollars__c != null){
				oTotal +=  p.os_onshore_1040_1041_dollars__c; 
			 }
			 if(p.os_onshore_business_dollars__c != null){
				oTotal +=  p.os_onshore_business_dollars__c; 
			 }
			 if(p.os_onshore_charter_dollars__c != null){
				oTotal +=  p.os_onshore_charter_dollars__c; 
			 }
               
			   p.os_order_total_trigger__c = oTotal;
           }  
    }
}
Thanks let me know if it helps you
 
This was selected as the best answer
Jim MontgomeryJim Montgomery
I had to change Interger to Decimal, but after that worked great.

Thanks!!!