Created
May 31, 2013 19:32
-
-
Save ReidCarlberg/5687402 to your computer and use it in GitHub Desktop.
Samples for the Force.com Developer Workshop
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
Developer Console Demo | |
1) SOQL Query | |
Select Id, Name From Account | |
Select Id, Name, Owner.Name From Account | |
Select Id, Name, Owner.Name From Account Limit 5 | |
Select Id, Name, Owner.Name From Account Order By Name Limit 5 | |
Select Id, Name, (Select Id, Name from Contacts) From Account | |
Select Count() from Account | |
Select BillingState, count(Id) from Account Group By BillingState | |
2) Insert Data | |
List<Account> newAccounts = new List<Account>(); | |
for (integer i = 0; i < 100; i++) { | |
newAccounts.add(new Account(Name = 'New Account ' + i, BillingState = 'ID')); | |
} | |
insert newAccounts; | |
Run: Select BillingState, count(Id) from Account Group By BillingState | |
3) Delete Account | |
List<Account> idAccounts = [Select Id, Name From Account Where BillingState = 'ID']; | |
Delete idAccounts; | |
Run: Select BillingState, count(Id) from Account Group By BillingState | |
[email protected] | |
Chatter Trigger Demo | |
trigger FeedItemTrigger on FeedItem (after insert) { | |
List<FeedComment> newComments = new List<FeedComment>(); | |
for (FeedItem current: trigger.new) { | |
if (current.body.contains('#demo')) { | |
FeedComment myComment = new FeedComment(); | |
newComments.add(myComment); | |
myComment.feedItemId = current.id; | |
myComment.commentType = 'TextComment'; | |
myComment.commentBody = 'Thank you sir may I have another.'; | |
} | |
} | |
if (newComments.size() > 0) { | |
insert newComments; | |
} | |
} | |
Refactored Trigger | |
trigger FeedItemTrigger on FeedItem (after insert) { | |
new FeedItemHelper().handleNewFeedItems(trigger.new); | |
} | |
Refactored Helper Class | |
public class FeedItemHelper{ | |
public void handleNewFeedItems(List<FeedItem> newItems) { | |
List<FeedComment> newComments = new List<FeedComment>(); | |
for (FeedItem current: newItems) { | |
if (current.body.contains('#demo')) { | |
FeedComment myComment = new FeedComment(); | |
newComments.add(myComment); | |
myComment.feedItemId = current.id; | |
myComment.commentType = 'TextComment'; | |
myComment.commentBody = 'Thank you sir may I have another.'; | |
} | |
} | |
if (newComments.size() > 0) { | |
insert newComments; | |
} | |
} | |
} | |
Refactored Test | |
@isTest | |
public class FeedItemHelperTest{ | |
static testmethod void testSimple() { | |
FeedItem testItem = new FeedItem(); | |
testItem.Body = 'Hello World'; | |
testItem.Type = 'TextPost'; | |
testItem.ParentId = UserInfo.getUserId(); | |
insert testItem; | |
List<FeedComment> comments = [Select Id From FeedComment Where FeedItemId = :testItem.id]; | |
System.assert(comments.size() == 0); | |
} | |
static testmethod void testSimpleWithComment() { | |
FeedItem testItem = new FeedItem(); | |
testItem.Body = 'Hello World #demo'; | |
testItem.Type = 'TextPost'; | |
testItem.ParentId = UserInfo.getUserId(); | |
insert testItem; | |
List<FeedComment> comments = [Select Id From FeedComment Where FeedItemId = :testItem.id]; | |
System.assert(comments.size() == 1); | |
} | |
} | |
Standard Controller Demo | |
1. Turn on Developer Mode | |
2. Create a HelloWorld page | |
3. Standard Visualforce Demo -- remove all the headers, add css, do simple JavaScript | |
4. Account | |
5. Apex:details | |
6. Show with the ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment