• Jacob Friedman 11
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
Howdy.  I'm using a Java program to connect to the SF SOAP API v41.  My end goal is to use the API to:
1. Create a record via create().
2. Search for the record in step 1 via search().
3. Cull list down from number 2 so that I can
4. Update that record.

Below is the code I'm using based on the samples in the documentation for the SOAP API.
I'm calling the create record first.  Then calling the search method, which uses a variable from create to get results.  For some reason the record created in step 1 is not found when I search for it in the API.  If I go to my org, I clearly see it.  If I run the code a second time, I see the record.

Any thoughts or ideas on how to get the record to show up in initial run of the code?

This is tough to articulate, so please let me know if you need any clarifcations to my question.
package resources;
import com.sforce.soap.partner.PartnerConnection;
import com.sforce.soap.partner.sobject.*;
import com.sforce.soap.partner.*;
import com.sforce.ws.ConnectorConfig;
import com.sforce.ws.ConnectionException;
import com.sforce.soap.partner.Error;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.*;

public class PartnerSamples {
    PartnerConnection partnerConnection = null;
    private static BufferedReader reader =
        new BufferedReader(new InputStreamReader(System.in));
    
    public static void main(String[] args) {
        PartnerSamples samples = new PartnerSamples();
        if (samples.login()) {
            // Add calls to the methods in this class.
            // For example:
            // samples.querySample();
        	samples.createSample();
        	String searchVariable = "Application Gathering";
        	samples.searchSample(searchVariable);
        	
        }
    } 
    
    private String getUserInput(String prompt) {
        String result = "";
        try {
          System.out.print(prompt);
          result = reader.readLine();
        } catch (IOException ioe) {
          ioe.printStackTrace();
        }
        return result;
    }
    
    private boolean login() {
        boolean success = false;
        String username = getUserInput("Enter username: ");
        String password = getUserInput("Enter password: ");
        String authEndPoint = getUserInput("Enter auth end point: ");
        

        try {
          ConnectorConfig config = new ConnectorConfig();
          config.setUsername(username);
          config.setPassword(password);
          
          config.setAuthEndpoint(authEndPoint);
          config.setTraceFile("traceLogs.txt");
          config.setTraceMessage(true);
          config.setPrettyPrintXml(true);

          partnerConnection = new PartnerConnection(config);          

          success = true;
        } catch (ConnectionException ce) {
          ce.printStackTrace();
        } catch (FileNotFoundException fnfe) {
          fnfe.printStackTrace();
        }

        return success;
      }

    // 
    // Add your methods here.
    //
    
    public String createSample() {
        String result = null;
        try {
            // Create a new sObject of type Contact
               // and fill out its fields.
        	////figure out how to make this block a variable within a test case and get inserted here////
//            SObject contact = new SObject();
//            contact.setType("Contact");
//            contact.setField("FirstName", "Jester");
//            contact.setField("LastName", "Jespersen");
//            contact.setField("Salutation", "Professor");
//            contact.setField("Phone", "(999) 555-1234");
//            contact.setField("Title", "Philologist");
            
//            SObject enrollment = new SObject();
//            enrollment.setType("optm_cld_inr__Enrollment__c");
//            enrollment.setField("optm_cld_inr__Enrollment_Application__c", "JFSOAPEn4");
//            enrollment.setField("optm_cld_inr__Provider__c", "0034600000TadcdAAB");
//            enrollment.setField("optm_cld_inr__Enrollment_Type__c", "New Enrollment");
//            enrollment.setField("optm_cld_inr__Enrollment_Status__c", "Initiated");
//            enrollment.setField("optm_cld_inr__Source__c", "Sales");
//            enrollment.setField("optm_cld_inr__Enrollment_Format__c", "Paper");
            
            SObject credentialing = new SObject();
        	credentialing.setType("optm_cld_inr__Credential__c");
        	credentialing.setField("Name", "JFSOAPCred1");
        	credentialing.setField("optm_cld_inr__Provider__c", "0034600000TadcdAAB");
        	credentialing.setField("optm_cld_inr__Type__c", "Initial Credentialing");
        	credentialing.setField("optm_cld_inr__Credentialing_Status__c", "Initiated");

            
            
            
        
            // Add this sObject to an array 
            SObject[] credentialings = new SObject[1];
            credentialings[0] = credentialing;
            // Make a create call and pass it the array of sObjects
            SaveResult[] results = partnerConnection.create(credentialings);              
            ///////////////end block///
            
            
            // Iterate through the results list
            // and write the ID of the new sObject
            // or the errors if the object creation failed.
            // In this case, we only have one result
            // since we created one contact.
            for (int j = 0; j < results.length; j++) {
                if (results[j].isSuccess()) {
                    result = results[j].getId();
                    System.out.println(
                        "\nA contact was created with an ID of: " + result
                    );
                 } else {
                    // There were errors during the create call,
                    // go through the errors array and write
                    // them to the console
                    for (int i = 0; i < results[j].getErrors().length; i++) {
                        Error err = results[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());
                    }
                 }
            }
        } catch (ConnectionException ce) {
            ce.printStackTrace();
        }
        return result;
        
        
    }
    
    public void searchSample(String searchVariable) {
        try {    
            // Example of phoneNumber format: 4155551212
            String soslQuery = 
                "FIND {" + searchVariable + "}  " +
                "RETURNING " +
                "Contact(Id, Phone, FirstName, LastName), " +
                "Lead(Id, Phone, FirstName, LastName)," +
                "Account(Id, Phone, Name)," +
                "optm_cld_inr__Credential_Tracking__c(Id, Name, optm_cld_inr__Credentialing_Step__c, optm_cld_inr__Credentialing__c)";
            	
            
            
            
            
            System.out.println(soslQuery);
            // Perform SOSL query
            SearchResult sResult = partnerConnection.search(soslQuery);
            // Get the records returned by the search result
            SearchRecord[] records = sResult.getSearchRecords();
            // Create lists of objects to hold search result records
            List<SObject> contacts = new ArrayList<SObject>();
            List<SObject> leads = new ArrayList<SObject>();
            List<SObject> accounts = new ArrayList<SObject>();
            List<SObject> credTracking = new ArrayList<SObject>();
            // Iterate through the search result records
            // and store the records in their corresponding lists
            // based on record type.
            if (records != null && records.length > 0) {
              for (int i = 0; i < records.length; i++){
                SObject record = records[i].getRecord();
                if (record.getType().toLowerCase().equals("contact")) {
                  contacts.add(record);
                } else if (record.getType().toLowerCase().equals("lead")){
                  leads.add(record);
                } else if (record.getType().toLowerCase().equals("account")) {
                  accounts.add(record);
                } else if (credTracking.add(record));
                
              }
              // Display the contacts that the search returned
              if (contacts.size() > 0) {
                System.out.println("Found " + contacts.size() + 
                    " contact(s):");
                for (SObject contact : contacts) {
                  System.out.println(contact.getId() + " - " +
                      contact.getField("FirstName") + " " +
                      contact.getField("LastName") + " - " +
                      contact.getField("Phone")
                  );
                }
              }
           //Cred Tracking   
              System.out.println("Found " + credTracking.size() + " record(s):" );
              for (SObject optm_cld_inr__Credential_Tracking__c  : credTracking ){
              	System.out.println(optm_cld_inr__Credential_Tracking__c.getId() + "-" +
              			optm_cld_inr__Credential_Tracking__c.getField("Name") + "-" +
              			optm_cld_inr__Credential_Tracking__c.getField("optm_cld_inr__Credentialing_Step__c") + "-" +
              			optm_cld_inr__Credential_Tracking__c.getField("optm_cld_inr__Credentialing__c")
              	);}
              // Display the leads that the search returned
              if (leads.size() > 0) {
                System.out.println("Found " + leads.size() +
                    " lead(s):");
                for (SObject lead : leads) {
                  System.out.println(lead.getId() + " - " +
                      lead.getField("FirstName") + " " +
                      lead.getField("LastName") + " - " +
                      lead.getField("Phone")
                  );
                }
              }
              // Display the accounts that the search returned
              if (accounts.size() > 0) {
                System.out.println("Found " + 
                    accounts.size() + " account(s):");
                for (SObject account : accounts) {
                  System.out.println(account.getId() + " - " +
                      account.getField("Name") + " - " +                  
                      account.getField("Phone")
                  );
                }
              }
            } else {
              // The search returned no records 
              System.out.println("No records were found for the search.");
            }
          } catch (ConnectionException ce) {
            ce.printStackTrace();
        }      
    }
}

 
All,
I'm working on Selenium Test Automation of my App using the LEX.  In Classic, locators are static in that I can reference an ID number or name, whereas it seems the same field/object in LEX has dynamic IDs depending on when I access said element.

HTML from LEX yields:
<a aria-required="true" class="select" aria-disabled="false" aria-haspopup="true" tabindex="0" role="button" aria-label="Enrollment Type" title="" href="javascript:void(0);" data-aura-rendered-by="2944:0" data-interactive-lib-uid="60">--None--</a>

I try to use the bold faced section as a locator, but it changes each time I click on it.  Here's another example of the same elment. As you can see the id is now 90, instead of 60 above.
<a aria-required="true" class="select" aria-disabled="false" aria-haspopup="true" tabindex="0" role="button" aria-label="Enrollment Type" title="" href="javascript:void(0);" data-aura-rendered-by="4995:0" data-interactive-lib-uid="90">--None--</a>

Here's a snippet from classic, where I can always US the same ID.  It never changes.  Has anyone found a solution to this problem for finding element locators in LEX?
<select id="00No000000DyWd7" name="00No000000DyWd7" tabindex="8"><option value="">--None--</option><option value="New Enrollment">New Enrollment</option><option value="Re-Enrollmet">Re-Enrollmet</option><option value="Re-Validation">Re-Validation</option><option value="Information Update">Information Update</option></select>



 
All,
I'm working on Selenium Test Automation of my App using the LEX.  In Classic, locators are static in that I can reference an ID number or name, whereas it seems the same field/object in LEX has dynamic IDs depending on when I access said element.

HTML from LEX yields:
<a aria-required="true" class="select" aria-disabled="false" aria-haspopup="true" tabindex="0" role="button" aria-label="Enrollment Type" title="" href="javascript:void(0);" data-aura-rendered-by="2944:0" data-interactive-lib-uid="60">--None--</a>

I try to use the bold faced section as a locator, but it changes each time I click on it.  Here's another example of the same elment. As you can see the id is now 90, instead of 60 above.
<a aria-required="true" class="select" aria-disabled="false" aria-haspopup="true" tabindex="0" role="button" aria-label="Enrollment Type" title="" href="javascript:void(0);" data-aura-rendered-by="4995:0" data-interactive-lib-uid="90">--None--</a>

Here's a snippet from classic, where I can always US the same ID.  It never changes.  Has anyone found a solution to this problem for finding element locators in LEX?
<select id="00No000000DyWd7" name="00No000000DyWd7" tabindex="8"><option value="">--None--</option><option value="New Enrollment">New Enrollment</option><option value="Re-Enrollmet">Re-Enrollmet</option><option value="Re-Validation">Re-Validation</option><option value="Information Update">Information Update</option></select>



 
I've a Lightning Component that works fine in dev org but deployed in a managed package it throws Internal Server Error. I found another developer thread that has expereinced same kind of error with Lightning Component -
http://salesforce.stackexchange.com/questions/100990/an-internal-server-error-has-occurred-error-id-143631613-25605-15667340

I'm looking to find out if my issue is due to same and I've no idea what this Error ID means, no more details are shown.

My error details are:
An internal server error has occurred Error ID: 1288557852-29109 (-898570520)



 
  • December 05, 2015
  • Like
  • 0