Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Apexdocs upgrade #594

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions bin/generate-apex-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rm -fr docs && \
rm -fr force-app/main/default/staticresources/documentation && \

# Generate Apex doc files
./node_modules/.bin/apexdocs-generate -p global public private protected namespaceaccessible -s force-app/main/default/classes && \
./node_modules/.bin/apexdocs markdown -p global public private protected namespaceaccessible -s force-app/main/default/classes && \

# Remove doc index
rm docs/index.md && \
Expand All @@ -22,8 +22,5 @@ find docs/* -type d -empty -delete && \
find docs/ -type f -name "*.md" -print0 | xargs -0 sed -i "" -E "s@]\(\.\/(.*)\.md@](https://github.com/trailheadapps/apex-recipes/wiki/\1@g" && \
find docs/ -type f -name "*.md" -print0 | xargs -0 sed -i "" -E "s@\]\(\.\.\/.*\/(.*)\.md@](https://github.com/trailheadapps/apex-recipes/wiki/\1@g" && \

# Remove first three line with layout header
find docs/ -type f -name "*.md" -print0 | xargs -0 sed -i "" "1,3d"

# Move docs
mv docs force-app/main/default/staticresources/documentation
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public with sharing class AtFutureRecipes {
* transaction than the calling code.
* @param data String to be logged
* @example
* ```
* AtFutureRecipes.atFutureMethodWithoutCalloutPrivileges('Some Data');
* ```
**/
@future
public static void atFutureMethodWithoutCalloutPrivileges(String data) {
Expand All @@ -41,7 +43,9 @@ public with sharing class AtFutureRecipes {
*
* @param url The URL to make a callout to.
* @example
* ```
* AtFutureRecipes.atFutureMethodWithCalloutPrivileges('google.com');
* ```
**/
@future(callout=true)
public static void atFutureMethodWithCalloutPrivileges(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public with sharing class BatchApexRecipes implements Database.Batchable<SObject
* @param context dependency injected by the system
* @return Database.QueryLocator QueryLocator object used for context
* @example
* ```
* Database.executeBatch(new BatchApexRecipes());
* ```
**/
public Database.QueryLocator start(Database.BatchableContext context) {
return Database.getQueryLocator(queryString);
Expand All @@ -47,7 +49,9 @@ public with sharing class BatchApexRecipes implements Database.Batchable<SObject
* called scope (in this example) that make this easier.
* @param scope a list of up to 200 SObject records to be processed
* @example
* ```
* Database.executeBatch(new BatchApexRecipes());
* ```
**/
public void execute(
Database.BatchableContext context,
Expand Down Expand Up @@ -98,7 +102,9 @@ public with sharing class BatchApexRecipes implements Database.Batchable<SObject
* notify others of the job's completion here.
* @param context dependency injected by the system
* @example
* ```
* Database.executeBatch(new BatchApexRecipes());
* ```
**/
public void finish(Database.BatchableContext context) {
BatchApexRecipes.result =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public with sharing class QueueableChainingRecipes implements Queueable {
* passed through to the next Queueable.
* @param context Dependency Injected by the System
* @example
* ```
* System.enqueueJob(new QueueableChainingRecipes());
* ```
**/
public static void execute(QueueableContext context) {
List<Account> accounts = [SELECT Id, Description FROM Account];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public with sharing class QueueableRecipes implements Queueable {
* details.
* @param qc dependency injected by the system
* @example
* ```
* System.enqueueJob(new QueueableRecipes());
* ```
**/
public static void execute(QueueableContext qc) {
List<Account> accounts = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public with sharing class QueueableWithCalloutRecipes implements Queueable, Data
* to developer.salesforce.com
* @param qc dependency injected by the system
* @example
* ```
* System.enqueueJob(new QueueableWithCalloutRecipes());
* ```
**/
public static void execute(QueueableContext qc) {
HttpResponse response = RestClient.makeApiCall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public with sharing class ScheduledApexDemo {
* logic from
* the schedulable interface code that executes it.
* @example
* ```
* ScheduledApexDemo.runAtMidnight();
* ```
**/
public void runAtMidnight() {
System.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ public with sharing class ScheduledApexRecipes implements Schedulable {
* BatchApexRecipes for more information.
* @param context Dependency Injected by the System
* @example
* ```
* System.schedule('Friendly Message to identify this job',
* ScheduledApexRecipes.TEST_CRON_STATEMENT,
* new ScheduledApexRecipes());
* ```
**/
public void execute(SchedulableContext context) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public with sharing class CollectionUtils {
* sObjects
* @return `Map<Id, sObject>`
* @example
* ```
* Contact[] contacts = [SELECT AccountId, firstName, lastName FROM Contact LIMIT 50];
* Map<Id, Contact> contactsByAccountId = (Map<Id, Contact>) CollectionUtils.idMapFromCollectionByKey('accountId', contacts);
* ```
*/
public static Map<Id, SObject> idMapFromCollectionByKey(
String key,
Expand All @@ -56,8 +58,10 @@ public with sharing class CollectionUtils {
* @param incomingList List of incoming sObjects to build the map from
* @return `Map<String, sObject>`
* @example
* ```
* Contact[] contacts = [SELECT AccountId, firstName, lastName FROM Contact LIMIT 50];
* Map<String, Contact> contactsByAccountId = (Map<String, Contact>) CollectionUtils.stringMapFromCollectionByKey('shippingStreet', contacts);
* ```
*/
public static Map<String, SObject> stringMapFromCollectionByKey(
String key,
Expand All @@ -83,8 +87,10 @@ public with sharing class CollectionUtils {
* @param incomingList List of sObjects to build the map from.
* @return `Map<Id, List<sObject>>`
* @example
* ```
* Contact[] contacts = [SELECT AccountId, firstName, lastName FROM Contact LIMIT 50];
* Map<Id, List<Contact>> contactsByAccountId = (Map<Id, List<Contact>>) CollectionUtils.mapFromCollectionWithCollectionValues('accountId', contacts);
* ```
*/
public static Map<Id, List<SObject>> mapFromCollectionWithCollectionValues(
String key,
Expand Down
28 changes: 28 additions & 0 deletions force-app/main/default/classes/Data Recipes/DMLRecipes.cls
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public with sharing class DMLRecipes {
* @param name name of the created account
* @return the inserted Account
* @example
* ```
* DMLRecipes.insertAccountViaInsertKeywordInUserMode('Hello');
* ```
*/
public static Account insertAccountViaInsertKeywordInUserMode(String name) {
Account acct = new Account();
Expand All @@ -59,7 +61,9 @@ public with sharing class DMLRecipes {
* to be inserted must insert successfully
* @return list of inserted accounts
* @example
* ```
* DMLRecipes.insertAccountsViaDatabaseMethod('Hello', false, AccessLevel.USER_MODE);
* ```
*/
public static List<Account> insertAccountsViaDatabaseMethod(
List<String> names,
Expand All @@ -84,7 +88,9 @@ public with sharing class DMLRecipes {
* @param acct account to upsert
* @return Upserted Account record
* @example
* ```
* DMLRecipes.upsertAccountViaUpsertKeywordInSystemMode(new Account(name='Hello World'));
* ```
**/
public static Account upsertAccountViaUpsertKeywordInSystemMode(
Account acct
Expand All @@ -105,7 +111,9 @@ public with sharing class DMLRecipes {
* @param acct account to upsert
* @return Upserted Account record
* @example
* ```
* DMLRecipes.upsertAccountViaUpsertKeywordInUserMode(new Account(name='Hello World'));
* ```
**/
public static Account upsertAccountViaUpsertKeywordInUserMode(
Account acct
Expand All @@ -127,8 +135,10 @@ public with sharing class DMLRecipes {
* @param allOrNothing all or nothing flag
* @return Upsert operation result
* @example
* ```
* DMLRecipes.upsertAccountViaDatabaseMethod(
* new Account(Name='Hello World'), false, AccessLevel.USER_MODE);
* ```
**/
public static Database.UpsertResult upsertAccountViaDatabaseMethod(
Account acct,
Expand All @@ -150,9 +160,11 @@ public with sharing class DMLRecipes {
* @param accts List of accounts to update
* @return List of updated records
* @example
* ```
* Account acct = new Account(name='Hello World');
* insert acct;
* DMLRecipes.updateAcccountViaKeywordInSystemMode(acct);
* ```
**/
public static List<Account> updateAcccountViaKeywordInSystemMode(
List<Account> accts
Expand All @@ -174,9 +186,11 @@ public with sharing class DMLRecipes {
* @param accts List of accounts to update
* @return List of updated records
* @example
* ```
* Account acct = new Account(name='Hello World');
* insert acct;
* DMLRecipes.updateAcccountViaKeyword(acct);
* ```
**/
public static List<Account> updateAcccountViaKeywordInUserMode(
List<Account> accts
Expand All @@ -198,10 +212,12 @@ public with sharing class DMLRecipes {
* @param accts list of accounts to update
* @return List of updated records
* @example
* ```
* List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
* insert accounts;
* List<Account> results = DMLRecipes.updateAccountViaDatabaseMethod(accounts, AccessLevel.USER_MODE);
* System.debug(results);
* ```
**/
public static List<Account> updateAccountViaDatabaseMethod(
List<Account> accts,
Expand All @@ -223,9 +239,11 @@ public with sharing class DMLRecipes {
* @description Deletes a list of accounts via the `delete` DML keyword
* @param accts list of accounts to delete in system mode
* @example
* ```
* List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
* insert accounts;
* DMLRecipes.deleteAccountViaKeywordInSystemMode(accounts);
* ```
**/
public static void deleteAccountViaKeywordInSystemMode(
List<Account> accts
Expand All @@ -242,9 +260,11 @@ public with sharing class DMLRecipes {
* @description Deletes a list of accounts via the `delete` DML keyword
* @param accts list of accounts to delete in user mode
* @example
* ```
* List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
* insert accounts;
* DMLRecipes.deleteAccountViaKeywordInUserMode(accounts);
* ```
**/
public static void deleteAccountViaKeywordInUserMode(List<Account> accts) {
try {
Expand All @@ -259,9 +279,11 @@ public with sharing class DMLRecipes {
* @description Deletes a list of accounts via the `Database.delete` method
* @param accts List of Accounts to delete
* @example
* ```
* List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
* insert accounts in user mode;
* DMLRecipes.deleteAccountViaDatabaseMethod(accounts, AccessLevel.USER_MODE);
* ```
**/
public static void deleteAccountViaDatabaseMethod(
List<Account> accts,
Expand All @@ -279,11 +301,13 @@ public with sharing class DMLRecipes {
* @param accts List of accounts to undelete in user mode
* @return list of undeleted accounts
* @example
* ```
* List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
* insert accounts;
* delete accounts;
* List<Account> results = DMLRecipes.undeleteAccountViaKeywordInSystemMode(accounts);
* System.debug(results);
* ```
**/
public static List<Account> undeleteAccountViaKeywordInSystemMode(
List<Account> accts
Expand All @@ -302,11 +326,13 @@ public with sharing class DMLRecipes {
* @param accts List of accounts to undelete in user mode
* @return list of undeleted accounts
* @example
* ```
* List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
* insert accounts;
* delete accounts;
* List<Account> results = DMLRecipes.undeleteAccountViaKeywordInUserMode(accounts);
* System.debug(results);
* ```
**/
public static List<Account> undeleteAccountViaKeywordInUserMode(
List<Account> accts
Expand All @@ -325,11 +351,13 @@ public with sharing class DMLRecipes {
* @param accts list of accounts to undelete
* @return list of undeleted accounts
* @example
* ```
* List<Account> accounts = new List<Account>{new Account(name = 'Hello World')};
* insert accounts;
* delete accounts;
* List<Account> results = DMLRecipes.undeleteAccountViaDatabaseMethod(accounts, AccessLevel.USER_MODE);
* System.debug(results);
* ```
**/
public static List<Account> undeleteAccountViaDatabaseMethod(
List<Account> accts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public with sharing class DynamicSOQLRecipes {
* does not include any input parameters so SOQL Injection is not possible.
* @return List<Account> with security enforced using USER_MODE
* @example
* ```
* System.debug(DynamicSOQLRecipes.simpleDynamicSOQLQuery());
* ```
**/
@SuppressWarnings('PMD.ApexSOQLInjection')
public static List<Account> simpleDynamicSOQLQuery() {
Expand All @@ -30,7 +32,9 @@ public with sharing class DynamicSOQLRecipes {
* @param name Name of the account to search for
* @return List<Account>
* @example
* ```
* System.debug(DynamicSoqlRecipes.simpleBindingSOQLQuery('hello'))
* ```
**/
public static List<Account> simpleBindingSOQLQuery(String name) {
Map<String, Object> nameBind = new Map<String, Object>{
Expand All @@ -54,9 +58,11 @@ public with sharing class DynamicSOQLRecipes {
* @param acct Account to base the search off of
* @return List<Account>
* @example
* ```
* Account acct = [SELECT Name FROM Account WHERE Name = 'hello' LIMIT 1];
* Account[] results = DynamicSOQLRecipes.dynamicFieldsBindingSOQLQuery(acct);
* System.debug(results);
* ```
**/
public static List<Account> dynamicFieldsBindingSOQLQuery(Account acct) {
Map<String, Object> accountNameBind = new Map<String, Object>{
Expand Down Expand Up @@ -91,7 +97,9 @@ public with sharing class DynamicSOQLRecipes {
* @param numberOfRecords String to be used as the comparison in the query
* @return List<Account>
* @example
* ```
* System.debug(DynamicSOQLRecipes.typecastDataIntelligently(2).size());
* ```
**/
@SuppressWarnings('PMD.ApexSOQLInjection')
public static List<Account> typecastDataIntelligently(
Expand Down Expand Up @@ -135,6 +143,7 @@ public with sharing class DynamicSOQLRecipes {
* @param whereClause A string containing the where clause
* @return `List<Account>`
* @example
* ```
* List<String> fields = new List<String>{
* 'Name',
* 'NumberOfEmployees',
Expand All @@ -149,6 +158,7 @@ public with sharing class DynamicSOQLRecipes {
* whereClause
* );
* System.debug(results);
* ```
*/
@SuppressWarnings('PMD.ApexSOQLInjection')
public static List<Account> simpleQueryBuilder(
Expand Down
Loading