Final answer:
The addError() method in Salesforce can be used to prevent saving records in a trigger and display an error message.
Step-by-step explanation:
To prevent saving records in a trigger and display an error message, you can use the addError() method in Salesforce. This method adds an error to a record and prevents it from being saved. The error message can be displayed in the user interface and logged for reference. Here is an example:
// Create a new Account
Account acc = new Account(Name='Test Account');
// Add an error to the Account
acc.addError('Unable to save Account record');
// The Account record will not be saved
Database.insert(acc, false);