Search This Blog

Monday, June 27, 2016

JVM terminated.Exit Code=2

Problem: Unable to open eclipse as it is giving the above error when it is opened.
image

Solution:
Step 1: Go to the path which is specified in the error window next to error line in your computer/laptop (path hightlighted in red color in above image).
Step 2: Make the folder empty by deleting all (here javapath folder to be made empty).
Step 3: Re-Open the eclipse again.Now it will work....

Hope this helped..Enjoy.

Sunday, June 26, 2016

How to get recordTypeId in Test Class

Assume 'Supplier' is the recordtype in Account Object as shown in image below.

If you want to get that supplier record type id in apex,We need to first prepare a map of all recordtypes of that account object and then get our required record typeid from it.
Sample Code:
Map <String,Schema.RecordTypeInfo> recordTypeMap = Account.sObjectType.getDescribe().getRecordTypeInfosByName();
Account accountObj = new Account();
accountObj.name = 'Test Record Type';
if(recordTypeMap.containsKey('Supplier')) {
accountObj.RecordTypeId= recordTypeMap.get('Supplier').getRecordTypeId();
}
insert accountOb;
system.debug('CreatedAccountId'+accountObj.id);
Output :

Thursday, June 23, 2016

Portal Account Owner Has No Role

Problem : This error will arise when no role was assigned to the user who is the owner of the portal account.


Solution :  Go to the owner of the associated account,and then assign a role to that user.

Regular expression to remove consecutive alphabets in apex

Examples :If input is "aabbbbcccdddd" output should be "abcd".
Piece Of Code: 
String str ='aaaabbbbcde';
string resultedString = (str).replaceAll('(.)\\1+', '$1');

System.debug('resultedStringresultedString'+resultedString);


Output :

Thursday, June 9, 2016

Calculate Age from Date Field.

Formula to calculate Age from date field.For Example Birthdate is date field in contact Object.

IF( NOT( ISBLANK( Birthdate ) ) ,
IF( DATE( 2000 , MONTH( Birthdate ) , DAY( Birthdate ) ) <= DATE( 2000 , MONTH( TODAY() ) , DAY( TODAY() ) ),
YEAR (Today()) - YEAR ( Birthdate ),
YEAR (Today()) - YEAR ( Birthdate ) -1 ),
null)

Sample Output:

Monday, June 6, 2016

How to display special characters like comma,$ etc in visualforce page

Sample Visualforce page to display comma,ampersand and asterisk
<apex:page>
To display ampersand : &#38;<br/>
To display asterisk  : &#42;<br/>
To display comma     : &#44;<br/>
</apex:page>
Output:
Note : Go through the link for more symbols and their associated code to be used to display it in visualforce page. Symbols

How to rename standard fields in salesforce

Example :To rename "Account Name" field of Account as Customer Name
Steps:
Step 1:Go to Setup --> Build --> Customize --> Tab Names and Labels --> Click on "Rename Tabs and Labels".

Step 2: Click on edit next to concerned object.In this case click on Edit before Account object.

Step 3:Click on Next.The following Screen appears.Rename the concerned field in Singular column as shown in image below.


and then click on "Save".
Label before rename looks like this
Label after rename looks like this

Convert Datetime to date in Apex

DateTime newDateTime = System.now();
Date newDate = date.newinstance(newDateTime.year(), newDateTime.month(), newDateTime.day());