Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cd4bb0a
Byttet custom metadata type
torhakon Jan 13, 2025
e580005
Custom metadata type for test
torhakon Jan 13, 2025
c497cfe
Oppdaterte pakke navn
torhakon Jan 13, 2025
51de510
Flyttet filene til classes
torhakon Jan 13, 2025
917d098
Fjernet filter som ikke fungerte
torhakon Jan 13, 2025
98f054b
Merge branch 'main' into customDaoFix
torhakon Jan 13, 2025
41ff188
Fjernet avhengighet i testen til en faktisk custom metadata type
torhakon Jan 14, 2025
ba31ee2
Merge branch 'main' into customDaoFix
torhakon Jan 14, 2025
23be4d9
La til since
torhakon Jan 14, 2025
da1e9ed
Merge branch 'main' into customDaoFix
torhakon Jan 14, 2025
d161e50
justering av kommentarer
torhakon Jan 14, 2025
74621bd
Merge branch 'main' into customDaoFix
torhakon Jan 14, 2025
250f86d
La til with inherited sharing
torhakon Jan 14, 2025
fc2c74f
Merge branch 'main' into customDaoFix
torhakon Jan 14, 2025
2b0c211
Fikse mindre skrivefeil
torhakon Jan 14, 2025
c2aecd5
Merge branch 'main' into customDaoFix
torhakon Jan 14, 2025
a5eec57
sette test metode til private
torhakon Jan 14, 2025
f22cbc2
Endret til ny equals type
torhakon Jan 14, 2025
fa55e57
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
a201faf
Fikset javadoc token
torhakon Jan 16, 2025
1ac9f34
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
566d4d7
Legge til paralell kjøriung av tester
torhakon Jan 16, 2025
7429ab9
justere pakke struktur
torhakon Jan 16, 2025
7ad0d0c
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
d0c33f1
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
3b18c85
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
e9bdb16
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
23a0756
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
ca64609
Merge branch 'main' into customDaoFix
torhakon Jan 16, 2025
f0b0e09
Merge branch 'main' into customDaoFix
torhakon Jan 17, 2025
41aff2e
Oppdatert sfdx-project.json fil
torhakon Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
{
"path": "src/platform-admin",
"package": "platform-admin",
"versionNumber": "0.0.0.NEXT",
"definitionFile": "config/project-scratch-def.json"
"versionNumber": "0.0.0.NEXT"
},
{
"path": "src/platform-utility",
"package": "platform-utility",
"versionName": "ver 0.1",
"versionNumber": "0.1.0.NEXT",
"path": "src/platform-utility/CustomMetadataDAO",
"default": false,
"versionDescription": "Package containing the core platform utilities.",
"definitionFile": "config/project-scratch-def.json"
"package": "custom-metadata-dao",
"versionDescription": "Custom Metadata Data Access Object class used to get access to Custom Metadata objects, and at the same time make it easier to test the various paths the code can take based on the values in the Custom Metadata."
}
],
"packageAliases": {
"platform-data-model": "0HoKB00000000010AA"
"platform-data-model": "0HoKB00000000010AA",
"custom-metadata-dao": "0HoKB000000000B0AQ"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @example
* List<CustomMetadata__mdt> nameCMList = (List<CustomMetadata__mdt>) new CustomMetadataDAO()
* .getCustomMetadataRecords(
* 'SELECT MasterLable, CustomField__c ' +
* 'SELECT MasterLabel, CustomField__c ' +
* 'FROM CustomMetadata__mdt ' +
* 'WHERE DeveloperName = \'Name\''
* );
Expand All @@ -25,8 +25,7 @@
* name = nameCMList[0];
* }
*/
@SuppressWarnings('PMD.ApexSharingViolations')
public class CustomMetadataDAO {
public inherited sharing class CustomMetadataDAO {
/**
* @description Is used to set the Custom Metadata Records in Unit Tests.
*
Expand All @@ -42,7 +41,7 @@ public class CustomMetadataDAO {
* @author Kenneth Soerensen ([email protected]), NAV
* @since 0.1.0, August 2024
* @param query The SOQL query string to fetch the Custom Metadata Records.
* @returns Return a list of Custom Metadata Records as `List<SObject>`
* @return Return a list of Custom Metadata Records as `List<SObject>`
* @example
* List<CustomMetadata__mdt> nameCMList = (List<CustomMetadata__mdt>) new CustomMetadataDAO()
* .getCustomMetadataRecords(
Expand All @@ -57,14 +56,10 @@ public class CustomMetadataDAO {
* }
*/
public List<SObject> getCustomMetadataRecords(String query) {
System.debug(LoggingLevel.DEBUG, 'query: ' + query);
System.debug(
LoggingLevel.DEBUG,
'customMetadataRecordsMap: ' + customMetadataRecordsMap
);
if (!customMetadataRecordsMap.containsKey(query)) {
customMetadataRecordsMap.put(query, Database.query(query));
}

return customMetadataRecordsMap.get(query);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @description This is the test class for the Custom Metadata Data Access Object class.
* <br><br>
* Inspiration for this way of solving the problem is taken form the article
* "Get 100% Code Coverage for Salesforce Custom Metadata Based Decisions".
*
* @author Kenneth Soerensen ([email protected]), NAV
* @since 0.1.0, August 2024
*
* @author Tor Håkon Sigurdsen, Nav
* @since 2025-01-14 - Made tests independent from Custom Metadata types in the orgs
*
* @group Custom Metadata DAO
* @see CustomMetadataDAO
* @see [Get 100% Code Coverage for Salesforce Custom Metadata Based Decisions](https://www.avenga.com/magazine/salesforce-custom-metadata/)
* @example
* CustomMetadataDAOTest.setMetadata(
* 'SELECT MasterLabel ' +
* 'FROM CustomMetadata__mdt ' +
* 'WHERE DeveloperName = \'Name\'',
* (List<CustomMetadata__mdt>) JSON.deserialize(
* '[{"attributes": {"type": "CustomMetadata__mdt"},"MasterLabel":"Value"}]',
* List<CustomMetadata__mdt>.class)
* );
*
* List<CustomMetadata__mdt> nameCMList = (List<CustomMetadata__mdt>) new CustomMetadataDAO()
* .getCustomMetadataRecords(
* 'SELECT MasterLable, CustomField__c ' +
* 'FROM CustomMetadata__mdt ' +
* 'WHERE DeveloperName = \'Name\''
* );
*
* CustomMetadata__mdt name;
* if (nameCMList.size() > 0) {
* name = nameCMList[0];
* }
*/
@IsTest(IsParallel=true)
public class CustomMetadataDAOTest {
/**
* @description Simple test for the getMetadata method.
*/
@IsTest
private static void testGetMetadata() {
List<SObject> customMetadataRecords;
String query =
'SELECT MasterLabel ' +
'FROM CustomMetadata__mdt ' +
'WHERE DeveloperName = \'Name\'';

// We set the type to Account in order to not be dependent on any Custom Metadata types
CustomMetadataDAOTest.setMetadata(
query,
(List<SObject>) JSON.deserialize(
'[{"attributes": {"type": "Account"},"MasterLabel":"Label"}]',
List<SObject>.class
)
);

System.Test.startTest();
customMetadataRecords = new CustomMetadataDAO()
.getCustomMetadataRecords(query);
System.Test.stopTest();
System.Assert.areEqual(
1,
customMetadataRecords.size(),
'Size should match'
);
}

/**
* @description A utility method to set custom metadata records for the tests.
*
* @author Kenneth Soerensen ([email protected]), NAV
* @since 0.1.0, August 2024
* @param query The SOQL query string to fetch the Custom Metadata Records.
* @param records Set Custom Metadata Records for the tests.
* @example
* CustomMetadataDAOTest.setMetadata(
* 'SELECT MasterLabel ' +
* 'FROM CustomMetadata__mdt ' +
* 'WHERE DeveloperName = \'Name\'',
* (List<CustomMetadata__mdt>) JSON.deserialize(
* '[{"attributes": {"type": "CustomMetadata__mdt"},"MasterLabel":"Value"}]',
* List<CustomMetadata__mdt>.class)
* );
*
* List<CustomMetadata__mdt> nameCMList = (List<CustomMetadata__mdt>) new CustomMetadataDAO()
* .getCustomMetadataRecords(
* 'SELECT MasterLabel ' +
* 'FROM CustomMetadata__mdt ' +
* 'WHERE DeveloperName = \'Name\''
* );
*
* CustomMetadata__mdt name;
* if (nameCMList.size() > 0) {
* name = nameCMList[0];
* }
*/
public static void setMetadata(String query, List<SObject> records) {
CustomMetadataDAO.customMetadataRecordsMap.put(query, records);
}
}
Loading