8.1.5 How to create / update data in ADvendio using your integration application

Sometimes you may want to build your own integration application to create or update data in ADvendio. The ADvendio itself is an application based on Salesforce platform, there are number of ways that your application can use to communicate with ADvendio. They are:

  • Using SOAP enterprise / partner service
  • Using REST service
  • Using BULK service

Each service has its advantages and disadvantages / limitations. For detailed information please refer following Salesforce documentations:

Following example Java code demonstrates how to use the SOAP partner service to create or update a data in object Adserver ID, Key and Value of ADvendio. To generate a Java library using Salesforce Partner WSDL, please refer Introduction to the Force.com Web Services Connector, there you can find example code how to login into ADvendio. The example code below just shows how to create or update data in ADvendio.

Before that, you must first know how the data model Adserver ID, Key and Value are defined in ADvendio.

The object Adserver ID, its API name is ADvendio__AdServer_ID__c, has following fields that will be set in the example:

Field API NameData Type
NameText(80)
RecordTypeIdLookup(RecordType)
ADvendio__Active__cCheckbox
ADvendio__AdServer_ID__cNumber(18, 0) (External ID)
ADvendio__AdServer_Login__cLookup(AdServer Login)
ADvendio__AdServer_Name__cText(255)
ADvendio__Category__cPicklist
ADvendio__Status__cPicklist
ADvendio__Type__cPicklist
ADvendio__UniqueKey__cText(255) (External ID) (Unique Case Insensitive)

The object Key, its API name is ADvendio__Key__c, has following fields that will be set in the example:

Field API NameData Type
NameText(80)
ADvendio__Active__cCheckbox
ADvendio__AdServerId__cMaster-Detail(AdServer ID)
ADvendio__Predefined__cCheckbox
ADvendio__UniqueKey__cText(255) (External ID) (Unique Case Insensitive)

The object Value, its API name is ADvendio__Value__c, has following fields that will be set in the example:

Field API NameData Type
NameText(80)
ADvendio__Active__cCheckbox
ADvendio__AdServerId__cLookup(AdServer ID)
ADvendio__Key__cMaster-Detail(Key)
ADvendio__UniqueKey__cText(255) (External ID) (Unique Case Insensitive)


According to the data model, a record of type Key requires a record of type AdServer ID. A record of type Value requires a record of type Key, and it has a field pointing to a record of type AdServer ID too.

Assume you want to create or update a key and a value in ADvendio, the property of them are:

  • For Key:
    • Name:  "An Example-Key"
    • ID: 12345
  • For Value of the Key:
    • Name: "An Example-Value"
    • ID: 54321

In addition, both key and value are assumed from an ad-server DFP defined as a record of "AdServer Login" in ADvendio, the Salesforce record ID of this "AdServer Login" is "a0AA000000yqsnXAQ" – in Salesforce 18 digits ID format.

Furthermore, the ID of RecordType with name DFP of object AdServer ID is known, e.g. "012A00000012g4AIAQ"  – in Salesforce 18 digits ID format.

The pseudo code to create or update the key and the value is as follows:

Java example code snippet to create or update a key an value
public void createOrUpdateKey() {
  try {
      // Create an sObject of type ADvendio__AdServer_ID__c
      SObject anAdServerId = new SObject();
      anAdServerId.setType("ADvendio__AdServer_ID__c");
      
      // Set the Name to key name. In our example it is given in assumption. 
      anAdServerId.setField("Name", "An Example-Key");
      // Set the RecordTypeId to ID of RecordType with name DFP of object AdServer ID. In our example it is given in assumption. 
      anAdServerId.setField("RecordTypeId", "012A00000012g4AIAQ");
      // Set the ADvendio__Active__c to true.
      anAdServerId.setField("ADvendio__Active__c", true);
      // Set the ADvendio__AdServer_ID__c to key ID. In our example it is given in assumption.
      anAdServerId.setField("ADvendio__AdServer_ID__c", 12345);
      // Set the ADvendio__AdServer_Login__c to the ID of record of ad-server DFP. In our example it is given in assumption. 
      anAdServerId.setField("ADvendio__AdServer_Login__c", "a0AA000000yqsnXMAQ");
      // Set the ADvendio__AdServer_Name__c to key name. In our example it is given in assumption. 
      anAdServerId.setField("ADvendio__AdServer_Name__c", "An Example-Key");
      // Set the ADvendio__Category__c to "Key-values" which is fix definition of ADvendio.
      anAdServerId.setField("ADvendio__Category__c", "Key-values");
      // Set the ADvendio__Status__c to the correspond value assigned to the key in ad-server if there is.
      // Allowed is one of "Active", "Inactive", "Archived" or "Deleted".
      anAdServerId.setField("ADvendio__Status__c", "Active");
      // Set the ADvendio__Type__c to the "Key" which is fix definition of ADvendio.
      anAdServerId.setField("ADvendio__Type__c", "Key");
      // Set the ADvendio__UniqueKey__c to a fixed format defined in ADvendio.
      // It is a string concatenation: ID of record of ad-server + "|" + "Key" + "|" + key ID
      anAdServerId.setField("ADvendio__UniqueKey__c", "a0AA000000yqsnXMAQ|Key|12345");

      // Create or update the ADvendio__AdServer_ID__c, using the upsert method.
      // The unique key for upsert is ADvendio__UniqueKey__c.
      UpsertResult[] upsertResults = partnerConnection.upsert(
         "ADvendio__UniqueKey__c"
         new SObject[] {anAdServerId}
      );

      // Iterate through the results, check the possible error
      for (int j = 0; j < upsertResults.length; j++) {
          System.out.println("\nItem: " + j);
          if (upsertResults[j].isSuccess()) {
              System.out.println("ADvendio__AdServer_ID__c with an ID of " + upsertResults[j].getId() + " was created/updated.");
          }
          else {                        
            // There were errors during the upset call,
            // go through the errors array and write
            // them to the console.
            for (int i = 0; i < upsertResults[j].getErrors().length; i++) {
              Error err = upsertResults[j].getErrors()[i];
              System.out.println("Errors were found on item " + j);
              System.out.println("Error code: " + err.getStatusCode().toString());
              System.out.println("Error message: " + err.getMessage());
            }
          }      
      }

      // Your additional error handler here.

      // Create an sObject of type ADvendio__Key__c
      SObject aKey = new SObject();
      aKey.setType("ADvendio__Key__c");
      
      // Set the Name to key name. In our example it is given in assumption. 
      aKey.setField("Name", "An Example-Key");
      // Set the ADvendio__Active__c to true.
      aKey.setField("ADvendio__Active__c", true);
      // Set the ADvendio__Predefined__c to the correspond value assigned to the key in ad-server if there is.
      aKey.setField("ADvendio__Predefined__c", false);
      // Set the ADvendio__UniqueKey__c to a fixed format defined in ADvendio.
      // It is a string concatenation: ID of record of ad-server + "|" + key ID
      aKey.setField("ADvendio__UniqueKey__c", "a0AA000000yqsnXMAQ|12345");
      // Set the ADvendio__AdServerId__c to the one created/updated above. Here we use the unique key of that record.
      anAdServerId = new SObject();
      anAdServerId.setType("ADvendio__AdServer_ID__c");
      anAdServerId.setField("ADvendio__UniqueKey__c", "a0AA000000yqsnXMAQ|Key|12345");
      aKey.setField("ADvendio__AdServerId__r", anAdServerId);  // Attention: the first parameter is ADvendio__AdServerId__r, not ADvendio__AdServerId__c.

      // Create or update the ADvendio__Key__c, using the upsert method.
      // The unique key for upsert is ADvendio__UniqueKey__c.
      upsertResults = partnerConnection.upsert(
         "ADvendio__UniqueKey__c"
         new SObject[] {aKey}
      );

      // Iterate through the results, check the possible error
      for (int j = 0; j < upsertResults.length; j++) {
          System.out.println("\nItem: " + j);
          if (upsertResults[j].isSuccess()) {
              System.out.println("ADvendio__Key__c with an ID of " + upsertResults[j].getId() + " was created/updated.");
          }
          else {                        
            // There were errors during the upset call,
            // go through the errors array and write
            // them to the console.
            for (int i = 0; i < upsertResults[j].getErrors().length; i++) {
              Error err = upsertResults[j].getErrors()[i];
              System.out.println("Errors were found on item " + j);
              System.out.println("Error code: " + err.getStatusCode().toString());
              System.out.println("Error message: " + err.getMessage());
            }
          }      
      }

      // Your additional error handler here.
  } catch (ConnectionException ce) {
      ce.printStackTrace();
  }
}

public void createOrUpdateValue() {
  try {
      // Create an sObject of type ADvendio__AdServer_ID__c
      SObject anAdServerId = new SObject();
      anAdServerId.setType("ADvendio__AdServer_ID__c");
      
      // Set the Name to value name. In our example it is given in assumption. 
      anAdServerId.setField("Name", "An Example-Value");
      // Set the RecordTypeId to ID of RecordType with name DFP of object AdServer ID. In our example it is given in assumption. 
      anAdServerId.setField("RecordTypeId", "012A00000012g4AIAQ");
      // Set the ADvendio__Active__c to true.
      anAdServerId.setField("ADvendio__Active__c", true);
      // Set the ADvendio__AdServer_ID__c to key ID. In our example it is given in assumption.
      anAdServerId.setField("ADvendio__AdServer_ID__c", 54321);
      // Set the ADvendio__AdServer_Login__c to the ID of record of ad-server DFP. In our example it is given in assumption. 
      anAdServerId.setField("ADvendio__AdServer_Login__c", "a0AA000000yqsnXMAQ");
      // Set the ADvendio__AdServer_Name__c to key name. In our example it is given in assumption. 
      anAdServerId.setField("ADvendio__AdServer_Name__c", "An Example-Value");
      // Set the ADvendio__Category__c to "Key-values" which is fix definition of ADvendio.
      anAdServerId.setField("ADvendio__Category__c", "Key-values");
      // Set the ADvendio__Status__c to the correspond value assigned to the key in ad-server if there is.
      // Allowed is one of "Active", "Inactive", "Archived" or "Deleted".
      anAdServerId.setField("ADvendio__Status__c", "Active");
      // Set the ADvendio__Type__c to the "Value" which is fix definition of ADvendio.
      anAdServerId.setField("ADvendio__Type__c", "Value");
      // Set the ADvendio__UniqueKey__c to a fixed format defined in ADvendio.
      // It is a string concatenation: ID of record of ad-server + "|" + "Value" + "|" + value ID
      anAdServerId.setField("ADvendio__UniqueKey__c", "a0AA000000yqsnXMAQ|Value|54321");

      // Create or update the ADvendio__AdServer_ID__c, using the upsert method.
      // The unique key for upsert is ADvendio__UniqueKey__c.
      UpsertResult[] upsertResults = partnerConnection.upsert(
         "ADvendio__UniqueKey__c"
         new SObject[] {anAdServerId}
      );

      // Iterate through the results, check the possible error
      for (int j = 0; j < upsertResults.length; j++) {
          System.out.println("\nItem: " + j);
          if (upsertResults[j].isSuccess()) {
              System.out.println("ADvendio__AdServer_ID__c with an ID of " + upsertResults[j].getId() + " was created/updated.");
          }
          else {                        
            // There were errors during the upset call,
            // go through the errors array and write
            // them to the console.
            for (int i = 0; i < upsertResults[j].getErrors().length; i++) {
              Error err = upsertResults[j].getErrors()[i];
              System.out.println("Errors were found on item " + j);
              System.out.println("Error code: " + err.getStatusCode().toString());
              System.out.println("Error message: " + err.getMessage());
            }
          }      
      }

      // Your additional error handler here.

      // Create an sObject of type ADvendio__Value__c
      SObject aValue = new SObject();
      aValue.setType("ADvendio__Value__c");
      
      // Set the Name to value name. In our example it is given in assumption. 
      aValue.setField("Name", "An Example-Value");
      // Set the ADvendio__Active__c to true.
      aValue.setField("ADvendio__Active__c", true);
      // Set the ADvendio__UniqueKey__c to a fixed format defined in ADvendio.
      // It is a string concatenation: ID of record of ad-server + "|" + value ID
      aValue.setField("ADvendio__UniqueKey__c", "a0AA000000yqsnXMAQ|54321");
      // Set the ADvendio__Key__c to the Key created/updated above. Here we use the unique key of that record.
      SObject aKey = new SObject();
      aKey.setType("ADvendio__Key__c");
      aKey.setField("ADvendio__UniqueKey__c", "a0AA000000yqsnXMAQ|Key|12345");
      aValue.setField("ADvendio__Key__r", aKey);  // Attention: the first parameter is ADvendio__Key__r, not ADvendio__Key__c.
      // Set the ADvendio__AdServerId__c to the one created/updated above. Here we use the unique key of that record.
      anAdServerId = new SObject();
      anAdServerId.setType("ADvendio__AdServer_ID__c");
      anAdServer.setField("ADvendio__UniqueKey__c", "a0AA000000yqsnXMAQ|Value|54321");
      aValue.setField("ADvendio__AdServerId__r", anAdServerId);  // Attention: the first parameter is ADvendio__AdServerId__r, not ADvendio__AdServerId__c.

      // Create or update the ADvendio__Value__c, using the upsert method.
      // The unique key for upsert is ADvendio__UniqueKey__c.
      upsertResults = partnerConnection.upsert(
         "ADvendio__UniqueKey__c"
         new SObject[] {aValue}
      );

      // Iterate through the results, check the possible error
      for (int j = 0; j < upsertResults.length; j++) {
          System.out.println("\nItem: " + j);
          if (upsertResults[j].isSuccess()) {
              System.out.println("ADvendio__Key__c with an ID of " + upsertResults[j].getId() + " was created/updated.");
          }
          else {                        
            // There were errors during the upset call,
            // go through the errors array and write
            // them to the console.
            for (int i = 0; i < upsertResults[j].getErrors().length; i++) {
              Error err = upsertResults[j].getErrors()[i];
              System.out.println("Errors were found on item " + j);
              System.out.println("Error code: " + err.getStatusCode().toString());
              System.out.println("Error message: " + err.getMessage());
            }
          }      
      }

      // Your additional error handler here.
  } catch (ConnectionException ce) {
      ce.printStackTrace();
  }
}