Difference between revisions of "Java API Cheatsheet"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
 
(28 intermediate revisions by the same user not shown)
Line 81: Line 81:
-->
-->


=== Email and Document Management ===
=== Email ===
[[Java_API:Email_and_Document_Management|Email and Document Management]]
[[Java API:Email]]


:{| border="1" cellpadding="5" cellspacing="0"
:{| border="1" cellpadding="5" cellspacing="0"
Line 90: Line 90:


|-width="150"
|-width="150"
|<tt>[[Java API:Email_and_Document_Management#sendEmail |sendEmail]](String objectName, String id, String to, String cc, String subject, String body, String attachmentTemplateId, String attachmentIdList)</tt>||Sends an Email|| [[Result Class|Result object]]
| <tt>[[Java API:Email#sendEmail |sendEmail]](String objectName, String id, String to, String cc, String subject, String body, String attachmentTemplateId, String attachmentIdList)</tt>
| Send an email
| [[Result Class|Result object]]
|-width="150"
 
| <tt>[[Java API:Email#sendEmail |sendEmail]](String objectName, String id, String to, String cc, String bcc, String subject, String body, String attachmentTemplateId, String attachmentIdList)</tt>
| Send an email with a bcc list
| [[Result Class|Result object]]
 
|-width="150"
| <tt>[[Java API:Email#sendEmail |sendEmail]](String objectName, String id, String to, String cc, String subject, String body, String attachmentTemplateId, String attachmentIdList, TenantContext context)</tt>
| Send an email with tenant context
| [[Result Class|Result object]]
 
|-width="150"
| <tt>[[Java API:Email#sendEmail |sendEmail]](String objectName, String recordid, String to, String cc, String bcc, String subject, String body, String attachmentTemplateId, String attachmentIdList, String fromName, String fromAddress)</tt>
| Send an email with bcc list, from name, and from address
| [[Result Class|Result object]]
 
|-
|-
|<tt>[[Java_API:Email_and_Document_Management#sendEmailUsingTemplate|sendEmailUsingTemplate]](String objectName, String recordId, String to, String cc, String subject, String bodyTemplateId, String attachmentTemplateId, String attachmentIdList)</tt>||Sends an Email evaluating Template identified by bodyTemplateId as email body|| [[Result Class|Result object]]
| <tt>[[Java_API:Email#sendEmailUsingTemplate|sendEmailUsingTemplate]](String objectName, String recordId, String to, String cc, String subject, String bodyTemplateId, String attachmentTemplateId, String attachmentIdList)</tt>
| Send an email evaluating Template identified by bodyTemplateId as email body
| [[Result Class|Result object]]


|-
|-
|<tt>[[Java API:Email_and_Document_Management#generateDocument |generateDocument]](String objectName, String recordId, String templateId, String format)</tt>||Generates document of templateId evaluated with params in format. If format is "PDF" it generates the document in PDF format, otherwise HTML format. It relates this generated document to object of type objectId and record with id recordId|| [[Result Class|Result object]]
| <tt>[[Java_API:Email#sendEmailUsingTemplate|sendEmailUsingTemplate]](String objectName, String recordId, String to, String cc, String bcc, String subject, String bodyTemplateId, String attachmentTemplateId, String attachmentIdList)</tt>
| Send an email using Template with bcc list
| [[Result Class|Result object]]
 
|-
| <tt>[[Java_API:Email#sendEmailUsingTemplate|sendEmailUsingTemplate]](String objectName, String recordId, String to, String cc, String bcc, String subject, String bodyTemplateId, String attachmentTemplateId, String attachmentIdList, String fromName, String fromAddress)</tt>
| Send an email using Template with bcc list, from name, and from address
| [[Result Class|Result object]]
|}
|}


<!--
=== Document Management ===
=== Email Handler APIs ===
[[Java API:Document Management]]
 
:{| border="1" cellpadding="5" cellspacing="0"
:{| border="1" cellpadding="5" cellspacing="0"
!API
!Syntax
!Description
!Description
!Return
|-
|-
| [{{DOCHOST}}/javadocs/com/platform/api/mail/EmailHandler.html <tt>EmailHandler</tt> interface]
| <tt>[[Java API:Document Management#generateDocument |generateDocument]](String objectName, String recordId, String templateId, String format)</tt>
| Specifies the <tt>processEmail</tt> method you define to handle incoming email messages. That method gets the incoming email in the form of an <tt>Email</tt> object (After creating the handler class, you specify it as the email handler in the [[External Email Tracking]] settings.)
| Generates document of using the specified template, in the specified format (PDF or HTML), using the specified object and record to populate template variables. Returns the ID of the generated document in the Result object.
| [[Result Class|Result]]


|-
|-
| [{{DOCHOST}}/javadocs/com/platform/api/mail/Email.html <tt>Email</tt> class]
| <tt>[[Java API:Document Management#getDocument |getDocument]](String documentId)</tt>
| This object contains the incoming email. It has methods to get the subject line, lists of recipients, and get attachments.
| Gets a document identified by its ID, in the form of a {{^PlatformFileBean}} contained in the Result.
| [[Result Class|Result]]


|-
|-
| [{{DOCHOST}}/javadocs/com/platform/api/mail/Attachment.html <tt>Attachment</tt> class]
| [[Java API:Document Management#Example:_Generate_an_Attachment|Example: Generate an Attachment]]
| Attachments that come with an email are wrapped in an <tt>Attachment</tt> object. Before it can be used, the content of the attachment must be decoded using the <tt>Base64Codec</tt> class.
| colspan="2"| Shows how to generate a document and attach it to the current record.


|-
| [{{DOCHOST}}/javadocs/com/platform/api/utility/Base64Codec <tt>Base64Codec</tt>] class
| An instance of this class is created and used to decode an incoming <tt>Attachment</tt>.
|}
|}
:''Learn more:'' [[HowTo:Handle Incoming Emails Programmatically]]
-->


=== Transaction Management ===
=== Transaction Management ===
Line 154: Line 181:
!Description
!Description
|-
|-
| [{{DOCHOST}}/javadocs/com/platform/api/Logger.html#info(java.lang.Object,%20java.lang.Object) <tt>info(String message,&nbsp;String msgType)</tt>]
| <tt>[[Java API:Utility functions#Logger Functions|info]](String msg, String msgType)</tt>
| Log an information message. This is the default display level in the [[Debug Log]]. This level is appropriate for most application debugging.
| Log an information message. This is the default display level in the [[Debug Log]].<br>This level is appropriate for most application debugging.


|-
|-
| [{{DOCHOST}}/javadocs/com/platform/api/Logger.html#warn(java.lang.Object,%20java.lang.Object) <tt>warn(String message, String msgType)</tt>]
| <tt>[[Java API:Utility functions#Logger Functions|warn]](String msg, String msgType)</tt>
| Log a warning.
| Log a warning.


|-
|-
| [{{DOCHOST}}/javadocs/com/platform/api/Logger.html#error(java.lang.Object,%20java.lang.Object) <tt>error(String message, String msgType)</tt>]
| <tt>[[Java API:Utility functions#Logger Functions|error]](String&nbsp;msg,&nbsp;String&nbsp;msgType)</tt>
| Log an error message.
| Log an error message.


|-
|-
| [{{DOCHOST}}/javadocs/com/platform/api/Logger.html#fatal(java.lang.Object,%20java.lang.Object) <tt>fatal(String message, String msgType)</tt>]
| <tt>[[Java API:Utility functions#Logger Functions|fatal]](String msg, String msgType)</tt>
| Log a fatal error.
| Log a fatal error.
|}
|}
Line 181: Line 208:
| Format a value specified in [[Database Format]] with no currency character and no grouping indicators (commas), and with a decimal point for fractional amounts.
| Format a value specified in [[Database Format]] with no currency character and no grouping indicators (commas), and with a decimal point for fractional amounts.
| Return a String with the value formatted using the company's locale setting for currencies, with the number of decimal places specified for the <tt>precision</tt>. If the conversion fails, return the original string.
| Return a String with the value formatted using the company's locale setting for currencies, with the number of decimal places specified for the <tt>precision</tt>. If the conversion fails, return the original string.
|-
| [{{DOCHOST}}/javadocs/com/platform/api/Functions.html#formatDate(java.util.Date) <tt>formatDate(Date d)</tt>]
| Format a date/time value.
| Return a String with the date formatted according the user's settings.
|-
| [{{DOCHOST}}/javadocs/com/platform/api/Functions.html#formatDateTime(java.util.Date) <tt>formatDateTime(Date d)</tt>]
| Format a date/time value.
| Return a String with the date formatted according the user's settings, and time formatted using the user's locale.


|-
|-
Line 191: Line 228:
| Format a value specified in [[Database Format]] with no percent sign, no grouping indicators (commas), and with a decimal point for fractional amounts.
| Format a value specified in [[Database Format]] with no percent sign, no grouping indicators (commas), and with a decimal point for fractional amounts.
| Return a String with the value formatted using the user's locale, with the number of decimal places specified for the <tt>precision</tt>. If the conversion fails, return the original string.
| Return a String with the value formatted using the user's locale, with the number of decimal places specified for the <tt>precision</tt>. If the conversion fails, return the original string.
|-
| [{{DOCHOST}}/javadocs/com/platform/api/Functions.html#formatTime(java.util.Date) <tt>formatTime(Date d)</tt>]
| Format a time value.
| Return a String with the time formatted using the user's locale.


|-
|-
Line 240: Line 282:


|-
|-
|<tt>[[Java_API:Utility functions#showMessage|showMessage]](long millisecs)</tt>||Displays message|| None
|<tt>[[Java_API:Utility functions#showMessage|showMessage]](String message)</tt>||Displays message|| None


|-
|-
|<tt>[[Java_API:Utility functions#sleep|sleep]](String message)</tt>||Sleeps for the designated number of milliseconds.|| None  
|<tt>[[Java_API:Utility functions#sleep|sleep]](long millisecs)</tt>||Sleeps for the designated number of milliseconds.|| None  
|-
|-
|<tt>[[Java_API:Utility functions#throwError|throwError]](String message)</tt>||Throws error with the message|| None
|<tt>[[Java_API:Utility functions#throwError|throwError]](String message)</tt>||Throws error with the message|| None

Latest revision as of 09:38, 26 September 2016

These APIs are defined in the Functions class.

Record Handling

Standard Objects

Record Handling APIs

Syntax Description Return
addRecord(String objectName, Params params) Adds a new record of type objectId with values from params Result object
updateRecord(String objectName, String recordId, Params params) Updates record of type objectId with values params. The Record is identified by recordId Result object
changeOwnerShipInfo(String object_id, String record_id, String owner_id) Changes the owner of the designated record None
deleteRecord(String objectName, String recordId) Deletes Record of type objectId where id is recordId Result object
getRecord(String objectName, String fields, String recordId) Gets the record of type objectId identified by recordId. fields is a comma separated list of fields that you want to fetch Result object
getRecordCount(String objectName, String criteria) Returns the number of records in the object int
searchRecords(String objectName, String fields, String criteria [, Parameters params]) Search and retrieve the records for an object. fields is a comma-separated list of fields to fetch. criteria is a Filter Expression Result object
searchRecords(String objectName, String fields, String criteria, String sortBy, String sortOrder, String sortBy2, String sortOrder2, int offset, int numberOfRows [, Parameters params]) Search and retrieve records for an object. fields is a comma-separated list of fields to fetch. criteria is a Filter Expression Result object
execSQL(String query) Execute a SQL query Result object


Composite Objects

Composite Object APIs

Syntax Description Return
getRecord(String compositeObject, String fields, String recordId) Get a Composite Object record, with specified fields. Result object
getRecordCount(String compositeObject, String criteria) Gets a count of records in a Composite Object that match specified filtering criteria. int
searchRecords(String compositeObject, String fields, String criteria [, Parameters params]) Search and retrieve Composite Object records. fields is a comma-separated list of fields to fetch. criteria is a Filter Expression Result object
searchRecords(String compositeObject, String fields, String criteria, String sortBy, String sortOrder, String sortBy2, String sortOrder2, int offset, int numberOfRows [, Parameters params]) Search and retrieve Composite Object records. fields is a comma-separated list of fields to fetch. criteria is a Filter Expression Result object


Email

Java API:Email

Syntax Description Return
sendEmail(String objectName, String id, String to, String cc, String subject, String body, String attachmentTemplateId, String attachmentIdList) Send an email Result object
sendEmail(String objectName, String id, String to, String cc, String bcc, String subject, String body, String attachmentTemplateId, String attachmentIdList) Send an email with a bcc list Result object
sendEmail(String objectName, String id, String to, String cc, String subject, String body, String attachmentTemplateId, String attachmentIdList, TenantContext context) Send an email with tenant context Result object
sendEmail(String objectName, String recordid, String to, String cc, String bcc, String subject, String body, String attachmentTemplateId, String attachmentIdList, String fromName, String fromAddress) Send an email with bcc list, from name, and from address Result object
sendEmailUsingTemplate(String objectName, String recordId, String to, String cc, String subject, String bodyTemplateId, String attachmentTemplateId, String attachmentIdList) Send an email evaluating Template identified by bodyTemplateId as email body Result object
sendEmailUsingTemplate(String objectName, String recordId, String to, String cc, String bcc, String subject, String bodyTemplateId, String attachmentTemplateId, String attachmentIdList) Send an email using Template with bcc list Result object
sendEmailUsingTemplate(String objectName, String recordId, String to, String cc, String bcc, String subject, String bodyTemplateId, String attachmentTemplateId, String attachmentIdList, String fromName, String fromAddress) Send an email using Template with bcc list, from name, and from address Result object

Document Management

Java API:Document Management

Syntax Description Return
generateDocument(String objectName, String recordId, String templateId, String format) Generates document of using the specified template, in the specified format (PDF or HTML), using the specified object and record to populate template variables. Returns the ID of the generated document in the Result object. Result
getDocument(String documentId) Gets a document identified by its ID, in the form of a PlatformFileBean contained in the Result. Result
Example: Generate an Attachment Shows how to generate a document and attach it to the current record.

Transaction Management

Utility functions

Syntax Description Return
addSavePoint(String name) Adds a Save Point with name None
doesSavePointExist(String name) checks whether the named save point exists or not Boolean
getAllSavePoints() Returns All Save Points Set
rollback() Roll backs all the inserts and updates None
rollbackToSavePoint(String name) Rollback to specific save point with name None
removeSavePoint(String name) removes save point with name from save point list None

Logger Functions

Logger class (static methods):

Syntax Description
info(String msg, String msgType) Log an information message. This is the default display level in the Debug Log.
This level is appropriate for most application debugging.
warn(String msg, String msgType) Log a warning.
error(String msg, String msgType) Log an error message.
fatal(String msg, String msgType) Log a fatal error.

Localization Functions

Functions class (static methods):

Syntax Description Return
formatCurrency(String value, int precision) Format a value specified in Database Format with no currency character and no grouping indicators (commas), and with a decimal point for fractional amounts. Return a String with the value formatted using the company's locale setting for currencies, with the number of decimal places specified for the precision. If the conversion fails, return the original string.
formatDate(Date d) Format a date/time value. Return a String with the date formatted according the user's settings.
formatDateTime(Date d) Format a date/time value. Return a String with the date formatted according the user's settings, and time formatted using the user's locale.
formatNumber(String value, int precision) Format a value specified in Database Format with no grouping indicators (commas), with a decimal point for fractional amounts. Return a String with the value formatted using the user's locale, with the number of decimal places specified for the precision. If the conversion fails, return the original string.
formatPercent(String value, int precision) Format a value specified in Database Format with no percent sign, no grouping indicators (commas), and with a decimal point for fractional amounts. Return a String with the value formatted using the user's locale, with the number of decimal places specified for the precision. If the conversion fails, return the original string.
formatTime(Date d) Format a time value. Return a String with the time formatted using the user's locale.
parseCurrency(String value) Parse a currency amount in the format specified by the company's locale setting for currencies. Return a String in Database Format format. If parsing fails, return the original string.
parseNumber(String value) Parse a numeric amount (with or without a fractional amount) in the format specified by the user's locale. Return a String in Database Format format. If parsing fails, return the original string.
parsePercent(String value) Parse a percentage in the format specified by the user's locale. Return a String in Database Format format. If parsing fails, return the original string.
validateCurrency(String value) Verify that the currency amount is in the format specified by the company's locale setting for currencies. Return true if the data is in the expected format, otherwise false.
validateNumber(String value) Verify that the numeric amount (with or without a fractional amount) is in the format specified by the user's locale. Return true if the data is in the expected format, otherwise false.
validatePercent(String value) Verify that the percentage is in the format specified by the user's locale. Return true if the data is in the expected format, otherwise false.

Utility Functions

Static Utility functions in the Functions class:

Syntax Description Return
getEnv(String key) Gets the environment variable value for the key The value of the environment variable
getParametersInstance() Gets an instance of Parameters class Parameters object
setTargetPage(String url) Sets the target page None
showMessage(String message) Displays message None
sleep(long millisecs) Sleeps for the designated number of milliseconds. None
throwError(String message) Throws error with the message None


ServiceConfiguration class (static methods):

Syntax Return Type Description
getServiceName() String Returns the Service Name (e.g. company name)
getServiceDomainURL() String Returns the Service URL.

Metadata Management

Customization methods.

Learn more: Java_API:Customize
Syntax Description Return
getObjectMetaData(String objectName) Retrieve metadata from a Custom Objects. CustomObjectMetaDataBean
getObjectMetaDataMap() Return a map of all visible Custom Object object metadata records, indexed by object ID. Map: Object ID => CustomObjectMetaDataBean
addObjectMetaData(CustomObjectMetaDataBean) Create a new object. String:Object ID
updateObjectMetaData(CustomObjectMetaDataBean) Modify an object definition. String: Object ID
deleteObjectMetaData(CustomObjectMetaDataBean) Deletes an object None
getRecordLocator(String objectName) Get an object's Record Locator information. RecordLocatorBean
updateRecordLocator(RecordLocatorBean) Modify an object's Record Locator Settings. String:Object ID