function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BrianWKBrianWK 

SendEmail Passes Sandbox - Fails on Deploy - Weird error: UNKNOWN_EXCEPTION Parameter value is null

I created a send email class that accepts a bunch of parameters. It's currently used by two visualforce pages and 1 trigger/class.

 

The trigger/class setup is currently failing when I deploy to production. However, when I run the tests in the sandbox it comes back completely fine. The trigger is fired on an update of a case. When I update the case to fire the trigger - I get the expected result (an email).

 

I am creating my objects in the test class - except my Email Template and SF user (which are in both sandbox and production). All other objects - Account, Contact, and Case are created in the test class directly.

 

I added a system.debug('THIS IS THE MAIL:" + mail); to my send email class and this is what I see in the debug log when I deploy.

 

20090417151127.818:Class.Send_Single_Email_Class.SendEmail: line 111, column 9: THIS IS THE MAIL:Messaging.SingleEmailMessage[getBccAddresses=();getCcAddresses=();getCharset=null;getDocumentAttachments=null;getFileAttachments=null;getHtmlBody=null;getPlainTextBody=null;getTargetObjectId=005700000017EbwAAE;getTemplateId=00X70000001F7ESEA0;getToAddresses=(support@pharmacyonesource.com);getWhatId=50070000008R2QFAA0;isUserMail=false;] System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null

 

 

You can see it stats Unknown_Exception - then tells me a parmaeters is null. I've compared these lines to a successful test that's run (using the same class but on different objects) - and with the exception of the TemplateID (not used) and the specific Email Address/WhatID it looks 100% the same.

 

I thought it might be my template problem - but I'm setting it like this

***Trigger's Class*** EmailTemplate ThisTemplate = [Select e.Id From EmailTemplate e where e.developerName= 'Case_Notification_of_New_Task_or_Comment']; ID TemplateID = ThisTemplate.Id; ***Send Email Class*** mail.setTemplateId(TemplateID); system.debug('Template is Valid: ' + TemplateID);

 

I'm really scratching my head on this one. I figured I must be missing something when I pass things over. But the SendEmail class works with my visualforce pages - just not this Trigger/Class. The main difference is I'm using a template ID and not setting the mail.setToAddresses to anything other than null.

 

Current UnitTest - The Trigger loops through trigger.new and assigns to variables the items passed over to each send email.

 

static testMethod void testTriggerCase_Interface_Before_Insert_Before_Update() 
{
	RecordType CaseRecordType = [Select r.SobjectType, r.Id, r.DeveloperName From RecordType r where r.DeveloperName='Standard' and sObjectType = 'Case'];
	User CSRQueue = [Select u.Username, u.UserRoleId, u.ProfileId, u.ManagerId, u.LastName, u.IsActive, u.Id, u.FirstName, u.Name,u.Email, u.CommunityNickname, u.Alias From User u where u.Id = '005700000017Ebw' and u.IsActive = True limit 1];
			
		Account NewAccount1 = new Account(name='Test Code Account',
			Hospital_Bed_Size__c = -1,
			BillingStreet = '7780 Elmwood Ave',
			BillingCity = 'Middleton', 
			BillingState = 'WI', 
			BillingPostalCode = '5356'
	   	);
	        insert NewAccount1;
		Contact NewContact = new Contact(
	   		LastName='Test',
	   		firstname='Contact',
	   		Email=CSRQueue.Email,
	   		AccountId = NewAccount1.id
	   	);	
	   	insert NewContact;	    
		Implementation__c NewS7IF = new Implementation__c 
	   	(
	   		RecordTypeId = '012500000009EQZ',
	   		Name = 'Test Code Implementation',
	   		Account__c = NewAccount1.id,
	   		//i.Product__c = 'Unit Stock',
	   		Sale_Date__c = date.Today(),
	   		Implementer__c = '005700000017Ebw', //CSR Queue   			
	   		Action_Requirement__c = 'POS',
	   		Stage__c = 'Initiation',
	   		Status__c = 'Moving Along',
	   		Status_Reason__c = 'N/A',
	   		Product__c = 'Sentri7 Interfaces',
	   		Interface_Products__c = 'Quantifi',
	   		Feed_Status__c = 'No Data Received Yet'
	   	);	
	   	insert NewS7IF;	   	
		Case NewStandardCase = new Case
		(
		  OwnerId = '005700000017Ebw', //CSR Queue 
		  //Implementation_Issue__c = ImpIssueTestUnit().id, //Issue to be used 
		  Type = 'Interfaces', 
		  Project_Type__c = 'Hold',
		  Implementation__c = NewS7IF.Id,
		  Products__c = 'Interfaces',		  
		  ContactId = NewContact.Id,
		  Origin = 'Internal',
		  Subject = 'This is a test subject used to test trigger',
		  RecordTypeId = CaseRecordType.Id		
		);
		Case NewStandardCase2 = new Case
		(
		  OwnerId = CSRQueue.ID, //'005700000017Ebw', //CSR Queue 
		  //Implementation_Issue__c = ImpIssueTestUnit().id, //Issue to be used 
		  Type = 'Interfaces', 
		  Project_Type__c = 'Hold',
		  Implementation__c = NewS7IF.Id,
		  Products__c = 'Interfaces',		  
		  ContactId = NewContact.Id, 
		  Origin = 'Internal',
		  Subject = 'This is a test subject used to test trigger2',
		  RecordTypeId = CaseRecordType.Id		
		);
		list<case> InsertCases = new list<case>();
		
		InsertCases.add(NewStandardCase);
		InsertCases.add(NewStandardCase2);			
		insert InsertCases;
		
        NewStandardCase.Notification_to_Owner__c = 1;
        NewStandardCase2.Notification_to_Owner__c = 0;
        list<case> UpdateCases = new list<case>();
        UpdateCases.add(NewStandardCase);
        UpdateCases.add(NewStandardCase2);        
        update UpdateCases;	
				
	} 

 

The Class that calls the SendEmail Class - this is done on a before update. Trigger is fired before update of case, and only cases with Notification_To_Owner__c set to 1 are sent to the NotificationToOwner class method below. The class loops through the list pulling the information and sending the e-mail and also returns the value to Notification_To_Owner__c to 0.

There's a lot of "empty" variables here since they get passed in other classes that use the SendEmail class. When I tested it doesn't appear that anything goes wrong if these are null as long as the required items are also present. (Example either a TemplateID or a HTMl/Plain body)

 

public static void NotificationToOwner(list<case> TheseCases) { set<id> OwnerID = new set<id>(); for(case c: TheseCases) { OwnerID.add(c.OwnerID); } map<id, User> MapUsers = new map<id,user>([Select u.Title, u.ManagerId, u.Id, u.Email From User u where u.id in :OwnerID]); /*Required SendEmail Variables */ list<string> ToEmail = new list<string>(); Contact eContact; list<string> CC = new list<string>(); list<string> BCC = new list<string>(); Boolean eAttach = False; Blob eAttachment; string eName; Boolean Activity = False; ID WhatID; Boolean Attach = False; String aName; String eSubject; String eBody; list<ID> DocAttach = new list<ID>(); EmailTemplate ThisTemplate = [Select e.Id From EmailTemplate e where e.developerName= 'Case_Notification_of_New_Task_or_Comment']; /*This template is present in both Sandbox and Production with the SAME developername */ ID TemplateID = ThisTemplate.Id; ID TargetObjectId; //list<case> UpdateCases = new list<case>(); /*Loop through cases and send Email */ for(case c: thesecases) { ToEmail.Clear(); //ToEmail.add(MapUsers.get(c.OwnerID).Email); WhatID = c.id; TargetObjectID = c.OwnerID; c.Notification_to_Owner__c=0; system.debug('Case Number, Case ID: ' + c.CaseNumber +' ID: '+ c.ID); system.debug('Email Variable OwnerID: ' + c.OwnerID); system.debug('Email Variable Email: ' + ToEmail); system.debug('Email Variable Case WhatID: ' + WhatID); Send_Single_Email_Class.SendEmail(ToEmail,eContact, CC,BCC, eAttach, eAttachment,eName, Activity,WhatId,Attach, aName,eSubject,eBody,DocAttach,TemplateID,TargetObjectID); } }

 

BrianWKBrianWK
 

Still trying to figure this out. I ran a test in the API Sandbox and pulled out the debug log. I'm comparing the log for the system.debug('THIS IS THE MAIL: ' + mail) ;

and here's what I get

*THIS WORKS PASSED TEST IN SANDBOX*** 20090417180534.902:Class.Send_Single_Email_Class.SendEmail: line 111, column 9: THIS IS THE MAIL:Messaging.SingleEmailMessage [getBccAddresses=(); getCcAddresses=(); getCharset=null; getDocumentAttachments=null; getFileAttachments=null; getHtmlBody=null; getPlainTextBody=null; getTargetObjectId=005700000017EbwAAE; getTemplateId=00XQ0000000HtVKMA0; getToAddresses=(); getWhatId=500Q0000000fgaCIAQ; isUserMail=false;]

 

 

**THIS FAILS Debug from Deploy Attempt** 20090417162503.801:Class.Send_Single_Email_Class.SendEmail: line 111, column 9: THIS IS THE MAIL:Messaging.SingleEmailMessage getBccAddresses=(); getCcAddresses=(); getCharset=null; getDocumentAttachments=null; getFileAttachments=null; getHtmlBody=null; getPlainTextBody=null; getTargetObjectId=005700000017EbwAAE; getTemplateId=00X70000001F7ESEA0; getToAddresses=(); getWhatId=50070000008R3NRAA0; isUserMail=false;]

System.EmailException: SendEmail failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: Argument Error: Parameter value is null

You can see that they're almost identical except for the TemplateID and WhatID (since WhatID is an inserted Test unit object, and the TemplateID is different between Sandbox/Production - but it's set via a SoQL query). So what's failing?

PSteves91PSteves91

Hello,

 

I am running into the same issue... have you received any update on this topic?

 

Thanks.

SkwalSkwal

Hello,

 

Has anyone resolved this? I have the same issue when testing send email code. The code works in Sandbox and sends the email but fails with the UNKOWN_EXECEPTION / Parameter values is null when running the test class.

 

Thanks 

 

SkwalSkwal

OK, I resolved the problem for my part: I had a VisualForce tag in the html body of my VisualForce email template. I replaced it by the html equivalent and all worked fine. If the deployment is failing, I would suggest to look into the email template on the production organization to make sure it is identical to the one on Sandbox.

Best Regards

PG

 

 

 

 

BritishBoyinDCBritishBoyinDC

For anyone else ending up here...I had the same error, and after reading this post, turned off a workflow rule triggered by the code that was sending a VF Template email, and the code deployed...thanks for posting!

 

 

rklaassenrklaassen

Had this problem too deploying to production. Just cleared all the htmlBody in the emailtemplate in production en got it to deploy.

Unfortunately, it's not working in production properly. When I just test the emailtemplate it works fine, but if the emailtemplate gets used by the scheduled apex I created, it gives the same error: UNKNOWN_EXCEPTION. I just tried about anything, any ideas?

samdsamd

I've just run into exactly the same problem.  My tests ran fine on sandbox, but failed when I tried to push to PROD.  I found that this was due to an approval process which was using  a VF email template.  I edited the approval process in PROD to remove the email template and the deployment completed successfully. 

 

Interestingly, I then added the email back to the approval process and ran the test that was failing previously and it completed successfully.  However, when I next tried to deploy other code to PROD, the same error cropped up and I had to remove the email from the approval process again.