AgileApps Support Wiki Pre Release

getRecord Examples

From AgileApps Support Wiki

Example: Retrieve a Key

This example calls getRecord, assigning the returned value to an instance of Result and calling Result.getCode to assign the error code to a variable which is then conditionally checked to determine the code to execute. If the call was not successful, the code calls throwError to display an error dialog. If the call was successful, the code creates an instance of Parameters from which it then extracts the city key.

String accountID = "";
// Some logic to populate accountID variable.
Result result = Functions.getRecord("ACCOUNT","city,country",accountID);
int resultCode = result.getCode();
if(resultCode != 1)
{
    // Some error happened.
    String msg = "Account could not be retrieved";
    Logger.info(msg + ":\n" + result.getMessage(), "Get Key"); // Log details
    Functions.throwError(msg + ".");                           // Error message
}
else
{
  //Records retrieved successfully
  Parameters resultParameters = result.getParameters();
  String city = resultParameters.get("city");
  // Other code according to your business logic.
}

Example:Access File Data

When a field points to a file, the PlatformFileBean parameter is used to retrieve the file's contents:
Result result = Functions.getRecord( {objectName}, "fieldName,..." , {record_Id} );
Parameters resultParameters = result.getParameters();
PlatformFileBean file= resultParameters.getPlatformFileBean("fieldName");
String content = file.getEncodedFileContent();
Learn more: See the PlatformFileBean javadocs for a complete list of methods.

Example: Access an Audit Log

Audit Logs can be searched using the getRecord and searchRecord APIs
Learn more: Audit Log Fields
How it Works
Provide an audit log recordID to get a single record and retrieve a list of audit log fields.
Syntax
public static Result Functions.getRecord(String objectId, String fields, String recordId)
objectId
log
fields
record_id, ownerid, type, operation, object_singular_name, date_created, description, type_code
recordId
audit log record Id
Return
Result object
Audit Log Example Based on recordID
Result result = Functions.getRecord("log","record_id,type,operation,"+
"object,description","656");

int resultCode = result.getCode();

if(resultCode != 1)
{
    // Some error happened.
    String msg = "Log could not be retrieved";
    Logger.info(msg + ":\n" + result.getMessage(), "Audit"); // Log details
    Functions.throwError(msg + ".");                         // Error message
}
else
{
  //Records retrieved successfully
    Parameters params = result.getParameters();
    String desc= params.get("description");
    String type= params.get("type");
    String obj = params.get("object");
    String record_id = params.get("record_id");
    String operation = params.get("operation");                  

    // Take action according to your business logic
   
}
Learn more: Audit Log Fields