Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I want a user to be able to create new new record for an object, but then be shown a message and not the inserted record itself, is there a method I can use for displaying a message other than addError()?

share|improve this question
Hi Kishan, I was going to edit this but are you saying you want it to show a message and still insert the records, or are you just after an alternative to addError()? – LaceySnr Sep 5 '12 at 5:27
i want to show a message and still insert the records in object but at that time record is not seen to user but user can only see the message and only admin can see that what that user enter – Kishan Trambadiya Sep 5 '12 at 6:05
Not enough info in the question. – Anup Sep 5 '12 at 6:27
2  
Ok, I think I've made your question into what you're actually asking... – LaceySnr Sep 5 '12 at 6:50

1 Answer

Displaying a Message After Insert

To allow a user to create a new record, but then see a message instead of the record you'll need to implement a VisualForce page using a controller extension, where the extension takes care of saving the record and then toggling a public variable used to control the onscreen display.

Some rough page could look something like this:

<apex:pageMessages/>
<apex:pageBlock rendered="{!theVariableToggledToFalse}">
  <apex:pageBlockButtons>
    <apex:commandButton action="{!SaveRecord}" value="Save" rerender=""/>
  </apex:pageBlockButtons>
  <apex:pageBlockSection>
    <!-- fields here -->
  </apex:pageBlockSection>
</apex:pageBlock>

Now you could add a new information message to be displayed when you save the record:

ApexPages.addMessage(new ApexPages.pageMessage(ApexPages.SEVERITY.INFO, "Record Saved!"));

Or, redirect them elsewhere via the PageReference returned by your action method.

Note, this code isn't tested, it's just been written in browser!

Reporting Errors From Triggers (old answer)

If you're looking for an alternative to using addError() you can also throw a custom exception, though it's handling by standard pages is less graceful than addError().

First define a new exception class:

public class MyException extends Exception {}

Then throw a new instance of this exception where you want things to grind to a halt:

if(someCondition == false)
{
  throw new MyException("No good!");
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.