select Substring(notes,1,4000) as notes from history
Where the 1 is where you start and the 4000 is how many characters you want to pull in.
SUBSTRING ( expression ,start , length )
A holding place for thoughts, ideas and revelations related to cloud configuration and development with Salesforce.com
SUBSTRING ( expression ,start , length )
trigger test on Lead (before update) { for(Lead lead:System.Trigger.new) { if (Lead.IsConverted) //do somethign here with converted leads } }
IMAGE( CASE( Priority, "Low", "/img/samples/flag_green.gif", "Medium", "/img/samples/flag_yellow.gif", "High", "/img/samples/flag_red.gif", "/s.gif"), "Priority Flag")
IMAGE( CASE(Project_Status__c, "Green", "/img/samples/light_green.gif", "Yellow", "/img/samples/light_yellow.gif", "Red", "/img/samples/light_red.gif", "/s.gif"), "status color")
IMAGE( CASE(Rating__c, "1", "/img/samples/stars_100.gif", "2", "/img/samples/stars_200.gif", "3", "/img/samples/stars_300.gif", "4", "/img/samples/stars_400.gif", "5", "/img/samples/stars_500.gif", "/img/samples/stars_000.gif"), "rating")
IMAGE( CASE(Rating__c, "1", "/img/samples/rating1.gif", "2", "/img/samples/rating2.gif", "3", "/img/samples/rating3.gif", "4", "/img/samples/rating4.gif", "5", "/img/samples/rating5.gif", "/s.gif"), "rating")
IMAGE("/img/samples/color_green.gif", "green", 15, Industry_Score__c * 2) & IMAGE("/s.gif", "white", 15, 200 - (Industry_Score__c * 2))
// An IN-bind with an Id list. Note that a list of sObjects // can also be used--the Ids of the objects are used for // the bind Contact[] cc = [SELECT Id FROM Contact LIMIT 2]; Task[] tt = [SELECT Id FROM Task WHERE WhoId IN :cc]; // An IN-bind with a String list String[] ss = new String[]{'a', 'b'}; Account[] aa = [SELECT Id FROM Account WHERE AccountNumber IN :ss];
Below is a basic example of a for loop. I always seem to need to need this and forget the exact context.
trigger OpportunitySubmitForApproval on Opportunity (after update) { for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.old[i].Probability < 30 && Trigger.new[i].Probability >= 30) { // create the new approval request to submit Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setComments('Submitted for approval. Please approve.'); req.setObjectId(Trigger.new[i].Id); // submit the approval request for processing Approval.ProcessResult result = Approval.process(req); // display if the reqeust was successful System.debug('Submitted for approval successfully: '+result.isSuccess()); } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | trigger OpportunitySubmitForApproval on Opportunity (after update) { for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.old[i].Probability < 30 && Trigger.new[i].Probability >= 30) { // create the new approval request to submit Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setComments('Submitted for approval. Please approve.'); req.setObjectId(Trigger.new[i].Id); // submit the approval request for processing Approval.ProcessResult result = Approval.process(req); // display if the reqeust was successful System.debug('Submitted for approval successfully: '+result.isSuccess()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | @isTest private class TestOpportunitySubmitForApproval { static testMethod void testApprovalSuccess() { Opportunity opp = new Opportunity(); opp.Name = 'Test Opp'; opp.Amount = 100; opp.CloseDate = Date.today(); opp.Probability = 10; opp.StageName = 'Prospecting'; // insert the new opp insert opp; // change the probability of the opp so the trigger submits it for approval opp.Probability = 40; // update the opp which should submit it for approval update opp; // ensure that the opp was submitted for approval List<ProcessInstance> processInstances = [select Id, Status from ProcessInstance where TargetObjectId = :opp.id]; System.assertEquals(processInstances.size(),1); } } |
CREATE FUNCTION [dbo].[udf_StripHTML] (@HTMLText VARCHAR(MAX))
RETURNS VARCHAR(MAX) AS
BEGIN
DECLARE @Start INT
DECLARE @End INT
DECLARE @Length INT
SET @Start = CHARINDEX('<',@HTMLText)
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
WHILE @Start > 0 AND @End > 0 AND @Length > 0
BEGIN
SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')
SET @Start = CHARINDEX('<',@HTMLText)
SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
END
RETURN LTRIM(RTRIM(@HTMLText))
END
GO
trigger ChatterActivity on Task (after insert, after update) {
List<FeedItem> feedItems = new List<FeedItem>();
//We want to show the User name as assignedTo. The only way to get to that is by querying the user table.
Set<ID> ownerIds = new Set<ID>();
for (Task t : Trigger.new) {
ownerIds.add(t.ownerId);
}
Map<ID,User> userMap = new Map<ID,User>([SELECT ID, Name FROM User WHERE ID IN :ownerIds]); //This is our user map
//Now loop though the new/updated tasks and create the feed posts
for (Task t : Trigger.new) {
if (t.WhatId != null) {
FeedItem fitem = new FeedItem();
fitem.type = 'LinkPost';
fitem.ParentId = t.WhatId;
fitem.LinkUrl = '/' + t.id; //This is the url to take the user to the activity
fitem.Title = 'View'; //This is the title that displays for the LinkUrl
//Get the user by checking the userMap we created earlier
User assignedTo = userMap.get(t.ownerId);
fitem.Body = ((Trigger.isInsert) ? 'New' : 'Updated') + ' Activity ' + ((t.ActivityDate != null) ? t.ActivityDate.format() :'')
+ '\nAssigned To: ' + ((assignedTo != null) ? assignedTo.name : 'Unknown')
+ '\nSubject: ' + t.Subject
+ '\nStatus: ' + t.Status;
feedItems.add(fitem);
}
}
//Save the FeedItems all at once.
if (feedItems.size() > 0) {
Database.insert(feedItems,false); //notice the false value. This will allow some to fail if Chatter isn't available on that object
}
}
public with sharing class ChatterUnitTests {
/*
* Test the ChatterActivity trigger which inserts chatter feed posts whenever a task is inserted on the parent object
*/
public static testMethod void testChatterActivity() {
//create the test account
Account a = new Account(name='Test Account');
insert a;
//create a task on that account
Task t = new Task(whatId=a.id);
t.Subject = 'This is a test activity for chatter';
t.ActivityDate = System.today();
t.Status = 'In Progress';
t.Description = 'Hello, this will be chattered';
insert t;
//Make sure Account has the feed enabled. If it does, make sure the chatter feed post is there
Schema.DescribeSObjectResult r = Account.SObjectType.getDescribe();
if (r.isFeedEnabled()) {
List<AccountFeed> posts = [SELECT Id, Type FROM AccountFeed WHERE ParentId = :a.id];
System.assertEquals(1, posts.size());
}
}
}