Salesforce Workbench Express

I developed a Express version of Salesforce Workbench:

package com.thysmichels;

import java.io.IOException;
import javax.servlet.http.*;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.*;
import java.util.logging.*;
import com.sforce.ws.*;
import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.SObject;


@SuppressWarnings("serial")
public class SalesforceGoogleAppServlet extends HttpServlet {
		private static final Logger log = Logger.getLogger(SalesforceGoogleAppServlet.class.getName());
		private static String copytablestr;
		private String username = "username";
		private String password = "passwordsecuritytoken";
		private PartnerConnection connection;
		
		public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
				
			resp.setContentType("text/html");
			PrintWriter t = resp.getWriter();   
			t.println("");
			t.println("");
			resp.getWriter().println("*** Welcome to Salesforce WorkBench Express ***" + "
"); getForceConnection( t, req); if ( connection == null ) { return; } QueryResult result = null; try { DescribeGlobalResult describeGlobalResult = connection.describeGlobal(); DescribeGlobalSObjectResult[] sobjectResults = describeGlobalResult.getSobjects(); //result = connection.query("Select id, name, phone from Account order by LastModifiedDate desc limit 10 "); t.println(""); t.println(""); t.println(""); for (int i = 0; i < sobjectResults.length; i++) { t.println("" + sobjectResults[i].getName() + ""); } t.println("" + "
"); t.println(""); t.println(""); //t.println("item 1item 2item 3item 4All"); } catch (ConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { try { resp.setContentType("text/html"); PrintWriter t = resp.getWriter(); String str= req.getParameter("slt"); if (str != null) { DescribeSObjectResult describeSObjectResult = connection.describeSObject(str); if (describeSObjectResult != null) { t.println("*** Fields from Object : " + str + " ***
"); copytablestr = str; Field[] fields = describeSObjectResult.getFields(); t.println(""); t.println(""); for (int k = 0; k < fields.length; k++) { t.println("" + fields[k].getName() + ""); } t.println(""); t.println(""); } } String field[]= req.getParameterValues("fieldselect"); if (field != null) { t.println(""); t.println(""); String strconcat = ""; for (int k=0; k < field.length; k++) { if (k==0) { strconcat += field[k]; t.println(""); } else { strconcat += "," + field[k]; t.println(""); } } t.println(""); String QueryStr = "SELECT " + strconcat + " FROM " + copytablestr; QueryResult queryResults = connection.query(QueryStr); if (queryResults.getSize() > 0) { for (SObject s: queryResults.getRecords()) { t.print(""); for (int col=0; col < field.length; col++) { t.print(""); } t.print(""); } } t.println("
" + field[k] + "" + field[k] + "
" + s.getField(field[col]) + "
"); } } catch(ConnectionException e) { e.printStackTrace(); } } void getForceConnection(PrintWriter out, HttpServletRequest req) { try { // build up a ConnectorConfig from a sid String sessionid = req.getParameter("sid"); String serverurl = req.getParameter("srv"); if ( connection == null ) { // login to the Force.com Platform ConnectorConfig config = new ConnectorConfig(); if ( sessionid != null && serverurl != null) { config.setServiceEndpoint(serverurl); config.setSessionId(sessionid); config.setManualLogin(false); } else { config.setUsername(username); config.setPassword(password); } connection = Connector.newConnection(config); } log.warning("Connection SID " +connection.getConfig().getSessionId()); } catch ( ConnectionException ce) { log.warning("ConnectionException " +ce.getMessage()); out.println( ce.getMessage() + " s " + ce.getClass() ); } } }

Access Salesforce Workbench Express Online Click Here

About these ads

One Comment on “Salesforce Workbench Express

  1. Pretty nice post. I simply stumbled upon your weblog and wished to mention that I’ve truly enjoyed surfing around your weblog posts. After all I’ll be subscribing on your
    rss feed and I’m hoping you write again soon!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 235 other followers

%d bloggers like this: