Java Reference
In-Depth Information
directory of your project. Right-click the project directory in Eclipse and select Build
Path
Add to Build Path . Open the servlet that was automatically created for you
under your src folder. Ours was called HelloWorldServlet.java . Copy the code from
Listing 9-9 into the servlet.
Listing 9-9. Code for the servlet
package com.kyleroche.sfdcwsc;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.*;
import com.sforce.ws.*;
import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.SObject;
@SuppressWarnings("serial") public class HelloWorldServlet extends
HttpServlet {
private String username = " appengine@apress.com";
private String password = "app1r10#123";
private PartnerConnection connection;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
resp.getWriter().println("Hello, from Salesforce.com");
PrintWriter t = resp.getWriter();
getConnection( t, req);
if ( connection == null ) { return; }
QueryResult result = null;
try {
result = connection.query("select name from Account
limit 10");
} catch (ConnectionException e) {
e.printStackTrace();
}
for (SObject account : result.getRecords()) {
t.println("<li>"+ (String)account.getField("Name") +
"</li>");
}
}
 
Search WWH ::




Custom Search