This section describes how error, warning, and question messages are created.
What does this section cover?
Error Messages
In order for an error message to appear on screen, a java exception must be created and thrown.
- Create the Exception class.
All exception classes must extend com.crm.exception.CRMValidationException. All exception methods should have a com.crm.exception.CRMValidationException object as an input parameter and use setMessage method of com.crm.exception.CRMException class
To create the exception method:
- Use com.crm.businessobject.CRMSession object as an input parameter and any other String input parameters needed.
- Put all String input parameters in a String ArrayList.
- Use setMessage method of com.crm.exception.CRMException class to construct the exception message.
public class AccountTerminationException extends CRMValidationException { /** * You are not allowed to terminate the Accounts Receivable %1. This is only allowed for Active or Suspended accounts. * * @param crmSession - the session object * @param value - the exception value * @throws Exception */ public AccountTerminationException(CRMSession crmSession, String value) throws Exception { super(); ArrayList<String> parameters = new ArrayList<String>(); parameters.add(value); try { setMessage(this.getClass().getName().toUpperCase(), crmSession, parameters); } catch (Exception e) { e.printStackTrace(); } } }
2. Define the exception in the messages.xml file. Use a unique key for the expression tag.
<messages> <message> <code>COM.CRM.EXCEPTION.ACCOUNTS.ACCOUNTTERMINATIONEXCEPTION</code> <expression>key_com_crm_exception_accounts_accountterminationexception</expression> <description>You are not allowed to terminate the accounts receivable. This is only allowed for Active or Suspended accounts.</description> </message> . . . </messages>
3. Define the exception in the properties file, by using the expression tag key defined in metadata messages file as the entry key, and specifying the exception message. Use %<number> where the input parameters should be placed. Note that <number> is their index+1 in parameters array list.
<properties> <entry key="key_com_crm_exception_accounts_accountterminationexception">You are not allowed to terminate the accounts receivable %1. This is only allowed for Active or Suspended accounts.</entry> . . . </properties>
Furthermore, the exception message should be defined in message metadata file with caps and the correct datapath as code whilst an expression and a description.
Then, the key expression mentioned above has to create an entry key in the label page and define the exact error message that will be appeared on the screen as follows:
Question Messages
In general, It is important to mention that question messages are implemented exclusively for interfaces. Thus, let see an example of creating a question message for post payments. Firstly, a method named postPaymentButton is constructed to call another method which will show the question message as follows. The nested method parses the class name of the function to be called if the Yes option is chosen. Then it passes the function, the code of the question message as it is defined in the messages metadata file and lastly the parameters of the message.
Later on, we observe below, the method named showConfirmQuestion which is implemented in the CRMUI parent class, where the question object and options are defined and lastly the message is been showed.
Moreover, as in the previous example, the code of the question message must be defined in messages of metadata file whilst the expression key must also be mentioned in labels file as follows:
Below, we can see the scenario with the payment post. The question message appears on the top of the screen and ask you if you want to continue and post the payment.
Warning Messages
The last example is about showing warning messages and as previously the same procedure is been followed. The following example constructing a warning message about the license on its interface class. Firstly, an InfoMessage object is created and some parameters are parsed. The first parameter is the crmSession, second the code of the message, third are some message parameters, then the path of the session and the organization id as follows. Lastly, the showInfoMessage method is called to demonstrates the warning message on the screen by parsing the message details.
Once again, the code of the warning message must be defined in messages of metadata file whilst the expression key must also be mentioned in labels file, as follows.
Then, on the following screen is illustrated the warning message, when a field is been changed.