Monday, November 24, 2014

Design a Visualforce Mail Template


Are you looking around on "how to design a Visualforce mail template?" Let’s see how we can design the template with images and styles.

    Steps to create a Visualforce Email Template:
  1.  Administer – Communication TemplatesEmail TemplatesNew Template
  2.  Select the type of email template as Visualforce.
  3.  Select the folder where you want to store your template.     
  4.  Select the Available for use check box to make it available to users when sending mail.
  5.  Name your email template.     
  6.  Select an Encoding setting to determine the character set for the template.
  7.   Enter the Email Subject(i.e., Here I entered it as Welcome)      
  8.  Select the Recipient type (Contact, Lead and User – One who receives the mail)
  9.  If you want to merge fields in your template then select the object you want in the  Related to  Type.      
  10.  Once you click save, click edit template to write Visualforce to design the template.
      Code Snippet:
      
<messaging:emailTemplate subject="Welcome" recipientType="Contact" >
  <messaging:htmlEmailBody>
      <html>
         <body>
           <table border="0" cellpadding="0" cellspacing="0">
              <tr>
               <td><apex:imageurl="https://instanceurl/servlet/servlet.ImageServer?id=yourimagedocumentid&oid=Organizationid"
width="38" height="38"/></td>
              </tr>
          </table>
       </body> 
     </html>
  </messaging:htmlEmailBody>
</messaging:emailTemplate>






For complete code visit the github link here.

Note:
 
Add an image to the documents tab. (To add image in the Visualforce mail template)
Once saved the image, get the image URL by right click on it.
Add that image URL to the following apex tag,
<apex:image url="https://instanceurl/servlet/servlet.ImageServer?id=your imagedocumentid&oid=Organizationid" width="38" height="38"/>



Screenshot for the Visualforce Mail Template


Tuesday, November 18, 2014

Abort Scheduled Apex Job


Well, If you don't find a way to abort the job that you have scheduled it via execute anonymous then here is the answer for you.



For ex:
I have a schedule class named schedGroupAccounts and I scheduled it for every 15 minutes via the execute anonymous in the developer console.

Code Snippet for Scheduling apex class
System.schedule('Scheduled Job 1','0 15 * * * ?',new schedGroupAccounts());
To monitor your apex jobs, go to Setup -> Monitor -> Jobs -> Apex Jobs.

So you scheduled it, now you want to abort the job for some reason. How can you do? The jobs we schedule will be available in the crontrigger object. Lets query the trigger and see how we can retrieve the particular job to abort it.
SELECT CreatedById, CreatedDate, CronExpression, CronJobDetailId, EndTime,Id, LastModifiedById, NextFireTime, OwnerId, PreviousFireTime, StartTime, State, TimesTriggered FROM CronTrigger
So from the above query, I found my job based on the cronexpression and createddate. I want to abort that job. So I get the id of the job and assign it to the soql query.

CronTrigger ct = [SELECT Id FROM CronTrigger where Id='']; 
System.abortJob(ct.Id);  

Thursday, November 13, 2014

PROCESS BUILDER - ADMIN BOOSTER

It is a new workflow tool to automate your business process by providing a powerful and user friendly visual representation of your process as you build it.


What you can do with this?

Create a record
Update fields on any related record
Launch a trigger-ready flow
Send an email
Post to chatter
Submit for approval
Publisher Actions

So you don’t need to write an apex code, you can easily do all this with this super wow feature ‘Process Builder’

How it is different from a workflow rule?

Process builder can automate every action that can be automated in a workflow rule except outbound messages.
You don’t need to create multiple workflow rules instead you can have a single process that can have multiple actions.

So want to try it out?

If your org is winter ’15 release, you can log a case with support to enable this feature. This is in beta version.

Links for reference:




Wednesday, January 8, 2014

MavensMate for Windows installation guide

 MavensMate plugin for sublime text, every Salesforce developer love to play with it.Powerful open source tool for building Force.com IDEs. Develop Force.com applications in your favorite text editors, like Sublime Text.
To install MavensMate, we need to have the following
Sublime Text 3 - Easy to install
Git - For Git, please follow the settings as below,




So we have Git and sublime text installed successfully in our windows. Download MavensMate plugin and just run the installer. When I tried to install mavensmate, I got the following error 


To resolve this, I just unset proxy configured by the following command
git config --global --unset http.proxy
Then I turned off the firewall settings. Once these changes done, I tried MavensMate installer again. Finally it got installed successfully. If the installation is successful, you will find mavensmate plugin in sublime text editor as shown below

To make mavensmate work we need to configure settings. To configure, Go to MavensMate menu in Sublime Text > Settings > User  . Mavensmate sublime settings page will open. 

set mm_workspace to the location where you'd like your MavensMate projects to reside.

Set mm_windows_subl_location to the location where your sublime text 3 is installed. Eg., C:/Program Files/Sublime Text 3/sublime_text.exe

Now we are ready to go, Go to MavensMate menu in Sublime Text >Project>New Project and a browser with a screen that prompts for Salesforce credentials.


Happy Salesforcing :)