自定义 Salesforce Lightning 应用程序给予 "You dont have access to this record"

Custom Salesforce Lightning App giving "You dont have access to this record"

名为“Stack”的自定义 Lightning 应用给出“您无权访问此记录联系人” 尝试按照

中的步骤操作

这是自定义对象 ERT 案例类型数据的组织范围默认值

这是 Apex stack.aspx

的代码
                public class Stack {
                      @AuraEnabled(cacheable=true)
                    public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds){
                        if(String.isBlank(searchTerm) || searchTerm.length() < 2){
                            return null;
                        }
                        String t = '%' + searchTerm + '%'; // decide how you want to search, "starts with", "includes" or what
                        
                        List<ERT_Case_Type_Data__c> records = [SELECT Id, Name, Level_1__c, Level_2__c, Level_3__c
                            FROM ERT_Case_Type_Data__c
                            WHERE Level_1__c LIKE :t OR Level_2__c LIKE :t OR Level_3__c LIKE :t
                            ORDER BY Level_1__c, Level_2__c, Level_3__c
                            LIMIT 20];
                        
                        /* You could also experiment with SOSL?
                        records =  [FIND :('*' + searchTerm + '*') IN ALL FIELDS 
                            RETURNING Case_Type_Data__c(Id, Name, Level_1__c, Level_2__c, Level_3__c)][0];
                        */
                        
                        List<LookupSearchResult> results = new List<LookupSearchResult>();
                        for(ERT_Case_Type_Data__c ctd : records){
                            results.add(new LookupSearchResult(ctd.Id, 'ERT_Case_Type_Data__c', 'standard:case_wrap_up', ctd.Name,
                                String.join(new List<String>{ctd.Level_1__c , ctd.Level_2__c, ctd.Level_3__c}, '; ')
                            ));
                        }
                        return results;
                    } 

                }

这里是光环成分(html部分)

                <aura:component implements="force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="Stack">
                    <aura:attribute access="global" type="List" name="selection" default="[]"/>
                    <aura:attribute access="global" type="List" name="errors" default="[]"/>

                    <lightning:card title="New Case Type">
                        
                        <lightning:recordEditForm aura:id="myForm" objectApiName="ERT_Case_Type__c" onsubmit="{!c.onSubmit}" onsuccess="{!c.onSuccess}">
                        <lightning:messages />
                        <c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/>
                        <lightning:inputField aura:id="Level_1__c" fieldName="Level_1__c" />
                        <lightning:inputField aura:id="Level_2__c" fieldName="Level_2__c" />
                        <lightning:inputField aura:id="Level_3__c" fieldName="Level_3__c" />
                        <lightning:button class="slds-m-top_small" variant="brand" type="submit" name="save" label="Save" />
                    </lightning:recordEditForm>
                    </lightning:card>
                </aura:component>

这里是Aura组件-JS控制器部分

({
    lookupSearch : function(component, event, helper) {
    // Get the lookup component that fired the search event
    const lookupComponent = event.getSource();
    const serverSearchAction = component.get('c.search');
    lookupComponent.search(serverSearchAction);
},

useSelected: function(component, event, helper) {
    const selection = component.get('v.selection');
    const errors = component.get('v.errors');
    
    if (selection.length) {
        if(errors.length){  // Clear errors, if any
            component.set('v.errors', []);
        }
        let levels = selection[0].subtitle.split('; ');
        component.find('Level_1__c').set('v.value', levels[0]);
        component.find('Level_2__c').set('v.value', levels[1]);
        component.find('Level_3__c').set('v.value', levels[2]);
    }
},
onSubmit: function(component, event, helper) {
    debugger;
    event.preventDefault();       // stop the form from submitting
    var fields = event.getParam('fields');
    fields.Case__c = component.get('v.recordId'); // link to "this" Case
    component.find('myForm').submit(fields);
},
onSuccess: function(component, event, helper){
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
        "title": "Success!",
        "message": "Case Type saved OK, refreshing",
        "type": "success"
    });
    toastEvent.fire();
    $A.get('e.force:refreshView').fire(); // reload page
   }
})

请帮我消除这个访问错误

此致, 卡罗琳

我怀疑它与共享相关(因此与 org-wide 设置无关)。如果它是共享的,它总是 return 0 个结果,但没有大的红色错误。

如果删除带有 <c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/> 的行,错误会消失吗?如果它仍然存在 - 这是自定义代码或 Case_Type_Data__c 周围的权限问题。如果它消失了——那就是创建 ERT_Case_Type__c)

检查配置文件(或权限集,如果您使用它们)权限:

  • 读取源对象 (Case_Type_Data__c) 和所有引用的字段 (Level_1__c...)
  • 创建目标对象 (ERT_Case_Type__c) 和 read/edit 所有引用字段 (Level1__c... 还有 Case__c)
  • 读取 Case 对象和 Case.CaseNumberCase.Subject 字段
  • 执行 Apex 的权限 class(重命名为 Stack,对吧?)。也许也可以添加对 运行 LookupSearchResult 的权限。

我怀疑您启用了一些关键更新(设置 -> 关键更新或设置 -> 发布更新),例如“根据用户配置文件限制经过身份验证的用户对 @AuraEnabled Apex 方法的访问”或“需要权限才能查看记录”查找字段中的名称