Thursday, 12 December 2013

Detail Page Link in Apex Class

Hi

below is the code where you get detail page link in Apex Class or trigger.

str= System.URL.getSalesforceBaseUrl().getHost();
str = str + '/'+ oldOpp.Id;
System.debug('---------System URL-----------------'+ str);

Tuesday, 3 December 2013

Creating Excel in Visualforce Page.

Create a visualforce page and add the content type attribute in the <apex:page>

<apex:page standardController="Opportunity" extensions="OpportunityReport_Extn" showHeader="true" sidebar="true" cache="true" contenttype="application/vnd.ms-excel#Opportunity_report.xls">
  <apex:pageBlock >
       <apex:pageblockTable value="{!generateReport}" var="oppty" id="tbl1">
           <apex:column value="{!oppty.Name}"/>
           <apex:column value="{!oppty.Id}"/>
           <apex:column value="{!oppty.StageName}"/>
           <apex:column value="{!oppty.Closedate}"/>
           <apex:column value="{!oppty.Type}" />
       </apex:pageblockTable>    
   </apex:pageBlock>
</apex:page>

In this page I have used controller, below is the code for that.

public class OpportunityReport_Extn {
    public List <Opportunity> getgenerateReport()
    {
       query = 'select Closedate,Name,Type,StageName,Id from Opportunity';    
        try
        {
            List<Opportunity> opplist = database.query(query);
            return opplist;          
        }
        catch (QueryException e)
        {
            ApexPages.addMessages(e);
            return Null;
        }      
   }
}

The above code will generate the Excel sheet.

Note: If your excel sheet contains some extra data, such us Months and month picklist, for that if you have used <apex:form> tag, remove that form tag in the visualforce page.