Friday, 23 November 2012

Sending Document as an attachment in the form of Pdf Using Workflow Rules of platform and Visualforce Template feature

Emailing the pdf on click of a boolean check box or click of a button are frequent requirements for which we often think of using Triggers and using Outbound Emails of apex .

This requirement can be easily accomplished through workflow rules and the Visualforce Email Templates

In this blog POST will walk through on how to approach this

Step 1:
Creation of Email Field This is the first step to create an Email Field so that when we develop workflow rules when for the email alert the Recipient Type is asked we may fill in the email field
Step 2:
Creation of workflowThis is a simple step where based on business criteria draft a workflow rule.Usually rule should be to trigger the email alert only if the boolean flag is checked .
Step 3:Creation of email template The email Template will be a visualforce template and hence if you are familiar with visualforce this must be a straight forward impementation
Below is the sample code that you may customize by replacing with your relevant object name

   Please find your  receipt attached with this mail.



<!-- Section to insert header-


Label1 Label 2 Label 3

Image From Notes and Attachment

If have any image to display from documents then you will have to use the following ImageServer?id=BBB&oid=CCC AAA = your SFDC server, found in the URL of any SFDC link after you log in BBB = the record ID of your publicly available document CCC = your organization ID You can pull from documents.Dont pull from static Resource .It never works .
I answered couple of questions in stackexchange recently and this promoted me to write this blog post so that may help .

Sunday, 4 November 2012

Native Parsing Of JSON input into User Defined Class through Apex Rest Service

I have walked into Apex Guide of SFDC to find if there are code samples for the parsing of the JSON into User defined Class in apex.Unfortunately document mentions that this can be achieved but still there were no code snippets i could find.

This blog post might help for small snippet reference to understand how we can write an apex class and structure the Constructor of the POST annotated method to achieve native parsing automatically.
Here is the Code Snippet of the Class . Note that the Request is a combination of Account and Contacts and hence we may need an inner class .

global with sharing class MyRestResourcedemo{

//User defined Class

global class RequestWrapper{
Account acct;
Contact[] cons;

//Response Wrapper Class
global class ResponseWrapper{           
public String StatusCode;
public String StatusMessage;
public Account acct;
public Contact[] cons;    

global static ResponseWrapper doPost(RequestWrapper reqst){

ResponseWrapper resp = new ResponseWrapper();
insert reqst.acct;
for(Contact c:reqst.cons){
c.AccountId = reqst.acct.Id;
Upsert reqst.cons;
catch( Exception e ){
resp.statusCode = 'Error';
resp.statusMessage = 'Exception : ' + e.getMessage();
resp.statusCode = 'Done';
resp.statusMessage = 'Test success message';
resp.acct = reqst.acct;
resp.cons = reqst.cons;
return resp;
The Request Body is as shown below
    "reqst" :
            "acct" : { 
                        "Name" : "Test Account 1",
                       "AccountNumber" : "00000001",
                       "Site" : "Site1",
                       "Website" : ""
                    { "Name": "Test Contact1", "email" : "", "LastName":"TLName2"},
                    { "Name": "Test Contact2", "email" : "", "LastName":"TLName3"},
                    { "Name": "Test Contact3", "email" : "", "LastName" : "TLName"}

The Workbench has REST Utility that simplifies testing.Attached the snapshot.

Introducing Lightning Base Components

Lightning Base Components are great addition to the platform and in fact revolutionary .One of the concerns around lightning component ...