Java Code Data Policy Examples/Update the Primary Contact's Address with Account's Address Code Sample

Java Code Data Policy Examples/Update the Primary Contact's Address with Account's Address Code Sample

From LongJump Support Wiki

Java Code Data Policy Examples/Update the Primary Contact's Address with Account's Address Code Sample
Jump to: navigation, search

This code is intended for use as part of a Data Policy. It is a complex example of the use of Java code to take a series of actions, each based on the previous code section. For information on the use of this code sample, see: Update the Primary Contact's Address with Account's Address.

import com.platform.api.*;


public class DataPolicyExamples {

  public void updatePrimaryContactAddress(Parameters requestParams) {
 
    Functions.debug("Updating Contact object address using Accounts address");

    //Get Primary Contact ID FROM UI
    String contactRecId = requestParams.get("primary_contact_id");
    Functions.debug("Account Object contactRecId:" + contactRecId);

    if(contactRecId != "") {
    //Get name of the ACCOUNT, Address
    String accountName = requestParams.get("name");
    String street = requestParams.get("street");
    String city = requestParams.get("city");

    //Create a Parameters instance to add the ACCOUNT record information
    Parameters params = Functions.getParametersInstance();

    params.add("street", street);
    params.add("city", city);
    params.add("description",
               "Updating address of Contact with details from Account");

    //Update CONTACT record associated with the ACCOUNT record
    //with details added to Parameters object
    Result result = Functions.updateRecord("CONTACT", contactRecId, params);
    int resultCode = result.getCode();
    Functions.debug("result of update record"+ result.getCode());
    Functions.debug("Message from Functions.updateRecord(): "+ result.getMessage());
    String msg;
    if(result.getCode() != -1)
    {
      // Take other actions on successful addition of the account
      String attachmentIdList = "";
      String attachmentTemplateIdList = "";
      Functions.debug(
        "After updating CONTACT RECORD - before sending email to CONTACT.");
      Result result1 = Functions.sendEmail("Contact", contactRecId,
                                 "abc@txt.com", "support@abc.com",
        "Testing sendEmail", "Hello, Your CONTACT Address has been updated.",
         attachmentTemplateIdList, attachmentIdList);
      if(result1.getCode() != -1)
        Functions.debug("Done with sending mail from ACCOUNT object.\n"
                       + result1.getMessage());  
      else {
        msg = "Could not send email after CONTACT record got updated.";
        Functions.debug(msg + ":\n" + result1.getMessage());  // Log details
        Functions.throwError(msg + ".");                     // Error dialog
      }
    }
    else
    {
      // Some error happened. Display error message in UI
      msg = "CONTACT could not be updated";
      Functions.debug(msg + ":\n" + result.getMessage());  // Log details
      Functions.throwError(msg + ".");                     // Error dialog
    }  
    }
    else
    {
    Functions.debug("Account is not associated with a contact.\n"
                 +  "Contact object not updated.");
    }
  } // end method
}// end class
Personal tools