From 901e0e54cdb3f4903c28f6cc20b9f48ace96ee30 Mon Sep 17 00:00:00 2001 From: hrk623 <981792+hrk623@users.noreply.github.com> Date: Tue, 5 Mar 2024 11:57:13 +0900 Subject: [PATCH] Fixed Config Error on None-Record-Detail Exp Page (#11) --- .../searchCardClassic/searchCardClassic.js | 1 - .../v2/shared/classes/SchemaDataService.cls | 16 +++++++++------ .../shared/classes/TestSchemaDataService.cls | 13 +++++++++++- package-lock.json | 20 ------------------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/force-app/main/v2/search/lwc/searchCardClassic/searchCardClassic.js b/force-app/main/v2/search/lwc/searchCardClassic/searchCardClassic.js index 0c39b96..f1e96e2 100644 --- a/force-app/main/v2/search/lwc/searchCardClassic/searchCardClassic.js +++ b/force-app/main/v2/search/lwc/searchCardClassic/searchCardClassic.js @@ -37,7 +37,6 @@ export default class SearchCardClassic extends LightningElement { if (data && !data.hasError) { // eslint-disable-next-line @lwc/lwc/no-api-reassignments this.objectApiName = data.body; - console.log("this.objectApiName", this.objectApiName); } else if (data && data.hasError) { this.showConfigurationError(data.errorMessage); } else if (error) { diff --git a/force-app/main/v2/shared/classes/SchemaDataService.cls b/force-app/main/v2/shared/classes/SchemaDataService.cls index deae68a..1c7f393 100644 --- a/force-app/main/v2/shared/classes/SchemaDataService.cls +++ b/force-app/main/v2/shared/classes/SchemaDataService.cls @@ -17,12 +17,16 @@ public with sharing class SchemaDataService extends DataService { @AuraEnabled(cacheable=true) public static Result getObjectApiNameById(String recordId) { try { - return new Result( - ((ID) recordId) - .getSObjectType() - .getDescribe(SObjectDescribeOptions.DEFERRED) - .getName() - ); + if (String.isBlank(recordId)) { + return new Result(''); + } else { + return new Result( + ((ID) recordId) + .getSObjectType() + .getDescribe(SObjectDescribeOptions.DEFERRED) + .getName() + ); + } } catch (Exception e) { return new Result('', e.getMessage()); } diff --git a/force-app/main/v2/shared/classes/TestSchemaDataService.cls b/force-app/main/v2/shared/classes/TestSchemaDataService.cls index 767f526..d246d5f 100644 --- a/force-app/main/v2/shared/classes/TestSchemaDataService.cls +++ b/force-app/main/v2/shared/classes/TestSchemaDataService.cls @@ -15,11 +15,22 @@ public class TestSchemaDataService { static void getObjectApiNameById() { User u = [SELECT Id, LastName FROM User LIMIT 1][0]; String userId = u.Id; - DataService.Result result = SchemaDataService.getObjectApiNameById(userId); String objectApiName = (String) result.body; System.assertEquals('User', objectApiName); } + @isTest + static void getObjectApiNameByIdWhenRecordIdIsNull() { + DataService.Result result = SchemaDataService.getObjectApiNameById(null); + String objectApiName = (String) result.body; + System.assertEquals('', objectApiName); + } + @isTest + static void getObjectApiNameByIdWhenRecordIdIsEmpty() { + DataService.Result result = SchemaDataService.getObjectApiNameById(''); + String objectApiName = (String) result.body; + System.assertEquals('', objectApiName); + } // TEST: Result getFieldInfo(String objectApiName, String fieldApiName) @isTest diff --git a/package-lock.json b/package-lock.json index fc55fe0..4a82922 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,6 @@ "@salesforce/eslint-plugin-lightning": "^1.0.0", "@salesforce/sfdx-lwc-jest": "^1.1.0", "eslint": "^8.11.0", - "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.25.4", "eslint-plugin-jest": "^26.1.2", "husky": "^7.0.4", @@ -3932,18 +3931,6 @@ "url": "https://opencollective.com/eslint" } }, - "node_modules/eslint-config-prettier": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz", - "integrity": "sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA==", - "dev": true, - "bin": { - "eslint-config-prettier": "bin/cli.js" - }, - "peerDependencies": { - "eslint": ">=7.0.0" - } - }, "node_modules/eslint-import-resolver-node": { "version": "0.3.7", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz", @@ -13252,13 +13239,6 @@ } } }, - "eslint-config-prettier": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz", - "integrity": "sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA==", - "dev": true, - "requires": {} - }, "eslint-import-resolver-node": { "version": "0.3.7", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.7.tgz",