3

I'm trying to patch a salesforce object using angular, but am getting no where. Every time I get a nondescript error.

salesforce.patch = function(resource, contentType, data) {
  var http = angular.injector(['ng']).get('$http');
  var defered = angular.injector(['ng']).get('$q').defer();
  var log = angular.injector(['ng']).get('$log');

  var upload = function() {
    log.info('Salesforce - Posting resource \'' + resource + '\'.');

    var url = salesforce.proxy.url + resource;
    http({
      method: 'PATCH',
      url: url,
      headers: {
        'Authorization': salesforce.user.accessTokenType + ' ' + salesforce.user.accessToken,
        'Content-Type': contentType,
        'Target-URL': salesforce.user.url
      },
      data: data
    }).success(function(data) {
      defered.resolve(data);
    }).error(function(error) {
      log.error('Salesforce - Failed to post resource \'' + resource + '\'.');
      salesforce.logApiError(log, error);
      defered.reject();
    });
  };

  salesforce.authenticate().then(upload).catch(defered.reject);

  return defered.promise;
};
  • Try using 'GET' as the httpmethod and append ?_HttpMethod=PATCH to the URL. I know in apex you have to do it this way – Eric Oct 2 '15 at 21:17
  • This didn't work. Isn't GET a retrieval method? – Dan Nelson Oct 2 '15 at 21:43
  • Yes, but in apex there is not 'Patch" method so you have to hack it. Was just a stab at it – Eric Oct 2 '15 at 21:49
  • 1
    What exactly is the nondescript error text that you are getting? – Mark Pond Oct 2 '15 at 23:04
  • It's nondescript, as in there's no error description. The client I'm working for has a low end version of Salesforce that does not include API errors as a feature from what I'm told. – Dan Nelson Oct 2 '15 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.