Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following examples demonstrate how to make use of the glossary mechanism when defining and throw an exception.

Expand
titleDefining an exception example

1. Create the exception class.

Code Block
languagejava
titleException class
public class OnlyOneRecordException extends CRMValidationException {
 /**
 * Only one %1 %2 must be specified.
 * 
 * @param crmSession - the session object
 * @param value1 - the exception first value
 * @param value2 - the exception second value 
 * @throws Exception
 */
 	public OnlyOneRecordException(CRMSession crmSession, String value1,String value2) throws Exception {
 
 		super();
 
 		ArrayList<String> parameters = new ArrayList<String>();
 
 		parameters.add(value1);
 		parameters.add(value2);
 
		try 
 		{
 			setMessage(this.getClass().getName().toUpperCase(), crmSession, parameters);
 		} 
 		catch (Exception e) 
 		{
 			e.printStackTrace();
 		}
 	}
}

 

2. Define the exception in the messages.xmlfile. Use a unique key for the expression tag. Keys used: key_com_crm_exception_onlyonerecordexception

Code Block
languagexml
titlemessages.xml
<messages>
	<message>
 		<code>COM.CRM.EXCEPTION.ONLYONERECORDEXCEPTION</code>
 		<expression>key_com_crm_exception_onlyonerecordexception</expression>
 		<description>Only one record must be specified.</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.

Code Block
languagexml
titletranslation_eng.properties
<properties>
	<entry key="key_com_crm_exception_onlyonerecordexception">Only one %1 %2 must be specified.</entry>
	.
	.
	.
</properties>

...

This section shows how to use the Glossary Mechanism when defining mandatory while creating business object classes.

Expand
titleMandatory fields example

keys used: key_website

 

Code Block
languagejava
titleCRMBOWebCustomerEventBean
@Override
protected LinkedHashMap<String, String> getMandatoryFields(CRMDO dto) throws Exception {
   		
	LinkedHashMap<String, String> mandatoryFields = new LinkedHashMap<String, String>();
   		
   	mandatoryFields.putAll(super.getMandatoryFields(dto));
   	mandatoryFields.put("key_website", "website");
   	return mandatoryFields;
}