Generate client jar for custom salesforce WSDL

Problem Statement:

How to generate client jar file for custom salesforce WSDL

Pre-requisite:

  1. MVN Setup
  2. JDK Setup
  3. WSC Connector jar

Solution:

Run below command,

C:\SalesForce\wsc>java -cp c:/SalesForce/wsc/tools.jar;c:/SalesForce/wsc/target/force-wsc-40.0.0-uber.jar com.sforce.ws.tools.wsdlc AccountHandler.wsdl myjar.jar

explanation:

  • Java is set on path
  • -cp is to set classpath
  • tools.jar is copied from <JAVA_HOME>/libs
  • 40.0.0-uber.jar is copied from WSC Connector folder (versions may vary, name could be like xxx-uber.jar)
  • com.sforce.ws.tools.wsdlc is client class generator for WSDL
  • handler.wsdl is custom wsdl downloaded from Salesforce
  • myjar.jar is output file name

crxde lite shows no content

Tags

, , , , ,

Problem Statement:

I started my aem¬†after a day and now I am not able to see anything in my crx lite. it shows only “/” nothing else.

Solution:

https://docs.adobe.com/docs/en/aem/6-2/administer/security/security-checklist/enabling-crxde-lite.html

This link has description of problem as well as step by step solution. Drop me a note if you face any challenges, cheers!

Error generating jar from salesforce wsdl

Tags

, , , ,

Problem Statement:

so many not found errors while generating jar file i.e.
Class not found RelationshipReferenceTo,
Class not found JunctionIdListNames,
Class not found SearchLayoutButtonsDisplayed,
Class not found SearchLayoutFieldsDisplayed,
Class not found RecordTypesSupported

Solution:

Download enterprise wsdl and copy these complex types from there and paste to your wsdl. Rebuild jar after that.

I copied this from enterprise wsdl and added to my WSDL,

<xsd:complexType name="SearchLayoutButtonsDisplayed"> 
<xsd:sequence> 
<xsd:element name="applicable" type="xsd:boolean"/> 
<xsd:element name="buttons" minOccurs="0" maxOccurs="unbounded" type="tns:SearchLayoutButton"/> 
</xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="SearchLayoutButton"> 
<xsd:sequence> 
<xsd:element name="apiName" type="xsd:string"/> 
<xsd:element name="label" type="xsd:string"/> 
</xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="SearchLayoutFieldsDisplayed"> 
<xsd:sequence> 
<xsd:element name="applicable" type="xsd:boolean"/> 
<xsd:element name="fields" minOccurs="0" maxOccurs="unbounded" type="tns:SearchLayoutField"/> 
</xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="SearchLayoutField"> 
<xsd:sequence> 
<xsd:element name="apiName" type="xsd:string"/> 
<xsd:element name="label" type="xsd:string"/> 
<xsd:element name="sortable" type="xsd:boolean"/> 
</xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="JunctionIdListNames"> 
<xsd:sequence> 
<xsd:element name="names" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/> 
</xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="RelationshipReferenceTo"> 
<xsd:sequence> 
<xsd:element name="referenceTo" minOccurs="0" maxOccurs="unbounded" type="xsd:string"/> 
</xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="RecordTypesSupported"> 
<xsd:sequence> 
<xsd:element name="recordTypeInfos" minOccurs="0" maxOccurs="unbounded" type="tns:RecordTypeInfo"/> 
</xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="RecordTypeInfo"> 
<xsd:sequence> 
<xsd:element name="available" type="xsd:boolean"/> 
<xsd:element name="defaultRecordTypeMapping" type="xsd:boolean"/> 
<xsd:element name="master" type="xsd:boolean"/> 
<xsd:element name="name" type="xsd:string"/> 
<xsd:element name="recordTypeId" type="tns:ID" nillable="true"/> 
</xsd:sequence> 
</xsd:complexType>

Unable to generate enterprise wsdl

Tags

, ,

Problem Statement:

Error: Unable to find compiler. Make sure that tools.jar is in your classpath: java.lang.ClassNotFoundException: com.sun.tools.javac.Main

Solution:

add tools.jar to your classpath like this,

java -cp <JAVA_HOME>/lib/tools.jar;c:/SalesForce/wsc/target/force-wsc-40.0.0-uber.jar com.sforce.ws.tools.wsdlc enterprise.wsdl enterprise.jar

Test failing while generating wsc connector jar

Tags

, ,

Problem Statement:

If you have downloaded WSC api from mvn and trying to build it and seeing below error,

docSample\SoapConnection.java: The process cannot access the file because it is being used by another process

Workaround Solution:

Skip Tests while generating jar using below command…

c:\>mvn clean package -Dgpg.skip -DskipTests

 

How to call Salesforce service from Java

Tags

, , ,

Problem Statement:

Call Salesforce webservice from a java client.

Pre-requisites:

  • Setup JDK 1.8 (Version may vary)
  • Setup Eclipse for Salesforce
  • Setup Maven
  • Setup Salesforce Webservice Connector

Solution:

  1. Open Eclipse and create a new Java Project,

java-project

2. Specify

  • Project Name = sflearn
  • JRE = JDK1.8
  • Click “Finish”

java-project2

3. Right Click on newly created project “sflearn” and select “Properties”

java-project3

4. Select

  • “Java Build Path” from left panel,
  • select “Libraries” tab from right panel,
  • click “External libraries” button,
  • select “**.uber.jar” from Salesforce Webservice Connector folder ( Refer:Setup Salesforce Webservice Connector)
  • select “enterprise.jar” from WSDL Jar folder ( Refer:Generate WSDL Jar)

java-project4

5. It should look like below,

java-project5

Click “Ok”

6. Right click on “sflearn” project->select “New”->”Class”

java-project6

7. Specify

  • Package: com.utility
  • Name: SFConnector
  • Check “Public static void main(String ars[[])”
  • Check “Generate Comments”
  • click “Finish”

java-project7

8. Copy and paste below code,

package com.utility;

import com.sforce.soap.enterprise.Connector;
import com.sforce.soap.enterprise.DeleteResult;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.Error;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SaveResult;
import com.sforce.soap.enterprise.sobject.Lead;
import com.sforce.ws.ConnectorConfig;
import com.sforce.ws.ConnectionException;

/**
 * This class makes salesforce webservice connection.
 * 
 * @author KumarAbhishek_Shahi
 *
 */
public class SFConnector {

 static final String USERNAME = "your sales force user name";
 static final String PASSWORD = "your password and security tocken";
 static EnterpriseConnection connection;

 /**
 * Main method to test this utility
 * 
 * @param String[]
 * args
 */
 public static void main(String[] args) {

 ConnectorConfig config = new ConnectorConfig();
 config.setUsername(USERNAME);
 config.setPassword(PASSWORD);

 try {

 connection = Connector.newConnection(config);

 // display some current settings
 System.out.println("Auth EndPoint: " + config.getAuthEndpoint());
 System.out.println("Service EndPoint: " + config.getServiceEndpoint());
 System.out.println("Username: " + config.getUsername());
 System.out.println("SessionId: " + config.getSessionId());

 // run the different examples
 queryLeads(); // Query Leads from Salesforce
 createLeads(); // Create Leads in Salesforce
 updateLeads(); // Update Leads in Salesforce
 deleteLeads(); // Delete Leads in Salesforce

 } catch (ConnectionException e1) {
 e1.printStackTrace();
 }

 try {
 connection.logout();
 System.out.println("Logged out.");
 } catch (ConnectionException ce) {
 ce.printStackTrace();
 }

 }

 /**
 * queries and displays the 5 newest leads
 * 
 * @param
 * @return
 */
 private static void queryLeads() {

 System.out.println("Querying for the 5 newest Leads...");

 try {

 // query for the 5 newest Leads
 QueryResult queryResults = connection
 .query("SELECT Id, FirstName, LastName, Company FROM Lead ORDER BY CreatedDate DESC LIMIT 5");
 if (queryResults.getSize() > 0) {
 for (int i = 0; i < 5; i++) {
 // cast the SObject to a strongly-typed Lead
 Lead l = (Lead) queryResults.getRecords()[i];
 System.out.println("Id: " + l.getId() + " - Name: " + l.getFirstName() + " " + l.getLastName()
 + " - Company: " + l.getCompany());
 }
 }

 } catch (Exception e) {
 e.printStackTrace();
 }

 }

 /**
 * create 5 test Leads
 * 
 * @param
 * @return
 */

 private static void createLeads() {

 System.out.println("Creating 5 new test Leads...");
 Lead[] records = new Lead[5];

 try {

 // create 5 test leads
 for (int i = 0; i < 5; i++) {
 Lead l = new Lead();
 l.setFirstName("SOAP API");
 l.setLastName("Lead " + i);
 l.setCompany("asagarwal.com");

 records[i] = l;
 }

 // create the records in Salesforce.com
 SaveResult[] saveResults = connection.create(records);

 // check the returned results for any errors
 for (int i = 0; i < saveResults.length; i++) {
 if (saveResults[i].isSuccess()) {
 System.out.println(i + ". Successfully created record - Id: " + saveResults[i].getId());
 } else {
 Error[] errors = saveResults[i].getErrors();
 for (int j = 0; j < errors.length; j++) {  System.out.println("ERROR creating record: " + errors[j].getMessage());  }  }  }  } catch (Exception e) {  e.printStackTrace();  }  }  /**  * updates the 5 newly created Leads  *   * @param  * @return  */  private static void updateLeads() {  System.out.println("Update the 5 new test leads...");  Lead[] records = new Lead[5];  try {  QueryResult queryResults = connection  .query("SELECT Id, FirstName, LastName, Company FROM Lead ORDER BY CreatedDate DESC LIMIT 5");  if (queryResults.getSize() > 0) {
 for (int i = 0; i < 5; i++) {
 // cast the SObject to a strongly-typed Lead
 Lead l = (Lead) queryResults.getRecords()[i];
 System.out.println(
 "Updating Id: " + l.getId() + " - Name: " + l.getFirstName() + " " + l.getLastName());
 // modify the name of the Lead
 l.setLastName(l.getLastName() + " -- UPDATED");
 records[i] = l;
 }
 }

 // update the records in Salesforce.com
 SaveResult[] saveResults = connection.update(records);

 // check the returned results for any errors
 for (int i = 0; i < saveResults.length; i++) {
 if (saveResults[i].isSuccess()) {
 System.out.println(i + ". Successfully updated record - Id: " + saveResults[i].getId());
 } else {
 Error[] errors = saveResults[i].getErrors();
 for (int j = 0; j < errors.length; j++) {  System.out.println("ERROR updating record: " + errors[j].getMessage());  }  }  }  } catch (Exception e) {  e.printStackTrace();  }  }  /**  * delete the 2 newly created Leads  *   * @param  * @return  */  private static void deleteLeads() {  System.out.println("Deleting the 2 new test Leads...");  String[] ids = new String[2];  try {  QueryResult queryResults = connection.query("SELECT Id, Name FROM Lead ORDER BY CreatedDate DESC LIMIT 2");  if (queryResults.getSize() > 0) {
 for (int i = 0; i < queryResults.getRecords().length; i++) {
 // cast the SObject to a strongly-typed Lead
 Lead l = (Lead) queryResults.getRecords()[i];
 // add the Lead Id to the array to be deleted
 ids[i] = l.getId();
 System.out.println(
 "Deleting Id: " + l.getId() + " - Name: " + l.getFirstName() + " " + l.getLastName());
 }
 }

 // delete the records in Salesforce.com by passing an array of Ids
 DeleteResult[] deleteResults = connection.delete(ids);

 // check the results for any errors
 for (int i = 0; i < deleteResults.length; i++) {
 if (deleteResults[i].isSuccess()) {
 System.out.println(i + ". Successfully deleted record - Id: " + deleteResults[i].getId());
 } else {
 Error[] errors = deleteResults[i].getErrors();
 for (int j = 0; j < errors.length; j++) {
 System.out.println("ERROR deleting record: " + errors[j].getMessage());
 }
 }
 }

 } catch (Exception e) {
 e.printStackTrace();
 }

 }

}

8. Follow below,

  • Right click on “SFConnector.java”,
  • Select “Run As”
  • Select “Run As Java Application”

java-project8

9. On console you will see this,

Auth EndPoint: https://login.salesforce.com/services/Soap/c/39.0/0DF280000000lrR
Service EndPoint: https://kumarshahi-dev-ed.my.salesforce.com/services/Soap/c/39.0/00D28000001Kjxx/0DF280000000lrR
Username: abhishek.shahi@gmail.com
SessionId: 00D28000001Kjxx!AREAQGU6MvrdmFFXXf4WgsnTEOti_MCJD6pGZJXCGN6xZy2F1FfPDdDc3qemeBx1mA78V411RUDADHHx3DNa_L9VCbb_6hmF
Querying for the 5 newest Leads...
Id: 00Q2800000dgxSKEAY - Name: SOAP API Lead 0 -- UPDATED - Company: asagarwal.com
Id: 00Q2800000dgxSLEAY - Name: SOAP API Lead 1 -- UPDATED - Company: asagarwal.com
Id: 00Q2800000dgxSMEAY - Name: SOAP API Lead 2 -- UPDATED - Company: asagarwal.com
Id: 00Q2800000cZJEDEA4 - Name: Vivek Kumar - Company: Wipro Technologies
Id: 00Q2800000IdBXzEAN - Name: Bertha Boxer - Company: Farmers Coop. of Florida
Creating 5 new test Leads...
0. Successfully created record - Id: 00Q2800000dgxnZEAQ
1. Successfully created record - Id: 00Q2800000dgxnaEAA
2. Successfully created record - Id: 00Q2800000dgxnbEAA
3. Successfully created record - Id: 00Q2800000dgxncEAA
4. Successfully created record - Id: 00Q2800000dgxndEAA
Update the 5 new test leads...
Updating Id: 00Q2800000dgxnZEAQ - Name: SOAP API Lead 0
Updating Id: 00Q2800000dgxnaEAA - Name: SOAP API Lead 1
Updating Id: 00Q2800000dgxnbEAA - Name: SOAP API Lead 2
Updating Id: 00Q2800000dgxncEAA - Name: SOAP API Lead 3
Updating Id: 00Q2800000dgxndEAA - Name: SOAP API Lead 4
0. Successfully updated record - Id: 00Q2800000dgxnZEAQ
1. Successfully updated record - Id: 00Q2800000dgxnaEAA
2. Successfully updated record - Id: 00Q2800000dgxnbEAA
3. Successfully updated record - Id: 00Q2800000dgxncEAA
4. Successfully updated record - Id: 00Q2800000dgxndEAA
Deleting the 2 new test Leads...
Deleting Id: 00Q2800000dgxndEAA - Name: null null
Deleting Id: 00Q2800000dgxncEAA - Name: null null
0. Successfully deleted record - Id: 00Q2800000dgxndEAA
1. Successfully deleted record - Id: 00Q2800000dgxncEAA
Logged out.

Have fun!!!

Don’t hesitate asking questions if you have any issues or doubts.

Accessing Weblogic Logs from Oracle Java Cloud Service using Putty

Make sure you have setup Oracle Java Cloud Service.

  1. Start Putty by clicking on putty.exe

jcsssh2. Specify Host Name – Public IP of Oracle Java Cloud Service Instance

3. make sure Connection Type = SSH

4. Specify Saved Session name = Any Name. Prefer Giving some meaningful name based on IP/Service connected.

5. Expand “Connections” from left panel. Select “Data”,

jcsssh1Specify Login Details -> Auto login User Name = opc

Select “Connection->SSH” from left Panel,

jcsssh2Make sure you have not selected “Don’t start a shell or command at all” in Protocol options. In the above image it is selected but please unselect to make it work.

Select “Connection->SSH->AUTH” from left panel,

jcsssh3Browse and supply private key which was generated in earlier blog to “Private Key file for authorization”.

Select “Connection->SSH->Tunnels” from left panel,

jcsssh4Specify Source Port = 9001 This is specially configured for SSH based access.

Specify Destination = Java Cloud Service Public IP:9001 and click “add”.

Select “Session” from Left Panel and “Save” configuration and Open. It will open a console like this,

jcsssh5

At Putty console run below command,

>sudo su – oracle

It will switch current “opc” user to super user “oracle”.

Now you can go to weblogic logs folder and check the log using below command,

>tail -f logFileName.out

and then run you application again. Putty console will show real-time logs.