• Jordan Miles
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I'm using the Salesforce REST APIs to created customers (in our case organizations) that can have n-number of agents (users within an organization). Most of them only have 1-2 users, but currently, I have an agent rich text field where I just append every agent with line breaks in between each name because I didn't know a way accomodate for what I was needing. In other words, I would have to create n-number of fields within salesforce, each with a unique field name. Is there a better way to do this?

I'm trying to add multiple values (email addresses) to a Long text area with the REST API. I've noticed that, when I query an object, that text field comes back as

{
   fieldName:"value1/n/rvalue2/n/rvalue3/n/r"
}
I can't really do the literal newline characters in the string, because java will try to treat them as newlines. I can't find any documentation that shows how to do this. How can I post multiple values to Salesforce, making sure each value is on a new line inside the text area?

We are writing an interface servlet which has data passed to it, parses the data and creates the JSON, then sends the JSON to Salesforce. I'm having an issue authenticating. My authorization is as follows:

 

public String getAuth() throws HttpException, IOException, JSONException {
    	//post.addParameter("code",code);
    	HttpClient httpClient = new HttpClient();
    	ServletConfig context = getServletConfig();
    	post = new PostMethod(context.getInitParameter("environment"));
    	
    	System.out.println("environment: " + context.getInitParameter("environment"));
    	System.out.println("clientId: " + context.getInitParameter("clientId"));
    	System.out.println("clientSecret: " + context.getInitParameter("clientSecret"));
    	System.out.println("redirectUri: " + context.getInitParameter("redirectUri"));

    	
        post.addParameter("grant_type","authorization_code");
        post.addParameter("client_id",context.getInitParameter("clientId"));    	
    	post.addParameter("client_secret",context.getInitParameter("clientSecret"));
    	post.addParameter("redirect_uri",context.getInitParameter("redirectUri"));
    	   
    	httpClient = new HttpClient();
    	httpClient.executeMethod(post);
   
    	String responseBody = post.getResponseBodyAsString();
    	
    	System.out.println("response body: " + responseBody);
    	   
    	JSONObject json = null;
    	json = new JSONObject(responseBody);
    	String accessToken = json.getString("access_token");
        //String issuedAt = json.getString("issued_at");
              
       /*HttpServletResponse httpResponse = (HttpServletResponse)response;
       Cookie session = new Cookie("ACCESS_TOKEN", accessToken);
       session.setMaxAge(-1); //cookie not persistent, destroyed on browser exit
       httpResponse.addCookie(session);*/
        
       return accessToken;
    }

I recieve this error back:

{"error":"invalid_grant","error_description":"invalid authorization code"}
I currently have "code" commented out, because I'm not exactly clear on the flow of things. The documentation says you get the authorization code from the redirect_url, but I'm not redirecting to anything, just connecting with this Java servlet. Is there a better way of doing this? Or am I even doing it correctly to start with? Any help would be appreciated.
I'm using the Salesforce REST APIs to created customers (in our case organizations) that can have n-number of agents (users within an organization). Most of them only have 1-2 users, but currently, I have an agent rich text field where I just append every agent with line breaks in between each name because I didn't know a way accomodate for what I was needing. In other words, I would have to create n-number of fields within salesforce, each with a unique field name. Is there a better way to do this?

We are writing an interface servlet which has data passed to it, parses the data and creates the JSON, then sends the JSON to Salesforce. I'm having an issue authenticating. My authorization is as follows:

 

public String getAuth() throws HttpException, IOException, JSONException {
    	//post.addParameter("code",code);
    	HttpClient httpClient = new HttpClient();
    	ServletConfig context = getServletConfig();
    	post = new PostMethod(context.getInitParameter("environment"));
    	
    	System.out.println("environment: " + context.getInitParameter("environment"));
    	System.out.println("clientId: " + context.getInitParameter("clientId"));
    	System.out.println("clientSecret: " + context.getInitParameter("clientSecret"));
    	System.out.println("redirectUri: " + context.getInitParameter("redirectUri"));

    	
        post.addParameter("grant_type","authorization_code");
        post.addParameter("client_id",context.getInitParameter("clientId"));    	
    	post.addParameter("client_secret",context.getInitParameter("clientSecret"));
    	post.addParameter("redirect_uri",context.getInitParameter("redirectUri"));
    	   
    	httpClient = new HttpClient();
    	httpClient.executeMethod(post);
   
    	String responseBody = post.getResponseBodyAsString();
    	
    	System.out.println("response body: " + responseBody);
    	   
    	JSONObject json = null;
    	json = new JSONObject(responseBody);
    	String accessToken = json.getString("access_token");
        //String issuedAt = json.getString("issued_at");
              
       /*HttpServletResponse httpResponse = (HttpServletResponse)response;
       Cookie session = new Cookie("ACCESS_TOKEN", accessToken);
       session.setMaxAge(-1); //cookie not persistent, destroyed on browser exit
       httpResponse.addCookie(session);*/
        
       return accessToken;
    }

I recieve this error back:

{"error":"invalid_grant","error_description":"invalid authorization code"}
I currently have "code" commented out, because I'm not exactly clear on the flow of things. The documentation says you get the authorization code from the redirect_url, but I'm not redirecting to anything, just connecting with this Java servlet. Is there a better way of doing this? Or am I even doing it correctly to start with? Any help would be appreciated.