Friday, May 23, 2014

Salesforce - Common footer and sender email address for all emails from one department

if you are in situation where you are sending email out from salesforce and you want to use same  sender email address and footer.Lets say you are from customer service department and you department tag line is Best in service:) and you want to send email always from one email id for customer service department.

Follow below steps-

Common email footer(Organization wide email footer):-
1)login to salesforce
2)click on setup, in Admistration setup section click on Email footers then click on new on email footer screen.
3) enter all the details and click on same.

Common Email address :- 

1)click on setup
2) click on setup, in Admistration setup click on organization-wide address and then click on Add
3)fill the details and select the profile like customer service profile or depends on you situation and click on save


Thursday, May 1, 2014

Salesforce Trigger On After Insert

If you want to know what is salesforce trigger and when can we have trigger run ,please check my previous post about Salesforce trigger.

In this post i will  be explaining how you can run your trigger after insert of record into database.

Lests take an example.

if you want to send email to someone in your organization  after every new account is created

so you will need
1) Trigger implementation
2) Html email body/template
3) email receipants

Trigger Implementation:

From Setup, click Customize -> Accounts -> Triggers
In the triggers section, click New.
In the trigger editor, delete the default template code and enter this trigger definition:
1.  trigger NewAccountCreationSendEmail on Account (after insert)      { 2.           for(Account act: Trigger.New)                {                        //code to send email Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String toEmail = ""; String[] toAddresses = new String[] {toEmail}; mail.setToAddresses(toAddresses); mail.setSubject('New Account is created'); String template = 'Hello {0}, \nNew Account has been Created. Here are the details - \n\n'; template+= 'Account Name- {1}\n'; template+= 'Account Owner - {2}\n'; template+= 'Account Contact - {3}\n'; List args = new List(); args.add(toEmail); args.add(act.Name); args.add(act.OwnerId); args.add(act.AccountNumber); String formattedHtml = String.format(template, args); mail.setPlainTextBody(formattedHtml); Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});                }      }
First line of  code defines the trigger

trigger Trigger_Account_Send_Email on Account (after insert)

It gives the trigger a name, specifies the object on which it operates, and defines the events that cause it to fire. For example, this trigger is called NewAccountCreationSendEmail, it operates on the Account object, and runs after new Accounts are inserted into the database. 

Second line in the trigger is for loop of Account records  referenced by contents of a trigger context variable called Trigger context variables such as are implicitly defined in all triggers and provide access to the records that caused the trigger to fire. In this case, contains all the new Accounts that are  inserted.

for(Account act: Trigger.New)

You can use same trigger before insert,you just have to change parameter on first line from "after insert" to "before insert"

Wednesday, April 30, 2014

What is Salesforce Trigger

Salesforce Trigger:-

Salesforce trigger is apex code that executes before or after the folowing types of operations.
  • insert    -  You can have this trigger run  before or after objects records are inserted into database.
  • update  -  You can have this trigger run  before or after objects records are updated into database.
  • delete   -  You can have this trigger run  before or after objects records are deleted from  database.
  • merge   -  Merge events do not fire their own trigger events. Instead, they fire delete and update event
  • upsert   -  Fire both before and after insert or before and after update triggers as  appropriate
  • undelete- record is restored from the Recycle Bin 

I will be explaining each trigger with example in next tutorial.

Tuesday, April 22, 2014

Sonar and Sonar runner with Jenkins

Configure  Sonar and Sonar runner with Jenkins

1)Install sonar plugin in jenkins
2)Download sonarqube( and unzip it  into C:\KB\sonar\sonarqube-4.1.2
3)Open file from conf folder and uncomment below properties


you will have to create sonar database

4))Open command prompt and type cd  C:\KB\sonar\sonarqube-4.1.2\bin\windows-x86-64

5) Run StartSonar.bat

6) Configure sonar through manage jenkins->configure system

7))Download sonar runner and unzip it intoC:\KB\sonar\sonar-runner-2.3
8)Open file from bin folder.
add this line at start below set ERROR_CODE=0
set SONAR_RUNNER_HOME=C:\KB\sonar\sonar-runner-2.3
and replace existing set  PROJECT_HOME with set PROJECT_HOME=C:\Jenkins\jobs\\workspace\
9)Configure sonar through manage jenkins->configure system

10) Now open job configuration from jenkins for which you want to run sonar
 and in Add Build Step select Invoke Standalone Sonar Analysis

11)Save the configuration  and then run the build for job.