Monday, June 6, 2016

@ mention groups and users in Process Builder

To @ mention records and users in a chatter post in a publisher action all you need to do is use the following syntax in the chatter post:

@[merge field]


@[group id/user id]

To @ mention the owner of a contact the syntax would be @[{![Contact].OwnerId}]

Friday, April 24, 2015

Salesforce Datetime in a Validation Rule

Salesforce Date Time in a Validation Rule

Recently I had to put in a very simple condition into a validation rule where we didn't want the validation rule to fire for records we created in the past, only on records we created going forward.

So I just wanted to put into the condition formula something that said the created data had to be greater than a set date, here is what I used:

DATEVALUE(CreatedDate) > DATEVALUE("2015-04-24") 


Because the CreatedDate is a datetime field I just used the DATEVALUE field and it worked like a charm!

Now my validation rule which is very simple looks like this and will only fire on records we create from April 24th and forward.

AND( 
     ISPICKVAL(Consulting_Type__c , 'Support – Time Bound'), 
     ISBLANK(Support_End_Date__c ), 
     DATEVALUE(CreatedDate) > DATEVALUE("2015-04-24") 
)

Tuesday, January 6, 2015

Simple Visualforce Page to Allow Updates to Related List

I have had many requests in the past to allow for quick easy updates to a related list. You can use list views to do some of the updates, but there is no way to do a quick update to a related list aside from installing an app. GridBuddy is a great app that can accomplish this at a very reasonable price.

However I recently had a request to do one simple update on Quotes that are related to an Opportunity, just one checkbox and everything else would be read only. Below is the source code for the Visualforce Page, Custom Controller and Test Class.

There are a couple custom fields mixed in here but most of this is standard Salesforce. This would be a Visualforce page that would be placed on the Opportunity page layout and it would show related Quotes with the option to update and save changes.

VF Page:

<apex:page standardController="Opportunity" extensions="quoteController">
 
 <apex:outputPanel id="refresh" rendered="true">
 <apex:outputPanel id="refresh1" rendered="{!refreshPage}">
  <script>
   window.top.location='/{!Opportunity.id}';
  </script>
 </apex:outputPanel>
</apex:outputPanel>

 <style>
.pbBody td {
 border-color: #E3DEB8;
 border-style: none none solid;
 border-width: medium medium 2px;
 padding-bottom: 4px;
 padding-top: 4px;
 width: 85px;
}
.pbBody input   { width: 105px;}
.pbBody .nameColumn { width: 125px;}
.hdr     {;}
</style>
<apex:form >


 <apex:messages />

 <apex:pageBlock title="Edit Quotes">
  <apex:pageBlockButtons >
   <apex:commandButton action="{!saveChanges}" value="Save" status="ajaxStatus" />
  </apex:pageBlockButtons>
  <apex:actionStatus id="ajaxStatus" startText="Updating quotes...">
   <apex:facet name="stop">

   <apex:outputPanel id="main"> 
       
       
    <table>
    <tr>
     <apex:repeat value="{!headers}" var="h">
      <td class="hdr">{!h}</td>
     </apex:repeat>
    </tr>

    <apex:repeat value="{!Quotes}" var="q">
     <tr>
      <td><apex:outputField value="{!q.QuoteNumber}" /></td>
      <td><apex:outputField value="{!q.Name}" /></td>
      <td><apex:outputField value="{!q.IsSyncing}" /></td>
      <td><apex:inputField value="{!q.Price__c}" /></td>
      <td><apex:inputField value="{!q.Margin__c}" /></td>  
     </tr>
    </apex:repeat>
    </table>  
   </apex:outputPanel>
   </apex:facet>
  </apex:actionStatus>
 </apex:pageBlock>
</apex:form>
</apex:page>


Custom Apex Controller:

public class quoteController {

public Boolean refreshPage {get; set;}
  
  // Constructor
 public quoteController (ApexPages.StandardController controller) {
  
  refreshPage=false;
  
  this.opp = (Opportunity)controller.getSubject();
  
     this.quote = [ SELECT 
      q.Id, q.QuoteNumber, q.name, q.IsSyncing, q.Price__c, 
      q.Margin__c
      FROM 
      Quote q 
      WHERE 
      q.OpportunityID = :opp.id ];
 }


 // Action Method called from page button
 public pagereference saveChanges() {   
  
  update this.quote;
  refreshPage=true;
  return null;
  
 }


 // Action Method called from page link
 public pagereference newQuote() { 
  Quote q = new Quote();
  q.OpportunityID =this.opp.id; 
  quote.add( q );
  return null;
 }

 // public Getter to provide table headers 
 public string[] getheaders() { return new string [] 
  {'Quote Number','Quote Name','Synching','Price',
  'Margin','Total Margin' } ; }

 // public Getter to list project deliverables
 public Quote[] getQuotes() { 
  return this.quote; 
 } 

 // class variables
 Opportunity opp;
 Quote[] quote; 
}


Test Class:

@isTest
private class controllerTest {
    
    
     public static testMethod void testMyController() {
        
        Account a = new Account(name='Test Account');      
        insert a;

        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opp';
        opp.Amount = 100;
        opp.CloseDate = Date.today();
        opp.Probability = 10;
        opp.StageName = 'New';      
        insert opp;
        
        // start the test execution context
        Test.startTest();

        // set the test's page to your VF page (or pass in a PageReference)
        Test.setCurrentPage(Page.OpportunityQuoteGrid);
        
        // call the constructor
        quoteController controller = new quoteController(new ApexPages.StandardController(opp));
        //quoteController controller = new quoteController();
        //String nextPage = controller.save().getUrl();
        
        // test action methods on your controller and verify the output with assertions
        controller.saveChanges();
        controller.getHeaders();
        controller.newQuote();
        controller.getQuotes();

        
        // stop the test
        Test.stopTest();
        
     }
    
    
}

Monday, May 19, 2014

Excel Text Format to Date

I recently had to format all dates in a specified format mm/dd/yyyy and was struggling with the formats available. I ended up resorting to this simple little text format that worked great!

=TEXT(B2,"mm/dd/yyyy")

Thursday, February 27, 2014

Conga Word Merge Format: Tab Within Table Cell, Prevent Table Page Break

A couple items I recently ran into when creating a Conga merge document were tabbing within a cell of a word table and preventing a table from breaking across pages.

Tabbing is simple, all you do is CTRL + TAB. You can put the ruler on the page layout and adjust how far the tab takes you at the top.

Here we use the "Keep with next" function found in the paragraph formatting. The trouble with this is when you highlight the table and right click you do not see the "Paragraph" as an option, all you see is Table Formatting. What you have to do (in word 2010) is highlight the table and on the Home ribbon at the top there is a Paragraph section, all you do is click the small little arrow on the bottom right of the section and it will pull the Paragraph format page up. Click on the "Lines and Page Breaks" tab then select "Keep with next" and that's it!

Tuesday, February 25, 2014

Convert 15 Character Salesforce ID to 18 Character (Case Sensitive)

The 15 character Salesforce ID is NOT case sensitive so when manipulating data in Excel you cannot do VLOOKUP's against a 15 character ID and you cannot use simple commands such as remove duplicates.

Salesforce sees these 2 records as being unique while microsoft programs see them as being the same:

006A000000NoiGl
006A000000Noigl

VLOOKUPs will work, but the data will be COMPLETELY WRONG!

Using something like this tool below you can convert the 15 character ID to the CASE SENSITIVE 18 character ID. Without getting into the logic behind the scenes the above examples convert to the case sensitive IDs below and you CAN do VLOOKUPs and remove duplicates on these.

006A000000NoiGl  >  006A000000NoiGlIAJ
006A000000Noigl  >  006A000000NoiglIAB


Below is a link to this great tool!

http://www.adminbooster.com/tool/15to18



Alternatively, you can use the CASESAFEID() function in a formula field to convert the ID right in Salesforce.

Thursday, February 13, 2014

SQL List of all Column Names

Sometimes I need to find a field in the database and have no idea where to look. This query pulls back all column names in the database.

SELECT t.name AS table_name,SCHEMA_NAME(schema_idAS schema_name,c.name AS column_name FROM sys.tables AS INNER JOIN sys.columns c ON t.OBJECT_ID c.OBJECT_ID


Monday, November 18, 2013

SQL Restrict Number of Characters

I have used the 'left()' function to limit the results of a query in the past, but sometimes it does not work. The other function that can be used to limit the results of a query is substring, here is how it is used:

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 )

Tuesday, November 12, 2013

Override Button to Pre populate Fields

I found this blog post the other day and though it was very well written and very helpful!

http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html

More button code notes that are Task Button specific:

/00T/e?
who_id={!$User.Id}                                 // Set "Assigned to" to current user
&what_id={!ExpenseAccount__c.Id}   // "Related to" which object
&tsk1=Roger Wicki                                 // Override "Assigned to" with this name
&tsk2={!User.Name}                               // Related Contact's Name
&tsk3={!ExpenseAccount__c.Name}  // The Object's name
&tsk3_id=01ID0000000OiBz                // My custom object's ID
&tsk4={!(TODAY() + 7)}                          // Due Date
&tsk5=Print%20Expenses                     // Subject
// &save=1
// &save=x
&retURL=/{!ExpenseAccount__c.Id}
&cancelURL=/{!ExpenseAccount__c.Id}

For other objects you when using Google Chrome you can right click and "Inspect Element" to identify the field ID and use '&00Ni000000CKJg7' to preset a field value. This is most helpful for standard fields because you can get the same ID for custom fields by clicking on the field in the setup and pulling the ID from the URL.

Monday, October 28, 2013

Insert Merge Field Shortcut for Word (Conga Mail Merge)

Below are the shortcut keystrokes for entering a Mail Merge field into a word document.

ALT - I - F - M - M

From there you would just copy the Salesforce field name into the field name and click OK.

Tuesday, October 22, 2013

Link to local file in Salesforce

It seems there is no really easy way to link to a local file from Salesforce. After researching this topic in detail the blog post below provides the best solution to including this functionality in Salesforce. The biggest pain point in this solution for the user is that you can not click a button and be directed right to the document/folder. You have to copy the link stored in the formula field you create and copy that into a new browser window. The post takes you through the step by step process very well though.

http://salesforcetechie.wordpress.com/2013/07/19/linking-to-local-folders-in-salesforce-records/

Monday, October 21, 2013

Apex Trigger - Only Run at Point of Entry

You can put in a very simple condition that will prevent a trigger from running when bulk updates are made. This will only let the trigger run when one record is being edited at a time. This will exclude List View updates and data loader insert/updates:

if (Trigger.new.size() == 1) {

if (Trigger.old[0].isConverted == false){

}

}

Friday, October 18, 2013

Trigger Before and After Explanation

  • Before triggers can be used to update or validate record values before they are saved to the database.
  • After triggers can be used to access field values that are set by the database (such as a record's Id or lastUpdated field), and to affect changes in other records, such as logging into an audit table or firing asynchronous events with a queue.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers.htm

Wednesday, October 2, 2013

Lead Conversion Trigger

Below is the syntax for a lead convert trigger.

trigger test on Lead (before update) {
 for(Lead lead:System.Trigger.new) {
  if (Lead.IsConverted)
  //do somethign here with converted leads
 }
}

Below is a more built out example from Jeff Douglas

http://blog.jeffdouglas.com/2009/02/13/enhancing-the-lead-convert-process-in-salesforce/

Friday, September 20, 2013

Indent keyboard shortcut in Gmail

I am always having to google this because I forget it, so I thought I would put it up here for reference...

  • Ctrl-] (Windows, Linux) or Command-] (Mac): Indent text (more)
  • Ctrl-[ (Windows, Linux) or Command-[ (Mac): Remove or lessend text indentation

Tuesday, September 3, 2013

Flags, Stoplights and Images in Salesforce Formula Fields

Below are the examples Salesforce gives you for creating formula fields that will display images such as flags, and stoplights. At the bottom is a link for the full knowledge article.

Flags for Case Priority

This formula displays a green, yellow, or red flag image to indicate case priority.
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")

Color Squares for Case Age

This formula displays a 30 x 30 pixel image of a red, yellow, or green, depending on the value of a Case Age custom text field.
IF( Case_Age__c > 20, 
IMAGE("/img/samples/color_red.gif", "red", 30, 30),
IF( Case_Age__c > 10,
IMAGE("/img/samples/color_yellow.gif", "yellow", 30, 30),
IMAGE("/img/samples/color_green.gif", "green", 30, 30),
))

Traffic Lights for Status

This formula displays a green, yellow, or red traffic light images to indicate status, using a custom picklist field called Project Status. Use this formula in list views and reports to create a “Status Summary” dashboard view.
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")

Stars for Ratings

This formula displays a set of one to five stars to indicate a rating or score.
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")

Consumer Reports™—Style Colored Circles for Ratings

This formula displays a colored circle to indicate a rating on a scale of one to five, where solid red is one, half red is two, black outline is three, half black is four, and solid black is five.
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") 

Horizontal Bars to Indicate Scoring

This formula displays a horizontal color bar (green on a white background) of a length that is proportional to a numeric score. In this example, the maximum length of the bar is 200 pixels.
IMAGE("/img/samples/color_green.gif", "green", 15, Industry_Score__c * 2) & 
IMAGE("/s.gif", "white", 15, 
200 - (Industry_Score__c * 2))


https://help.salesforce.com/apex/HTViewHelpDoc?id=useful_advanced_formulas.htm&language=en#ImageFormulasTitle



Wednesday, August 21, 2013

SqlError: FILESTREAM feature is disabled

I recently ran into this filestream SQL error when trying to restore a backup database. I have restored many databases in the past with no problem so I was a bit confused by the error. After googling it I found this post and it helped to fix the error!

http://brianseekford.com/index.php/2011/05/17/how-to-fix-sqlerror-filestream-feature-is-disabled/

Essentially you need to follow the steps below:


  1. Open SQL Configuration Manager and locate your database then right click on it and open up the properties
  2. Navigate to the FILESTREAM tab and check all the checkboxes then click apply
  3. Right click on your database again and restart it
  4. Close SQL Server Management Studio if it was opened then open it up again
  5. Run the query below
    1. EXEC sp_configure filestream_access_level, 2
    2. RECONFIGURE
  6. Close SQL Server Management Studio and reopen it
  7. Now you should be able to restore the database!



Monday, July 29, 2013

Eclipse Force.com IDE Issue Resolved

Over the years I have run into problem after problem with the Eclipse Force.com IDE. Once it is working I try not to touch anything to prevent it from breaking again!

I wanted to outline the issue I recently ran into and how I resolved it.

Whenever I tried to create a project or refresh an exiting project I was getting this error:

com.salesforce.ide.api.metadata.types.Metadata$JaxbAccessorF_fullName cannot be cast to com.sun.xml.bind.v2.runtime.reflect.Accessor

After researching it, primarily on the Developer discussion boards (this one specifically: http://boards.developerforce.com/t5/General-Development/Unable-to-refresh-resource/m-p/333759#M60381 ) I tried the solutions that were suggested in changing workspaces and running as an admin and neither of those worked. So I decided to downgrade the Java JRE from 7 to 6 and this worked!

I went here to download JRE 6 http://www.oracle.com/technetwork/java/javase/downloads/jre6-downloads-1637595.html then before I installed JRE 6 I uninstalled JRE 7 from the control panel.

To check what version of Java was currently running I went to the command prompt and typed in 'java -version' below is what output:

java version "1.7.0_05" ..... before I removed version 7

java version "1.6.0_34" .... after in uninstalled version 7 from the control panel

After that I started up the force.com IDE and everything worked perfectly! 

Tuesday, July 23, 2013

Using Apex Variables in SOQL and SOSL Queries (SOQL IN Clause)

I spent some time looking for this documentation around using the SOQL IN clause with a list and wanted to save it.

I basically want to run a SOQL query that is looking at a list of String values in the WHERE condition, like this:

// 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];


http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_variables.htm

Sunday, July 21, 2013

Basic For Loop

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());
 
  }
 
 }
 
}