How to send email using apex

From Salesforce you can send emails using multiple methods. Commonly we will be image using workflows to send emails. But it is common to come across requirements that require more sophisticated email which might contain attachments. Please check below to see sample code to send email with attachments using apex,

Steps to Use

1) Get details regarding email body, attachments, to address etc.

    You need get some basic details and take some design considerations before starting development. Salesforce allows only 10 emails to be sent in one apex transaction. So if you are sending email from a trigger for each record it will fail, when data is loaded through data loader in bulk. In addition to this, there will be organization level limit in number of emails that can be sent in one day. But this limit is usually high(1000 x number of users).

3) Reuse below code to send simple email (minimum example)

    Please check below code sample to send a very simple email from apex.


3) Reuse below code to send email with attachment (full example)

    Please check below code sample to send email from apex.


This sample code receives a string of TO email addresses separated by commas, a String of CC email addresses separated by commas, email subject and email body as string. This method also creates a text attachment in the email.

4) Additional reference

    In addition to the methods used above there are many built in salesforce methods and supporting class related to sending emails. Please check below links for additional details,

Single Outbound email

Messaging Class

Send Email Result

How to use Google Charts in Visualforce pages

Usually you might come across requirements to show charts in visualforce page.image Salesforce’s built in analytics solutions is good. You can even embed those charts in your regular visualforce pages without much difficulty. But the only limitations is that some types of charts are not available in visualforce page. Another one common use case is community pages. Salesforce charts can be used in community, only if users have partner community or community user plus licenses, which are bit more costly. In such cases, you will have to go for third party charting solutions like Google Charts, Fusion charts etc. Here is an example of how to embed a Google chart in visualforce page.

Steps to Use

1) Understand the data requirements of the chart you need

    You can find the list of all Google charts at charts gallery. Once you have found the right chart for your requirement, you need to check the data requirements of the chart. Each chart requires data in some specific format.

2) Format data in visualforce page controller in the required format

    Once you have found the right format for data, next step is to format data in that format before sending to chart.

3) Visualforce page and controller implementation of doughnut chart

    Check out below code where a doughnut chart is displayed with attendance of student. In the controller different attendance values are aggregated and passed that to page level using properties,





Use Cases

  • Whenever charts need to be shown in visualforce pages
  • Wherever standard Salesforce charts are not fitting your requirements
  • If you have regular community licenses and want to show charts to users, Google charts is a good alternative.

 

Integration between Java app and Salesforce – Partner WSDL

It is very common for any Salesforce developer to come across scenarios involving integrationsalesforcecodes logo between Salesforce and other systems. Most of these systems are based on JAVA. In this post we will cover how to integrate between Salesforce and a locally running Java application. The same logic and code can be used to connect to Salesforce from a web based java application also.

Steps to integrate

1) Download Partner WSDL from your sandbox 

    You can find Partner WSDL in your salesforce sandbox under Setup – Develop – API. Download partner WSDL file from above location to your local system folder.

2) Get WSC (Webservice connector) jar file provided by salesforce.  

    This jar file was initially provided by salesforce as .jar itself. Force.com webservice connector is a high performance webservice client stack implemented using a streaming parser. This gives some advantages compared to regular java classes generated from partner WSDL using other WSDL to Java tools. You can find source code to latest version of source code in force.com WSC github.

First clone the repository to your system and then build jar file using the instructions given.

3) Generate Partner.jar using WSC (Webservice connector) jar generated in step 2  

    You can convert partner WSDL into a jar file using WSC jar file. It is single command from command line, which can be found in the above github link.

4) Create project in eclipse 

    By the end of step 3 you have all the components needed for connecting to salesforce. Now create a new java project in eclipse. Import wsc.jar from step 2 and partner.jar from step 3 as external libraries. Then create a new class with name “PartnerExample” in the project. Then copy paste the code below,

It should compile without any error. Use Runas Java application option in eclipse to run the project. This code queries 5 contact and creates an account

Reference links

There is lot of good resources demonstrating similar connectivity options between salesforce and java applications. Please check below links,

How to pass ADM 201–Salesforce certified administrator

ADM 201    ADM 201 or Salesforce certified administrator certification assesses you for the knowledge required to maintain a salesforce instance in a company. It checks candidates ability to configure an application in force.com application. But it does not evaluate against coding aspects like apex and visualforce.Difficulty wise it is a bit more tougher than DEV 401. ADM 201 syllabus contains all the topics needed for DEV 401 along with some additional contents like basic knowledge in sales cloud, service cloud, chatter, reporting, user setup, securing application etc. Detailed syllabus can be found in below link.

Syllabus / Study guide 

    First and mandatory thing to do while preparing is to go through the above study guide. It will give you a very good understanding regarding different areas against which you will be assessed.

Structure of Exam

    It is a multiple choice exam with 60 questions. You will get 90 minutes to complete the exam and need 65 percentage(39 correct answers) to pass the exam. Exam fee is $200. If you failed in first attempt, second attempt can be done with a fee of $100. Most of the companies have partnership with salesforce.com through which they will be able to get vouchers for exam. So if you are from a partner company of Salesforce, try to get a voucher from your company.  

Materials to prepare

    This certification is demanded by companies looking for administrators. The role of an administrator in small to medium sized companies includes tasks like maintaining the production sandbox, creating users, managing security, running reports etc. Many business analysts who does not have plan to go to development side of salesforce.com also takes this certification. Salesforce.com recommends its “Administration Essentials for new Admins” instructor led training program as a preparation for this certification. But it is a paid training. If you cannot afford paid training, you can pass it preparing with resources available online. Also there are many people who pasted notes from salesforce training online. For example check  ADM Notes in this blog. Please find the list of other free resources to prepare for the exam,

  • Force.com Fundamentals - You can find HTML/PDF version of the book in salesforce documentation. It walks you through creating a recruiting application in force.com platform. It might look bit time consuming initially, but it is a very good resource and gives clear understanding of most of the aspects of force.com platform. Try to build recruiting application on your own with the instructions given in the book.
  • Create your own Developer Org and practice – Salesforce offers free developer org for anyone who is interested to practice. You can create your own org in registration link.
  • Online Free Training – Salesforce offers free online training videos. Once you have registered for developer org, you can access these materials from the “Help” link in top right corner of your developer org. It will give you access to lot of videos regarding different aspects of force.com platform. Again if your company is a partner of salesforce, you can get access to premium online training videos. Out of those videos “Administration Essentials for New Admins”, “Administration Essentials for Service Cloud” etc are very useful. Salesforce offers trail head training which is free and gives practical experience.
  • Online blogs – There are many good blogs explaining about all the topics in the study guide. For example you can check – Cloudsocius blog. You can check salesforce documentation for additional materials regarding any topic related to force.com platform. Just search in Google for additional new blogs. There are many coming up every day.
  • Flash card training – These are basically sample questions very similar to the actual questions in exam. This you can use as the last step in practice. Once you have gone through all materials, you will be able to answer most of the questions. If there are some questions you are not able to answer, prepare more in that area and attempt again. Some good flash card training sites are – cram , Quizlet etc.

 

I am certified. Now what?

    Congrats. It is time to celebrate. But remember that now you have to maintain your certification. Salesforce require you to maintain DEV 401 and ADM 201 certifications. Every year there will be three releases(updates to the platform) for Salesforce. Associated with each of these there will be maintenance exams. So every year you have to write thee maintenance exams. But these are online exams, based on release updates. These are easy exams, which you can clear easily if you go through release notes. After your initial certification, two consecutive release exams are free for you. But after that you will have to pay $100 every year once for maintenance exams. So always remember to take maintenance exams on time, otherwise your certifications will become invalid.

Also ADM 201 certification is a mandatory requirement before you can take Sales cloud consultant, Service cloud consultant and advanced administrator certifications. Make a good study plan and start preparing towards it.

How to pass DEV 401 - Salesforce Developer Certification

DEV 401     DEV 401 or Salesforce.com certified developer is the easiest of the salesforce certifications. It asses the capability of the candidate to configure force.com applications. But it does not cover any coding topics like apex or visualforce pages. Detailed syllabus can be found in below link.

 
    First and mandatory thing to do while preparing is to go through the above study guide. It will give you a very good understanding regarding different areas against which you will be assessed.
 

Structure of Exam

    It is a multiple choice exam with 60 questions. You will get 90 minutes to complete the exam and need 68 percentage(41 correct answers) to pass the exam. Exam fee is $200. If you failed in first attempt, second attempt can be done with a fee of $100. Most of the companies have partnership with salesforce.com through which they will be able to get vouchers for exam. So if you are from a partner company of Salesforce, try to get a voucher from your company.  

Materials to prepare

    It is a very popular certification and so very good resources are available to prepare for this certification. Salesforce.com recommends its instructor led training program, but as it is costly and it is not a difficult certification, you can very well prepare on your own and clear this certification. Below are the list of free resources to prepare for the exam,

  • Force.com Fundamentals - You can find HTML/PDF version of the book in salesforce documentation. It walks you through creating a recruiting application in force.com platform. It might look bit time consuming initially, but it is a very good resource and gives clear understanding of most of the aspects of force.com platform. Try to build recruiting application on your own with the instructions given in the book.
  • Create your own Developer Org and practice – Salesforce offers free developer org for anyone who is interested to practice. You can create your own org in registration link.
  • Online Free Training – Salesforce offers free online training videos. Once you have registered for developer org, you can access these materials from the “Help” link in top right corner of your developer org. It will give you access to lot of videos regarding different aspects of force.com platform. Again if your company is a partner of salesforce, you can get access to premium online training videos. Out of those videos “Building Applications with Force.com – Part 1" and its part 2 are very useful for DEV 401. There are many other free online video trainings like – Udacity course
  • Online blogs – There are many good blogs explaining about all the topics in the study guide. For example you can check – Cloudsocius blog. You can check salesforce documentation for additional materials regarding any topic related to force.com platform. Just search in Google for additional new blogs. There are many coming up every day.
  • Flash card training – These are basically sample questions very similar to the actual questions in exam. This you can use as the last step in practice. Once you have gone through all materials, you will be able to answer most of the questions. If there are some questions you are not able to answer, prepare more in that area and attempt again. Some good flash card training sites are – quizlet , proprofs etc.

 

I am certified. Now what?

    Congrats. Now you have to maintain your certification. Salesforce require you to maintain DEV 401 and ADM 201 certifications. Every year there will be three releases(updates to the platform) for Salesforce. Associated with each of these there will be maintenance exams. So every year you have to write thee maintenance exams. But these are online exams, based on release updates. These are easy exams, which you can clear easily if you go through release notes. After your initial certification, two consecutive release exams are free for you. But after that you will have to pay $100 every year once for maintenance exams. So always remember to take maintenance exams on time, otherwise your certifications will become invalid.