Skip to main content

Posts

Populating merge field in email template while sending mail from apex.

Hi All, You might have come across the issue of populating custom object info in email template dynamically. Suppose you have designed one email template having merge fields of contact object and one custom object. if you will send a mail from apex using singleEmailmessagApi then only contact merge field will be populated.This is an existing behavior of sfdc. How do we overcome this issue?? As we know if we will use setTemplateId method to set email template which we have already designed then we need to use setTargetObjectId method(Mandatory method ).  setTargetObjectId only accept Contact,User and Lead id that is why  those object merge fields will be populated in email template. Now the question is how can we pass custom object id ?. If we are setting contact id in setTargetObjectId  here then we can use another method called   setWhatId ,there we can pass custom object id.That means if we are sending mail to contact mail then we can pass custom obje...

How to add Salesforce Chatter Information in Visualforce Page??

Adding chatter functionality in to visualforce is quite simple. Use below tags. <chatter:feed>: Displays the Chatter feed for a record. <chatter:feedWithFollowers>: An integrated UI component that displays the Chatter feed for a record, its list of followers, and optionally, a header bar that allows users to show or hide the Chatter feed and subscribe to it. <chatter:follow>: Renders a button for a user to follow or unfollow a Chatter record. <chatter:followers>: Displays the list of Chatter followers for a record. <chatter:feed entityId="{!Leadid}" /> <chatter:follow entityId="{!Leadid}" /> <chatter:followers entityId="{!Leadid}" /> Id LeadId =  ApexPages.currentPage().getParameters().get('id');

Phone Validation For USA format.

Hi  We all know USA phone number "(999) 999-9999" . How do we restrict user from invalid entry ? We can create validation rule. Error Condition Formula:- NOT(REGEX(Phone__c, "^\\(\\d{3}\\)\\s?\\d{3}-\\d{4}")) Error Message:- US phone numbers should be in this format: (999) 999-9999. if you want to add validation in controller, below is the method public static boolean isValid(String phone){                       String PhoneRegex =  ' ^\\(\\d{3}\\)\\s?\\d{3}-\\d{4} ';                  Pattern MyPattern = Pattern.compile(PhoneRegex);                  // then instantiate a new Matcher object “MyMatcher”         Matcher MyMatcher = MyPattern.matcher(phone);         if (!MyMatcher.matches()) {         return false;        ...

How to refer custom html page from document in visualforce page.

Hi All,  I came across one requirement during work, thought to share, it will be useful info for you. I was working on designing partner portal site for user,as you all know for designing site,we have to take care of company branding, header and footer and lot more style sheet and css, and it's not a best practice to use all the code in vf page itself ,because same header and footer might be required to be used in several pages,so it's better we will keep it separately whenever it is required we can refer it. We have stored header and footer code(html page with css) in document object in sfdc.Now the question is how can we refer it in vf page? If we have stored in static resource it is quite simple to refer it.(use global variable $Resource). Solution:- Use Below code to refer this.     public String getHeader() {                  return [Select Body,Name From Document Where Name  = 'Header'].Body.toString(); ...

Searching Component In SFDC

Hi All, This is a  cool post for me.Here I have created one page where you can search many sfdc component(apex class,vf pages, user,report,approval process, trigger).  Useful for Whom ? All developers who always try to finish work as son as possible. Don't want click on Next & Prev link to reach at particular component(if more than 100 is there). Want to get all different component in one page. The best thing is with in less time to get component. We can search these component as below image.if you want to search more than add that component in options list rest will be take care. Here is the Page:- <apex:page controller="SearchApexComponent">     <apex:form >                  <apex:pageBlock title="Find Your SFDC Component" id="pblock">         <apex:pageMessages id="message"></apex:pageMessages>          <apex:outp...

Filtering Record Using Long Text Area Field

Hi All, We might have come across a scenario to filter some record based on a field value which is long text area type.This is post is all about how can we filter records using text area field value. Here is code:- String s; list<Account> listOfAccounts = [SELECT id,name FROM Account WHERE TextAreaFiedl__c like :'%'+s+'%']; If we write same code then compiler will fire a error like below image. Below is work around for above error. String s = 'asish'; list<Account> listOfAccounts;  listOfAccounts = new list<Account>(); for(Account acc:[SELECT id,name,TextAreaFiedl__c FROM Account where name='test']){     if(acc.TextAreaFiedl__c.Contains(s)){        listOfAccounts.add(acc);     } }

How would we get recordtype id and recordtype name of an particular Object?

Hi All, Sometimes it may require to know the recordtypeid and recordtypename of an object in apex class.This is post is all about to make you comfortable with Recordtype methods.I am assuming you have concept of recordtype. Below is few code snippet to make you comfortable with recordtype method. RecordTypeInfo is a class contains methods for accessing recordtype information for an sObject with associated recordtype. getRecordTypeInfosByName(); - Returns maps that associate RecordTypeInfo with  record labels. getRecordTypeInfosById();- Returns maps that associate RecordTypeInfo with  record Id. getname():- Returns recordtype name. getRecordTypeId() :- Returns recordtype id. isAvailable() :-Returns true if this record type is available to the current user, false otherwise isDefaultRecordTypeMapping() :-Returns true if this is the default record type mapping, false otherwise. Here Contact is the standard object and Service Contact is the recordtype name. Sch...