/**
   * Helper methods to create "count" of test records
   *
   * @param count
   * @return map of id to name for the created accounts
   * @throws Exception
   */
  protected Map<String, String> createRecordsOnServer(int count, String objectType)
      throws Exception {
    Map<String, String> idToValues = new HashMap<String, String>();
    for (int i = 0; i < count; i++) {

      // Request.
      String fieldValue = createRecordName(objectType);
      Map<String, Object> fields = new HashMap<String, Object>();
      // add more object type if need to support to use this API
      // to create a new record on server
      switch (objectType) {
        case Constants.ACCOUNT:
          fields.put(Constants.NAME, fieldValue);
          break;
        case Constants.OPPORTUNITY:
          fields.put(Constants.NAME, fieldValue);
          fields.put("StageName", "Prospecting");
          DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
          fields.put("CloseDate", formatter.format(new Date()));
          break;
        default:
          break;
      }

      RestRequest request =
          RestRequest.getRequestForCreate(
              ApiVersionStrings.getVersionNumber(targetContext), objectType, fields);

      // Response.
      RestResponse response = restClient.sendSync(request);
      assertNotNull("Response should not be null", response);
      assertTrue("Response status should be success", response.isSuccess());
      String id = response.asJSONObject().getString(LID);
      idToValues.put(id, fieldValue);
    }
    return idToValues;
  }
  /**
   * @param response returned by soap soql request - also sets totalSize field
   * @return
   */
  private JSONArray parseSoapResponse(RestResponse response) {
    JSONArray records = null;
    try {
      XmlPullParser parser = Xml.newPullParser();
      parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
      parser.setInput(new ByteArrayInputStream(response.asBytes()), null);

      JSONObject record = null;
      boolean inDocument = true;
      boolean inResults = false;
      boolean inRecord = false;
      boolean queryDone = false;

      while (inDocument) {
        int next = parser.next();

        switch (next) {
          case XmlPullParser.START_TAG:
            Log.i("----> Starting TAG", parser.getName());

            if (parser.getName().equals(RESULT)) {
              inResults = true;
              records = new JSONArray();
            } else if (inResults && parser.getName().equals(RECORDS)) {
              inRecord = true;
              record = new JSONObject();
            } else if (inResults && parser.getName().equals(DONE)) {
              queryDone = Boolean.parseBoolean(parser.nextText());
            } else if (inResults && parser.getName().equals(QUERY_LOCATOR)) {
              queryLocator = queryDone ? null : parser.nextText();
            } else if (inResults && parser.getName().equals(SIZE)) {
              totalSize = Integer.parseInt(parser.nextText());
            } else if (inRecord && parser.getName().startsWith(SF)) {
              String attributeName = parser.getName().substring(SF.length());
              String attributeValue = parser.nextText();
              if (attributeName.equals(TYPE)) {
                JSONObject t = new JSONObject();
                t.put(TYPE, attributeValue);
                record.put(Constants.ATTRIBUTES, t);
              } else {
                record.put(attributeName, attributeValue);
              }
            }
            break;

          case XmlPullParser.END_TAG:
            Log.i("----> Ending TAG", parser.getName());

            if (inRecord && parser.getName().equals(RECORDS)) {
              inRecord = false;
              records.put(record);
            } else if (inResults && parser.getName().equals(RESULT)) {
              inResults = false;
            }
            break;

          case XmlPullParser.END_DOCUMENT:
            inDocument = false;
            break;
        }
      }

      totalSize = records.length();
    } catch (Exception e) {
      Log.e("ContentSoqlSyncDownTarget:parseSoapResponse", "Parsing failed", e);
    }

    return records;
  }