Java Code Data Policy Examples/Convert a Prospect to Account, Triggered by an Add Code Sample

Java Code Data Policy Examples/Convert a Prospect to Account, Triggered by an Add Code Sample

From LongJump Support Wiki

Java Code Data Policy Examples/Convert a Prospect to Account, Triggered by an Add 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: Convert a Prospect to Account, Triggered by an Add.

import com.platform.api.*;


public class DataPolicyExamples {

  public void convertProspectToAccount(Parameters requestParams) {
    Functions.debug("Starting Convert Prospect To Account Action.");

    //Get field details of the record using requestParams object
    String prospectName = requestParams.get("name");
    String street = requestParams.get("street");
    String city = requestParams.get("city");
    String state = requestParams.get("state");

    //Create a parameter instance
    Parameters params = Functions.getParametersInstance();
     
    //Add the field details retrieved from the record to params object
    params.add("name", prospectName);
    params.add("number", prospectName + "- ConvertedToAccount");
    params.add("street", street);
    params.add("city", city);
    params.add("state", state);

    //Add the record to ACCOUNT object
    Result result = Functions.addRecord("ACCOUNT", params);

    Functions.debug(" Result message for addRecord is " + result.getMessage());
    Functions.debug(" Result code is " + result.getCode());

    if(result.getCode() < 0) {
      // Some error happened.
      String msg = ""Account record for the " + prospectName + "could not be added";
      Functions.debug(msg + "
:\n" + result.getMessage());  // Log details
      Functions.throwError(msg + "
.");                     // Error dialog
    } else {
      String recordId = result.getID();
      Functions.debug("
Record ID after: " + recordId);
      requestParams.add("
converted_to_account_id", recordId);
      requestParams.add("
stage", "Converted To Account");
      Functions.debug("
Done with Convert To Account.");
    }
  } // end method
}// end class
Personal tools