Wednesday, 16 December 2015

Fetech contacts data in excel sheet through visual force page


<apex:page controller="FetchdatathroughCSV" sidebar="false" action="{!Fetechdata}" cache="false" contentType="text/plain/#contacts.csv">
<apex:repeat value="{!con}" var="r">
  {!r.firstname}{!r.lastname}
</apex:repeat>
</apex:page>
public class FetchdatathroughCSV {  public List<Contact> con {get;set;}  public PageReference Fetechdata()  {    con = [Select Id ,firstName ,LastName from contact limit 10];    return null;  } }

Dynamically select the record type by using custom button javascript

When i tried to create a contact record without selection of record type it is not possible from the standard button. So i came up with some custom java script button.

To create a custom button navigate to Setup- Customize - Contacts - Buttons, Links, and Actions

Click on Buttons, Links, and Actions and click new Button or link. Give the Name and api name and select the Display Type as List Button, behavior as Execute javascript and content source as onclick javascript.

Paste the below code in the space provided. change the recordtype name to your record type name.

{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 
 
var qr = sforce.connection.query("SELECT Id FROM RecordType WHERE SobjectType ='" + "Contact" + "'" +" AND DeveloperName = '"+"RecordTypeName"+ "'"); 
var records = qr.getArray("records"); 
 
if(!records.isEmpty)
 var redirecturl="/003/e?retURL={!Account.Id}&con4={!Account.Name}&con4_lkid={!Account.Id}&RecordType="+qr.records.Id; 
 window.location=redirecturl; 
}