简体   繁体   English

自定义 Salesforce Lightning 应用程序提供“您无权访问此记录”

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

Custom Lightning App named "Stack" giving "You dont have access to this record Contact " Trying to follow steps in How To Implement Full Search in Case Type using Salesforce?名为“堆栈”的自定义 Lightning 应用程序提供“您无权访问此记录联系人” 尝试按照如何使用 Salesforce 在案例类型中实施完整搜索中的步骤进行操作?

在此处输入图片说明

Here is Org wide defaults of the custom object ERT Case Type data这是自定义对象 ERT 案例类型数据的组织范围默认值在此处输入图片说明

Here is Apex code of stack.aspx这是stack.aspx的Apex代码

                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;
                    } 

                }

Here is Aura component (html part)这是Aura 组件(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>

Here is Aura component - JS controller part这是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
   }
})

Please help me in removing this access error请帮助我消除此访问错误

Regards, Carolyn问候, 卡罗琳

I doubt it's sharing related (so not the org-wide settings).我怀疑它与共享相关(所以不是组织范围的设置)。 If it was sharing it'd simply always return 0 results but no big red errors.如果它是共享的,它只会总是返回 0 结果,但没有大的红色错误。

If you remove the line with <c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/> does the error go away?如果删除带有<c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" onSelection="{!c.useSelected}" errors="{!v.errors}" label="Search" placeholder="Search Case Types Data"/>错误是否消失? If it stays - it's problem with permissions around the custom code or Case_Type_Data__c ).如果它仍然存在 - 自定义代码或Case_Type_Data__c周围的权限有问题)。 If it goes away - it's something with creating ERT_Case_Type__c )如果它消失了 - 这是创建ERT_Case_Type__c的事情)

Check the Profile (or Permission Sets if you use them) rights to:检查配置文件(或权限集,如果您使用它们)权限以:

  • Read the source object ( Case_Type_Data__c ) and all referenced fields ( Level_1__c ...)读取源对象( Case_Type_Data__c )和所有引用的字段( Level_1__c ...)
  • Create the target object ( ERT_Case_Type__c ) and read/edit all referenced fields ( Level1__c ... but also Case__c )创建目标对象( ERT_Case_Type__c )并读取/编辑所有引用的字段( Level1__c ... 还有Case__c
  • Read on the Case object and Case.CaseNumber , Case.Subject fields阅读Case对象和Case.CaseNumber , Case.Subject字段
  • Permission to execute the Apex class (renamed to Stack , right?).执行 Apex 类的权限(重命名为Stack ,对吗?)。 And maybe add permission to run LookupSearchResult too.也可能添加运行LookupSearchResult权限。

I suspect you have enabled some critical updates (Setup -> Critical updates or Setup -> Release Updates) like "Restrict Access to @AuraEnabled Apex Methods for Authenticated Users Based on User Profile" or "Require Permission to View Record Names in Lookup Fields"我怀疑您启用了一些关键更新(设置 -> 关键更新或设置 -> 发布更新),例如“根据用户配置文件限制对经过身份验证的用户的 @AuraEnabled Apex 方法的访问”或“需要在查找字段中查看记录名称的权限”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM