SalesForce中的Http Request和iFrame问题,INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY

时间:2015-12-08 14:58:37

标签: angularjs servlets iframe permissions salesforce

这是我的问题,我在SalesForce中创建了一个应用程序,它对我很有用。我有管理员权限,在这个应用程序中我有一个引用SF,servlet文件阅读器的iFrame,当我作为管理员登录时调用它它工作得很好但是当我尝试使用标准用户时我得到以下错误:

  

拒绝展示           ' https://myDomain.salesforce.com/servlet/servlet.FileDownload?file=00PG000000UCL0CMAX'   在一个框架中因为它设置了X-Frame-Options'到' SAMEORIGIN'。

这是第一个问题,第二个是Http请求,我通过Http请求创建一个AngularJS附件,再次以管理员身份登录时工作正常但是对于标准用户我得到了以下错误:

  

POST   https://myDomain.salesforce.com/services/data/v26.0/sobjects/Attachment/   400(不良请求)

对于这篇特别的文章,我正在配置http请求,如下所示:

app.run(['$http', '$window', function($http, $window) {

    /*Get the '{!GETSESSIONID()}' value cannot be processed on static ressource, 
            hence the link to the window global variable.*/
    var sessionId = $window.__sfdcSessionId;

    $http.defaults.useXDomain = true;
    delete $http.defaults.headers.common["X-Requested-With"];

    /* In order for this to work the domain has to be white-listed within
            SalesForce security Settings > CORS */
    $http.defaults.headers.common["Access-Control-Allow-Origin"] = "*";
    $http.defaults.headers.common["Accept"] = "application/json";
    $http.defaults.headers.common["Content-Type"] = "application/json";
    //Session ID necessary for authentication purposes.
    $http.defaults.headers.common['Authorization'] = "OAuth " + sessionId;
    $http.defaults.headers.common['X-User-Agent'] = "MyClient";
}]);

同样适用于管理员但不适用于标准用户。 任何想法,我认为它与许可有关,但我显然不想给每个人提供管理员权限......我不确定问题的真正来源,任何建议?

更新:通过网络通话,我能够获得有关错误请求的更准确错误:

  

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY

Network Request and Responsee

所以我知道这与权限有关,但无法弄清楚,确切地做些什么使其适用于所有用户而不仅仅是管理员......有什么建议吗?

我附加了进行调用的实际AngularJS函数:

attachment.save = function(base64value,document){

    /*Stripping the file type text in front of the base64 
        string, without this the file would show as corrupted */
    var position = base64value.indexOf("base64,");
    var matchWord = "base64,";
    var base64valueClean = base64value.slice(position + matchWord.length, base64value.length);

    //Setting payload to be saved in SF database.
    var data = {
        "Body": base64valueClean,
        "ContentType": document.attachmentContentType,
        "ParentId": document.id,
        "Name": document.fileName
    };

    var requestHeaders = {
            'Timeout': '600',
            'Content-Type': 'application/json',
            'Authorization': 'Bearer ' + $window.__sfdcSessionId
        };


    /*Get the {!URLFOR('/services/data/v26.0/sobjects/Attachment/')} value
        cannot be processed on static ressource, hence the link to the window
        global variable.*/
    var url = $window.__url;
    var method = 'POST';

    /* May be useful in future
    //Allows this function to be used for updates as well as insert
    var isUpdate = ($.trim(document.attachmentId) !==);
    if (isUpdate) {
        url = url + document.attachmentId;
        method = 'PATCH';
    } else {
        // Method for creation
        method = 'POST';
    };*/

    //Request system data
    var request = {

        url: url,
        method: method,
        data: data,
        requestHeaders: requestHeaders

    };

    console.log(request);

    //Promise type approach to Http request, allows easy handle of succes and failure
    // Very useful for asynchronous calls.
    var deferred = $q.defer();

    //Performing http request to Server
    $http(request).then(function(response) {

        deferred.resolve(response);
        console.log('File UPLOADED to SF!');

    }, function(event) {

        //Need to Improve error handling!!!
        deferred.reject('The attachment could not be saved:' + event);

    });


    return deferred.promise;
}

1 个答案:

答案 0 :(得分:0)

嗯,这一切都归结为Profile中的权限。用户没有与此附件关联的父对象的读写权限。

我改变了它,现在它的作用就像一个魅力......不像我想的那样令人费解!