Skip to main content

Posts

How to get help text in apex class ??

We generally use help text while creating custom field in salesforce . Sometimes we need it in apex controller while development. This post is regarding to get help text of particular field and display in vf page.  Here is some code snippet to get help text in apex class. Schema.DescribeFieldResult dfr = Schema.sObjectType.Account.fields.TestField__c; String helptext = dfr.getSObjectField().getDescribe().getInlineHelpText(); In the visualforce page we can display help text. {!$ObjectType.Account.fields.TestField__c.inlineHelpText}

How to check list size in Visualforce page

Hi All, It seems to very simple by name but not as much simple as you are thinking now.As we all know list itself has a method so called size() to check its size,however we can write list.size() in controller, which will return no. of elements present in the list otherwise return 0 if no elements present .But we can not write list.size method in visual-force page,then how will we check ???? For that I have done a workaround, one visual-force page is there having one field Account Type. When Account Type will be selected with some value ,then list of Accounts records will be displayed whose Account Type is matched with the selected value otherwise a message saying No Accounts Present in this Type. Here is page:- <apex:page controller="passingParamActionFuncController">     <apex:form >         <apex:pageBlock title="Account Information" id="pb">             <apex:pageBlockSection >   ...

How to do DML Operation when a Page loads

Hi All, Here is a scenario that I have come across, there was a need to do DML operation when a vf page loads. How will we achieve it ? As we all know when a page loads, constructor executes first but we can not write DML statement in constructor,however there is another approach for the above requirement.  Here is the Page.  <apex:page controller="DMLStatementOnPageloadController" action="{!createAccount}" > </apex:page> createAccount will be invoked when page loads. Controller:- public with sharing class DMLStatementOnPageloadController {     public PageReference createAccount(){         Account acc = new Account(name = 'DMLStatementOnPageload');         insert acc ;         return null;     } }

How can we check singly email limit ?

We can send emails programmatically in Apex, however  if we're not careful we can hit the measly governor limit of 10 in no time at all. We know, although  outbound email limit is 1000 with Apex, but only a total of 10 sendEmail method calls are allowed in each context. Obviously the way to avoid this is to gather up all emails we want to send in a list and call the sendEmail method once from your Apex context. When passing an argument to the sendEmail method it must be of type Email.  In the mean while we need to check how many times we have already called send email method in a transaction and how more are remaining. How will we do that? Below is the few lines of code. Integer used = Limits.getEmailInvocations(); Integer emailLimit = Limits.getLimitEmailInvocations(); System.debug('print--used ->'+used ); System.debug('print--emailLimit ->'+emailLimit );

How to pass lookup field id to controller?

Lets take an example. Suppose we want pass Accountid(look up field from contact to account) from visual force page to controller. If we choose one account from look up then automatically account industry will be populated. Here is the page:- <apex:page controller="passingLookupIdController">   <script>     function doSomething(test) {                alert('hi-->'+test);         PassingParameter1(test);         // lkfield.value now has the selected ID value     }     </script>  <apex:form >   <apex:actionFunction name="PassingParameter1" action="{!PassingParameter}" reRender="field1">   <apex:param value="" name="recordId"/>   </apex:actionFunction>    <apex:pageBlock >         ...

How to use required attribute in picklist as like salesforce standard?

There is an attribute called Required which can be used in almost all visual-force component.If we use that attribute then red color mark will be appended with the field and if we don't enter any value ,try to save,then it shows one error(You must enter some value) just below to that field.  For example:- <apex:inputField value="{!account.Industry}" id="field1" required="true" />  Here Industry is a standard pick-list, if we write required = true, red mark is coming,however if we are making pick-list in controller and displaying using <apex:selectlist> and <apex:selectoptions> then red won't be displayed.  <apex:selectList label="Picklist" multiselect="false" size="1" required = "true" >                <apex:selectOptions value="{!options }">                   </apex:selectOption...

How to permanently delete record from data base.

As we all know if we delete records from our org. It will be stored in recycle bin for 15 days. We can go to recycle bin and delete manually.  Suppose the requirement is when we delete records those records should be deleted from recycle bin. For this requirement we have to write a trigger on object.  trigger todelteRecordPermanent on Account (after delete) {     list<Id> Ids = new list<Id>();     for(Account  account: Trigger.old){         Ids.add(account.id);       }     Database.emptyRecycleBin(ids); }