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
Uves RavatUves Ravat 

Error Message

Hi.

 

If anyone can help me that would be great. I want a error message appear on the screen to say project is locked if a variable is true. Below

 

    public void updatingProjectProposalHeader()
    {
        SObject ErrorMessage;
        if (m_ProposalLocked)
        {
           // if its true, i want it to display on the screen that project it locked.
        }
    }

 

if have tried the following code, the error message is very ugly.

 

	public void updatingProjectProposalHeader()
	{
		if (m_ProposalLocked)
		{
			throw new lockProposalException ('Proposal Locked');
		}
	}

	public class lockProposalException extends Exception{}

 Thanks

 

sfdcfoxsfdcfox

You should probably be using addError instead:

 

public void updatingprojectproposalheader() {
  if(m_proposallocked) {
    proposalRecord.addError('This proposal is locked for editing.');
  }
}

(proposalRecord should be the record obtained from the page's standard controller or member variable).

 

When this occurs in a Visualforce page, the error will appear in your page's apex:pagemessages block. If you do this through a trigger, it will appear on the standard page's error header, or as an error message on an API call.

Uves RavatUves Ravat

Hi,

 

I am bit confused on where i get proposalRecord value from

 

Thanks

Uves

sfdcfoxsfdcfox

ProposalRecord is an SObject that is bound to the page. I presumed you had a Visualforce page, in which case it'd look like this:

 

<apex:page standardController="Proposal__c" extensions="ProposalExtension">
  <apex:form>
    <!-- details of the page -->
  </apex:form>
</apex:page>

 The controller looks like this:

 

public with sharing class ProposalExtension {
  apexpages.standardcontroller controller;
  Proposal__c proposalrecord;

  public ProposalExtension(Apexpages.standardcontroller controller) {
    this.controller = controller;
    proposalRecord = (Proposal__c)controller.getrecord();
  }
  // Other page logic here
}