Java Code Data Policy Examples/Add Contact On Importing Prospect Records Code Sample

Java Code Data Policy Examples/Add Contact On Importing Prospect Records Code Sample

From LongJump Support Wiki

Java Code Data Policy Examples/Add Contact On Importing Prospect Records 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: Add Contact On Importing Prospect Records.

import com.platform.api.*;


public class DataPolicyExamples {

  public void addContact(Parameters requestParams) {
    Parameters params = Functions.getParametersInstance();
    params.add("first_name", "John");
    params.add("last_name", "Smith");
   
    //In order to relate the above contact to a specific prospect that is being
    //added, the following key value pairs need to be added to the params object
    // before calling the addRecord API.
    //You need to retrieve the record ID of the prospect to which this contact
    //has to be related.
    //Populate the following variable - prospectRecordAdded with the record ID
    //of the prospect that has been added.
    String prospectRecordAdded = "";
    params.add("account_id", prospectRecordAdded);
    //Relating the contact being added to PROSPECT
    params.add("reference_type", "LEAD");
    //reference_id key should have prospect record to which the new contact
    //will be related
    params.add("reference_id", prospectRecordAdded);
    //record locator value should be specified in reference_id_name key-value pair
    //For example, if the name of the prospect is 'Hello World Prospect' and
    //the record locator is the name of the prospect
    params.add("reference_id_name", "Hello World Prospect");
    Result contactAddResult = Functions.addRecord("CONTACT", params);
    Functions.debug("Result of addRecord for Contact:"
                   + contactAddResult.getMessage());
    if(contactAddResult.getCode() < 0)
    {
         //Throw error if the addRecord fails.
         //On Error the import action that triggered this policy will error out
        String msg = "Import Trigger: Error adding Contact";
        Functions.debug(msg + ":\n" + contactAddResult.getMessage());  // Log details
        Functions.throwError(msg + ".");                     // Error dialog
    }
    else
    {
     //Add further logic here
     Functions.debug("ID of the contact record added:" + contactAddResult.getID());
    }
  } // end method
}// end class
Personal tools