AgileApps Support Wiki Pre Release

Difference between revisions of "UpdateRecord"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
 
(15 intermediate revisions by the same user not shown)
Line 3: Line 3:
;Syntax:
;Syntax:
:<syntaxhighlight lang="java" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
Result result = Functions.updateRecord(String objectID, String recordID, Parameters params);
Result result = Functions.updateRecord(String objectName, String recordID, Parameters params);
</syntaxhighlight>
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
:;objectID:The identifier of the object
:;objectName:The identifier of the object


:;recordID:The identifier of the record to update.  
:;recordID:The identifier of the record to update.  
Line 15: Line 15:
:;params:
:;params:
::* The field-value pairs for the object.
::* The field-value pairs for the object.
::* Data policy override parameter:
::* Turn off rules that might otherwise be triggered as a result of this action:
:::<syntaxhighlight lang="java" enclose="div">
:::<syntaxhighlight lang="java" enclose="div">
params.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_DATA_POLICY,"1");
params.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_RULES,"1");
</syntaxhighlight>
::* Pass file parameters in the current request to any subsequent API calls made in a data policy defined on this object:
:::<syntaxhighlight lang="java" enclose="div">
params.add(PLATFORM.PARAMS.RECORD.ENABLE_MULTIPART,"1");
</syntaxhighlight>
</syntaxhighlight>


Line 25: Line 29:


====Example #1: Update an Account Record ====
====Example #1: Update an Account Record ====
This example creates an instance of <tt>Parameters</tt> and adds name-values pairs to it. The code then calls <tt>updateRecord</tt>, assigning the returned value to an instance of <tt>Result</tt> and calling <tt>Result.getCode</tt> 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 <tt>[[throwError]]</tt> to display an error dialog.
This example creates an instance of <tt>Parameters</tt> and adds name-values pairs to it. The code then calls <tt>updateRecord</tt>, assigning the returned value to an instance of <tt>Result</tt> and calling <tt>Result.getCode()</tt> 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 <tt>[[throwError]]</tt> to display an error dialog.


:<syntaxhighlight lang="java" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
Line 39: Line 43:
     // Some error happened.
     // Some error happened.
     String msg = "Account could not be updated";
     String msg = "Account could not be updated";
     Functions.debug(msg + ":\n" + result.getMessage()); // Log details
     Logger.info(msg + ":\n" + result.getMessage(), "Accounts"); // Log details
     Functions.throwError(msg + ".");                     // Error dialog
     Functions.throwError(msg + ".");                           // Error message
}
}
else  
else  
Line 48: Line 52:
</syntaxhighlight>
</syntaxhighlight>


====Example #2: Update a "Related To" Field in an Opportunity Record====
====Example #2: Update a Record with a Multi Object Lookup field====
This example gets needed details to update the Opportunity object's <tt>Related To</tt> field. In order to update opportunity object's <tt>Related to</tt> field to be Account or Prospect, you need to use both of these fields:  <tt>related_to_id</tt> and <tt>related_to_type</tt>
 
:<syntaxhighlight lang="java" enclose="div">
//Retrieve the record ID of the ACCOUNT that you want to relate to the current opportunity
String accountID = "";
 
//Use either requestParams or functionParams to retrieve the record_id of the Opportunity record to update
String opportunityID = "";
 
//Create an instance of the Paramters object to hold the key-value pairs to update the record with
Parameters oppParams = Functions.getParametersInstance();
 
oppParams.add("related_to_id", accountID);
oppParams.add("related_to_type", "ACCOUNT"); 
Result opportunityUpdateResult = Functions.updateRecord("OPPORTUNITY_v2", opportunityID, oppParams);
Functions.debug("Result from opportunity update: " + opportunityUpdateResult.getMessage());
 
</syntaxhighlight>
 
====Example #3: Update a Record to Change Ownership====
Use the <tt>updateRecord</tt> API to change the owner of a record. Behavior of this API is the same as changing [[Record Owners]] via the UI.
:<syntaxhighlight lang="java" enclose="div">
Parameters params = Functions.getParametersInstance();
params.add("owner_id","12138534646");
Result result = Functions.updateRecord(requestParams.get("object_id"),requestParams.get("record_id"),params);
Functions.debug("Result code and Message:"+result.getCode()+":"+result.getMessage());
</syntaxhighlight>
 
====Example #4: Update a Record with a Multi Object Lookup field====
This example uses the same fields and record IDs as those shown when adding a record with a multiobject lookup field.
This example uses the same fields and record IDs as those shown when adding a record with a multiobject lookup field.
:<syntaxhighlight lang="java" enclose="div">
:<syntaxhighlight lang="java" enclose="div">
Line 83: Line 58:
String bookID = "117645552"
String bookID = "117645552"
params.add("title", "Another Good Book");  
params.add("title", "Another Good Book");  
params.add("libraryBook", "e5fadf228160483b81ea8d84c71259c9:767645492");
params.add("libraryBook", "9978946545:767645492");
                                    //  {library_object_id}:{record_id}
                      //  {object_id}:{record_id}
Result result = Functions.updateRecord("Books", bookID, params);  
Result result = Functions.updateRecord("Books", bookID, params);  
int resultCode = result.getCode();
int resultCode = result.getCode();
Line 91: Line 66:
     // Some error happened.
     // Some error happened.
     String msg = "Book record could not be updated";
     String msg = "Book record could not be updated";
     Functions.debug(msg + ":\n" + result.getMessage()); // Log details
     Logger.info(msg + ":\n" + result.getMessage(), "Library"); // Log details
     Functions.throwError(msg + ".");                     // Error dialog
     Functions.throwError(msg + ".");                           // Error message
}
}
else
else

Latest revision as of 22:41, 10 September 2013


Syntax
<syntaxhighlight lang="java" enclose="div">

Result result = Functions.updateRecord(String objectName, String recordID, Parameters params); </syntaxhighlight>

Parameters

objectName
The identifier of the object
recordID
The identifier of the record to update.
  • Use the searchRecords API to retrieve the record ID
  • An error is returned if the record is not found.
params
  • The field-value pairs for the object.
  • Turn off rules that might otherwise be triggered as a result of this action:
<syntaxhighlight lang="java" enclose="div">

params.add(PLATFORM.PARAMS.RECORD.DO_NOT_EXEC_RULES,"1"); </syntaxhighlight>

  • Pass file parameters in the current request to any subsequent API calls made in a data policy defined on this object:
<syntaxhighlight lang="java" enclose="div">

params.add(PLATFORM.PARAMS.RECORD.ENABLE_MULTIPART,"1"); </syntaxhighlight>

Return

Result object

Example #1: Update an Account Record

This example creates an instance of Parameters and adds name-values pairs to it. The code then calls updateRecord, 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.

<syntaxhighlight lang="java" enclose="div">

Parameters params = Functions.getParametersInstance(); String accountID = ""; // Some logic to populate accountID variable. params.add("name", "Acme Solutions"); params.add("number", "GRG2323339"); Result result = Functions.updateRecord("ACCOUNT", accountID, params); int resultCode = result.getCode(); if(resultCode < 0) {

   // Some error happened.
   String msg = "Account could not be updated";
   Logger.info(msg + ":\n" + result.getMessage(), "Accounts"); // Log details
   Functions.throwError(msg + ".");                            // Error message

} else {

   // Take other actions after successful addition of the account.

} </syntaxhighlight>

Example #2: Update a Record with a Multi Object Lookup field

This example uses the same fields and record IDs as those shown when adding a record with a multiobject lookup field.

<syntaxhighlight lang="java" enclose="div">

Parameters params = Functions.getParametersInstance(); String bookID = "117645552" params.add("title", "Another Good Book"); params.add("libraryBook", "9978946545:767645492");

                     //  {object_id}:{record_id}

Result result = Functions.updateRecord("Books", bookID, params); int resultCode = result.getCode(); if(resultCode < 0) {

   // Some error happened.
   String msg = "Book record could not be updated";
   Logger.info(msg + ":\n" + result.getMessage(), "Library"); // Log details
   Functions.throwError(msg + ".");                           // Error message

} else {

   // Successful update. Take other actions, as needed.

} </syntaxhighlight>