+ Start a Discussion
Philip StennettPhilip Stennett 

Testing sending a Chatter Message

I'm having trouble with the tests for deployment of chatter messaging (private messages) in the visualforce community that I'm building. The tests all work in sandbox no problem but when I try and deploy to production I get the following incredibly vague error with no line numbers or anything:

Validation Errors While Saving Record(s)
Stack Trace: null

Below is a completely cut down version of a method that causes the issue. The user creation code is used elsewhere in other tests and doesn't cause difficulties and as far as I can tell all chatter permissions are enabled on the profile (it is a custom user profile which many of our employees use). I have also tried sending the message as myself instead of creating a user for that and encounter the same issue.

@isTest(SeeAllData=true)
static void testConversationCreation() {
		
    	Profile	profile = [Select Id FROM Profile WHERE Name = 'General Users'];
    			
	User sender = new User(Alias = 'unittest', Email='test@unittesting.com', 
            EmailEncodingKey='UTF-8', LanguageLocaleKey='en_US',
            LocaleSidKey='en_US', ProfileId = profile.Id,
            Title = 'Tester', FirstName = 'Test', LastName = 'Sender',
            TimeZoneSidKey='America/Los_Angeles', UserName='test@unittestingsender.com');
        insert sender;    
        
        User recipient = new User(Alias = 'unittest', Email='test@unittesting.com', 
            EmailEncodingKey='UTF-8', LanguageLocaleKey='en_US',
            LocaleSidKey='en_US', ProfileId = profile.Id,
            Title = 'Tester', FirstName = 'Test', LastName = 'Recipient',
            TimeZoneSidKey='America/Los_Angeles', UserName='test@unittestingrecipient.com');
        insert recipient;
        
        System.runAs(sender) {
        	ConnectApi.ChatterMessage message = ConnectApi.ChatterMessages.sendMessage('test', recipient.Id);
        	
        	System.assertNotEquals(null, message);
        }
}


jody_blyjody_bly
Methods in the ConnectApi namespace (Chatter in Apex) don't support the System.runAs() method: 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_connectapi_differences.htm

I'll pass this post to a QE eng, too, to see if there could be another issue. 

Jody


jody_blyjody_bly
The QE couldn't reproduce it locally, but said that the error suggests that there could be some validation rules in the production org preventing the private message from being sent.

Hope that helps,
Jody