This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
This page must be accessed with an Account ID in the URL. | |
For example: https://<salesforceInstance>/apex/ContactsCsvPage?id=001D000000JRBet | |
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_styling_content_type.htm | |
--> | |
<apex:page standardController='Account' contentType='application/vnd.ms-excel#contacts.xls'> | |
<apex:pageBlock title='Contacts'> | |
<apex:pageBlockTable value='{!account.Contacts}' var='contact'> | |
<apex:column value='{!contact.Name}'/> | |
<apex:column value='{!contact.MailingCity}'/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String csv = 'Id,Name\n'; | |
for ( List<Account> accts : [ SELECT id, name FROM Account LIMIT 10 ] ) { | |
for ( Account acct : accts ) { | |
csv += acct.id + ',' + acct.name.escapeCsv() + '\n'; | |
} | |
} | |
ContentVersion file = new ContentVersion( | |
title = 'accounts.csv', | |
versionData = Blob.valueOf( csv ), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Developed by Doug Ayers | |
* douglascayers.com | |
* | |
* Designed to be used by SendEmailInvocable class when sending | |
* several emails but need to stay within the apex governor limits | |
* of how many emails can be sent per transaction. Call this batchable | |
* with all the emails to send and set the batch size to max per transaction. | |
* https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FeedItem item = new FeedItem( | |
parentId = UserInfo.getUserId(), // where to post message | |
createdById = '005j000000Bz31U', // author to impersonate | |
body = '<p><b>FeedItem</b> supports <i>rich text</i> but not @ mentions:</p> @[0F9j00000008TNc] @0F9j00000008TNc {0F9j00000008TNc} @{0F9j00000008TNc}', | |
isRichText = true | |
); | |
insert item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Designed to be used in Flow to retrieve all the custom permission sets | |
* assigned to the given user ids. Excludes permission sets tied to profiles. | |
*/ | |
public with sharing class GetUserPermissionSetsInvocable { | |
@InvocableMethod( | |
label = 'UPS: Get User Permission Set Assignments' | |
description = 'Get User Permission Set Assignments' | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger AccountTrigger on Account ( before insert, before update, before delete, after insert, after update, after delete, after undelete ) { | |
System.debug( 'trigger event: ' + ( Trigger.isBefore ? 'before' : 'after' ) + ' ' + ( Trigger.isInsert ? 'insert' : Trigger.isUpdate ? 'update' : Trigger.isDelete ? 'delete' : 'undelete' ) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger AttachmentTrigger on Attachment ( before delete ) { | |
Set<ID> parentIds = new Set<ID>(); | |
for ( Attachment a : Trigger.old ) { | |
parentIds.add( a.parentId ); | |
} | |
System.debug( parentIds ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ID recordId = '5001a00000CgCE2'; | |
DescribeSObjectResult describeResult = recordId.getSObjectType().getDescribe(); | |
List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() ); | |
String query = | |
' SELECT ' + | |
String.join( fieldNames, ',' ) + | |
' FROM ' + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// without an ID, simply specify the object to then derive the sobject type | |
DescribeSObjectResult describeResult = Account.getSObjectType().getDescribe(); | |
List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() ); | |
String query = | |
' SELECT ' + | |
String.join( fieldNames, ',' ) + | |
' FROM ' + | |
describeResult.getName() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class SampleOpptyController { | |
public List<Opportunity> opportunities { get; set; } | |
public SampleOpptyController() { | |
this.opportunities = queryOpportunities(); | |
} | |
private List<Opportunity> queryOpportunities() { | |
return [ |