Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 "a0AA000000yqsnX"a0AA000000yqsnXAQ" – in Salesforce 18 digits ID format.

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

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

Code Block
languagejava
titleJava 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("NameRecordTypeId", "012A00000012g4A012A00000012g4AIAQ");
      // 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", "a0AA000000yqsnXa0AA000000yqsnXMAQ");
      // 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", "a0AA000000yqsnXa0AA000000yqsnXMAQ|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", "a0AA000000yqsnXa0AA000000yqsnXMAQ|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", "a0AA000000yqsnXa0AA000000yqsnXMAQ|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("NameRecordTypeId", "012A00000012g4A012A00000012g4AIAQ");
      // 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", "a0AA000000yqsnXa0AA000000yqsnXMAQ");
      // 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", "a0AA000000yqsnXa0AA000000yqsnXMAQ|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", "a0AA000000yqsnXa0AA000000yqsnXMAQ|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", "a0AA000000yqsnXa0AA000000yqsnXMAQ|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", "a0AA000000yqsnXa0AA000000yqsnXMAQ|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();
  }
}