Skip to main content

https://github.com/takahitomiyamoto/lwc-basic/wiki/Intermediate-Level-3

↑こちらの中級のlevel3に取り組んでいるのですが以下のソースでOpportunityControllerクラスを記述し自身のプレイグラウンド環境にデプロイしてもreturnのところでValidate CRUD permission before SOQL/DML operationというエラーがでてきてしまいデプロイに失敗してしまいます。また、解決方法を調べて出てきた以下のソースを追加して記述してもまた別のエラーがでてしまいます。

 if(               Contact.SObjectType.getDescribe().isAccessible() &&               Schema.SObjectType.Contact.fields.Name.isAccessible() &&               Schema.SObjectType.Contact.fields.Phone.isAccessible()       ) {

こちらの問題についてご教示いただけますと幸いです。

よろしくお願いいたします。

public with sharing class OpportunityController {

@AuraEnabled(cacheable=true)

public static List<Opportunity> findOpportunities(String searchKey) {

String key = '%' + searchKey + '%';

return [

SELECT Id, Name, Amount, StageName

FROM Opportunity

WHERE Name LIKE :key

LIMIT 50000

];

}

2 respuestas
  1. 7 nov 2022, 21:06

    @彪 松本 さん

     

    VSCode の PMD ソース コード アナライザーから SOQL の前に CRUD 権限を確認するようにという上記の警告が表示されます。この警告は基本的に、SOQL クエリを実行する前に、現在のユーザがアクセスまたはクエリしているオブジェクトと項目にアクセスできることを確認することを示唆しています。この警告を削除するには、次のような多くのコードを追加する必要があります:- 

     

    I am getting the above warning to check CRUD permissions before SOQL from my PMD source code analyzer in VSCode. This warning basically suggests us to make sure that the current user has access to the object and fields that we're accessing or querying before executing the SOQL query. To remove this warning, we need to add a lot of code like:- 

     

    https://www.sfdcstop.com/2020/03/validate-crud-permission-before-soqldml.html

0/9000