Skip to content

Commit

Permalink
Merging branch WI-000030
Browse files Browse the repository at this point in the history
  • Loading branch information
Szandor72 committed Jan 17, 2024
2 parents ddbedd6 + 1dfeb20 commit c821545
Show file tree
Hide file tree
Showing 22 changed files with 744 additions and 219 deletions.
8 changes: 6 additions & 2 deletions .ci/legacy-metadata-files.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
force-app/main/default/classes/AccountService.cls
force-app/main/default/classes/AccountService.cls-meta.xml
# Add all files that should be treated as legacy files here, e.g.:
# force-app/main/default/classes/ContentDocumentTriggerHandler.cls
force-app/main/default/objects/Contact/fields/Faulty_Url_Field__c.field-meta.xml
force-app/main/default/flexipages/Custom_Contact_Record_Page.flexipage-meta.xml
force-app/main/default/flows/UpdateVIPStatus.flow-meta.xml
force-app/main/default/classes/AccountService.cls
20 changes: 10 additions & 10 deletions .github/workflows/validate-code.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Code Scans with SFDX Scanner

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- 'force-app/**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- "force-app/**"

jobs:
sfdx-scanner:
name: 'Validate Code'
uses: 'Szandor72/devops-center-actions/.github/workflows/validate-code.yml@main'
secrets: inherit
sfdx-scanner:
name: "Validate Code"
uses: "Szandor72/devops-center-actions/.github/workflows/validate-code.yml@main"
secrets: inherit
20 changes: 10 additions & 10 deletions .github/workflows/validate-deployment.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Validate Deployment

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- 'force-app/**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- "force-app/**"

jobs:
validate-deployment:
name: 'SFDX Scanner'
uses: 'Szandor72/devops-center-actions/.github/workflows/validate-deployment.yml@main'
secrets: inherit
validate-deployment:
name: "SFDX Scanner"
uses: "Szandor72/devops-center-actions/.github/workflows/validate-deployment.yml@main"
secrets: inherit
18 changes: 9 additions & 9 deletions .github/workflows/validate-metadata.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Custom Metadata Checks

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- 'force-app/**'
pull_request:
types: [opened, synchronize, reopened]
branches:
- integration
paths:
- "force-app/**"

jobs:
validate-metadata:
name: 'Validate Metadata'
uses: 'Szandor72/devops-center-actions/.github/workflows/validate-metadata.yml@main'
validate-metadata:
name: "Validate Metadata"
uses: "Szandor72/devops-center-actions/.github/workflows/validate-metadata.yml@main"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ deploy-options.json
**/aura/.eslintrc.json
**/lwc/.eslintrc.json
jest.config.cjs
!.ci/legacy-metadata-files.txt
.ci
package.xml


# LWC VS Code autocomplete
Expand Down
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
20 changes: 10 additions & 10 deletions config/project-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"orgName": "Demo company",
"edition": "Developer",
"features": ["EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
}
"orgName": "Demo company",
"edition": "Developer",
"features": ["EnableSetPasswordInApi"],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
}
}
}
132 changes: 68 additions & 64 deletions demo-classes/AccountService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,82 @@
* Provides various services related to Account object
*/
public class AccountService {
/**
* Fetches details for a given account
* @param accountId The ID of the account
* @return Account The details of the account
*/
public Account getAccDetails(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
return acc;
}
return null;
/**
* Fetches details for a given account
* @param accountId The ID of the account
* @return Account The details of the account
*/
public Account getAccDetails(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
return acc;
}
return null;
}

public Account getAccDetails2(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
update acc;
return acc;
}
return null;
public Account getAccDetails2(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
update acc;
return acc;
}
return null;
}

// This method lacks ApexDocs
public void UpdateAccount(List<Account> accounts) {
// DML operation inside a loop - bad practice
for (Account acc : accounts) {
acc.Name += ' - Updated';
update acc; // This should be done in bulk outside the loop
}
// This method lacks ApexDocs
public void UpdateAccount(List<Account> accounts) {
// DML operation inside a loop - bad practice
for (Account acc : accounts) {
acc.Name += ' - Updated';
update acc; // This should be done in bulk outside the loop
}
}

/**
* Deletes a specified account
* @param accountId The ID of the account to be deleted
*/
public void delete_Account(Id accountId) {
// Hardcoding IDs - bad practice
Id hardCodedId = '001xx000003DGAXAA4';
delete [SELECT Id FROM Account WHERE Id = :hardCodedId];
}
/**
* Deletes a specified account
* @param accountId The ID of the account to be deleted
*/
public void delete_Account(Id accountId) {
// Hardcoding IDs - bad practice
Id hardCodedId = '001xx000003DGAXAA4';
delete [SELECT Id FROM Account WHERE Id = :hardCodedId];
}

// This method lacks ApexDocs
public List<Account> ListAccounts() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
// This method lacks ApexDocs
public List<Account> ListAccounts() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}

/**
* Calculates the annual revenue
* - This ApexDoc is incomplete and lacks parameter description
* @return Decimal The calculated annual revenue
*/
public String CalculateAnnualRevenue() {
// Lack of null checks and exception handling - bad practice
Account acc = [SELECT Industry FROM Account WHERE Id = '001xx000003DGAZAA4'];
return acc.Industry;
}
/**
* Calculates the annual revenue
* - This ApexDoc is incomplete and lacks parameter description
* @return Decimal The calculated annual revenue
*/
public String CalculateAnnualRevenue() {
// Lack of null checks and exception handling - bad practice
Account acc = [
SELECT Industry
FROM Account
WHERE Id = '001xx000003DGAZAA4'
];
return acc.Industry;
}

// This method lacks ApexDocs
public List<Account> ListAccounts2() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
// This method lacks ApexDocs
public List<Account> ListAccounts2() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}

// This method lacks ApexDocs
public List<Account> ListAccounts3() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
// This method lacks ApexDocs
public List<Account> ListAccounts3() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
}
14 changes: 7 additions & 7 deletions demo-classes/CaseService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
* @description service related updates
*/
public with sharing class CaseService {
public static void doUpdates(Set<Id> caseIds) {
List<Case> cases = [SELECT Id, Status FROM Case WHERE Id IN :caseIds];
for (Case c : cases) {
c.Status = 'Closed';
// raise pmd error
update c;
}
public static void doUpdates(Set<Id> caseIds) {
List<Case> cases = [SELECT Id, Status FROM Case WHERE Id IN :caseIds];
for (Case c : cases) {
c.Status = 'Closed';
// raise pmd error
update c;
}
}
}
94 changes: 94 additions & 0 deletions force-app/main/default/classes/AccountService.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* AccountService Class
* Provides various services related to Account object
*/
public class AccountService {
/**
* Fetches details for a given account
* @param accountId The ID of the account
* @return Account The details of the account
*/
public Account getAccDetails(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
return acc;
}
return null;
}

public Account getAccDetails2(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
update acc;
return acc;
}
return null;
}

public Account getAccDetails3(Id accountId) {
// SOQL query inside a loop - bad practice
for (Id accId : new List<Id>{ accountId }) {
Account acc = [SELECT Id, Name, Industry FROM Account WHERE Id = :accId];
update acc;
return acc;
}
return null;
}

// This method lacks ApexDocs
public void UpdateAccount(List<Account> accounts) {
// DML operation inside a loop - bad practice
for (Account acc : accounts) {
acc.Name += ' - Updated';
update acc; // This should be done in bulk outside the loop
}
}

/**
* Deletes a specified account
* @param accountId The ID of the account to be deleted
*/
public void delete_Account(Id accountId) {
// Hardcoding IDs - bad practice
Id hardCodedId = '001xx000003DGAXAA4';
delete [SELECT Id FROM Account WHERE Id = :hardCodedId];
}

// This method lacks ApexDocs
public List<Account> ListAccounts() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}

/**
* Calculates the annual revenue
* - This ApexDoc is incomplete and lacks parameter description
* @return Decimal The calculated annual revenue
*/
public String CalculateAnnualRevenue() {
// Lack of null checks and exception handling - bad practice
Account acc = [
SELECT Industry
FROM Account
WHERE Id = '001xx000003DGAZAA4'
];
return acc.Industry;
}

// This method lacks ApexDocs
public List<Account> ListAccounts2() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}

// This method lacks ApexDocs
public List<Account> ListAccounts3() {
// Not using bulkified approach - bad practice
List<Account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
return accounts;
}
}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/AccountService.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading

0 comments on commit c821545

Please sign in to comment.