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
snodskov_secuniasnodskov_secunia 

Error Messages in Community

We are using Communities and have a Trigger in place preventing Users with certain Profiles from deleting specific records (in this case a Question record).

The Trigger uses "addError" to prevent a record from being deleted. So, in short, the code validates if the User trying to delete the Question has a Profile that allows this or not. If not, the record is marked using addError along with an error message.

This works perfectly for our internal users but when a Community User tries to delete a Question they get this error message instead of the more userfriendly one:

"An internal server error has occurred
Error ID: 201458473-277641 (853642360)"

My question is this: Do we need to do something special in order to display the userfriendly error message defined when calling addError?

Does it have to do with the latest release of Communities? We found that displaying validation errors also was a bit tricky with the latest release.

Thanks.

/Søren Nødskov Hansen
ShashankShashank (Salesforce Developers) 
Hi Soren,

Could you please let me know if you are still facing this issue? If so, could you please provide me detailed replication steps?

Thanks,
Shashank
Salesforce.com
snodskov_secuniasnodskov_secunia
Hi Shashank

Thanks for getting back to me. It is still an issue for us so any help is much appreciated.

We run a Support Community using the Napili Community Template. In our SFDC Production Org. we have a Before Delete Trigger in place that prevents Users from deleting any records of the Question object. The trigger looks like this:
trigger QuestionBefore on Question (before insert, before update, before delete) {
    if (Trigger.isInsert) {
        
    } else if (Trigger.isUpdate) {
        
    } else if (Trigger.isDelete) {
        QuestionHandler.verifyDelete(Trigger.old);
    }
}
The QuestionHandler looks like this:
public with sharing class QuestionHandler {
	public static void verifyDelete(List<Question> newQuestions){
		if (!ObjectDeletionAllowance__c.getInstance().CanDeleteQuestions__c) {
			for (Question question : newQuestions){
				question.addError(Label.CantDeleteQuestions);
			}
		}
	}
}
The ObjectDeletionAllowance__c is a Custom Setting of type Hierarchy with Protected visibility. However, I have tried removing the reference to that Custom Setting as well as the reference to the Custom Label called CantDeleteQuestions but that didn't change anything. The internal server error message was still the one that was shown.

I have also tried using question.Title.addError(Label.CantDeleteQuestions) in order to link the error message to a specific field but the result was the same. We still got the internal server error message instead of our own message.

Finally, i have also tried changing QuestionHandler to use the without sharing keyword instead but still no change.

To reproduce this error, do the following:
  1. Create a Before Delete Trigger on Question that uses addError to prevent Users from deleting any Question records
  2. Create Community using Napili Template
  3. Log in to the Community as a Community User
  4. Ask a Question
  5. Delete the Question
Let me know what you come up with and if you need any further info or details, please don't hesitate to contact me directly.

Thanks.
Søren Nødskov
ShashankShashank (Salesforce Developers) 
Hi,

Could you please grant me login access and send me your org Id to ssrivatsavaya@salesforce.com so that I can investigate further on this issue?
snodskov_secuniasnodskov_secunia
Hi Shashank

I have now granted access for 1 week to Salesforce Support. Let me know if you need me to extend that period.

Thanks.
Søren Nødskov
ShashankShashank (Salesforce Developers) 
Please also send me your org Id to ssrivatsavaya@salesforce.com