+ Start a Discussion
Sandeep AgrawalSandeep Agrawal 

Post to chatter

I am trying to post on chatter wall,chatter user, chatter group.

 

When I posting on chatter wall, I am sending 1000 character but it is taking less than 1000 character and posting on chatter wall.

 

When I am posting on chatter user and selecting the multiple user than it is posting random character there and giving below error:

08-30 18:31:17.867: V/Noteprise(3238): Response for user[{"message":"Text is too large.","errorCode":"STRING_TOO_LONG"}]
08-30 18:31:17.867: V/Noteprise(3238): [{"message":"Text is too large.","errorCode":"STRING_TOO_LONG"}]

  I am using chatter rest api with latest salesforce Android Sdk.

 

How to calculate the length of character which we can post on the basic of number of user. There may be multiple user which I can select and post chatter .

 

On what factor content length depends like user name or something else?

 

I am using below code :

public static RestResponse publishNoteWithUserMentions(RestClient salesforceRestClient, String noteContent, String SF_API_VERSION, ArrayList<String> selectedIds)
	{
		RestResponse publishResponse = null;
		if (salesforceRestClient != null)
		{
			try 
			{				
				StringEntity stringEntity = new StringEntity(generateJSONBodyForChatterFeed(noteContent, selectedIds));
				stringEntity.setContentType("application/json");
				String url = "/services/data/" + SF_API_VERSION + "/chatter/feeds/news/me/feed-items";
				NotepriseLogger.logMessage(url);
				publishResponse = salesforceRestClient.sendSync(RestMethod.POST, url, stringEntity);
			} 
			catch (UnsupportedEncodingException e) 
			{
				NotepriseLogger.logError("UnsupportedEncodingException while publishing chatter feed.", NotepriseLogger.ERROR, e);
			} 
			catch (IOException e) 
			{
				NotepriseLogger.logError("IOException while publishing chatter feed.", NotepriseLogger.ERROR, e);
			}	
		}
		return publishResponse;
	}
	
	public static String generateJSONBodyForChatterFeed(String content, ArrayList<String> mentionIds)
	{
		JSONArray msg = new JSONArray();
		String bodyString = null;
		try 
		{			
			if (mentionIds != null)
			{
				for (int i = 0; i < mentionIds.size(); i++)
				{
					JSONObject mention = new JSONObject();				
					mention.put("type", "mention");
					mention.put("id", mentionIds.get(i));
					msg.put(mention);
				}				
			}
			if (content != null)
			{
				content = URLEncoder.encode(content, "UTF-8");
				JSONObject text = new JSONObject();
				text.put("type", "text");
				text.put("text", " " + content);
				msg.put(text);
			}			
			JSONObject body = new JSONObject();
			body.putOpt("body", new JSONObject().put("messageSegments", msg));
			bodyString = body.toString();				
			NotepriseLogger.logMessage(bodyString);			
		}  
		catch (JSONException e) 
		{
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return bodyString;
	}

 I will appreciate any kind of help.

Thanks