Posts

Showing posts from January, 2017

Standard Pagination Using Standard Controller based on RecordSetVar

Image
<apex:page standardController="Opportunity" recordSetVar="opportunities" tabStyle="Opportunity" sidebar="false">     <apex:form >             <apex:pageBlock title="Edit Opportunities" >             <apex:pageMessages ></apex:pageMessages>             <apex:pageBlockButtons >               <apex:commandButton value="Save" action="{!save}"/>               <apex:commandButton value="Cancel" action="{!cancel}"/>             </apex:pageBlockButtons>             <apex:pageBlockTable value="{!opportunities}" var="opp">                 <apex:column value="{!opp.name}"/>                   <apex:column headerValue="Stage">                     <apex:inputField value="{!opp.stageName}"/>                   </apex:column>                   <apex:column headerV

Get list of Key Prefix of Sobject in Salesforce

Image
Requirement:  Show the list of Key Prefix of Sobject in salesforce Solution: Class Code: public class populateObjectsAndKeyPrefixController {      public List<Schema.SObjectType> lstofSType {get;set;}       public List<SObjectInfo> lstofSobject {get;set;}           public class SObjectInfo {         public String prefix {get;set;}         public String name {get;set;}     }        public gettingObjectsAndKeyPrefix(){                        lstofSType  = Schema.getGlobalDescribe().Values();         lstofSobject = new List<SObjectInfo>();         for(Schema.SObjectType f : lstofSType )         {             SObjectInfo sobjectinfo = new SObjectInfo();            sobjectinfo.prefix = f.getDescribe().getKeyPrefix();             sobjectinfo.name = f.getDescribe().getLabel();             lstofSobject.add(SObjectInfo);         }             } } VF Page Code <apex:page controller="populateObjectsAndKeyPrefixController "

Find Day of selected Date on VF Page

Image
Requirement: Find the day of selected date in date field Solution: public class DayOfDate {     Private Date startDate = date.newInstance(0001, 1, 1);        Public Date selectedDate{get;set;}     public String dayValue{get;set;}     public Account acc {get;set;}     public DayOfDate()     {           system.debug('startDate***'+startDate);         selectedDate = date.today();         system.debug('selectedDate*****'+selectedDate);         acc = new Account();     }     public void calculateDayOfDate()     {         List<String> listDay = new List<String>{'Saturday' , 'Sunday' , 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday'};         selectedDate = acc.SLAExpirationDate__c;         Integer remainder = Math.mod(startDate.daysBetween(selectedDate) , 7);         system.debug('remainder____'+remainder);         dayValue = listDay.get(r

Show All custom and standard Object and respective field on VF Page

Image
Requirement: Provide a option on vf page that user can select any custom or standard object and create slelected SOQL query and get records according to selected fields  Solution:  Controller Class : public class clsCustStandObj  {     public PageReference checkAll1() {         return null;     }     public PageReference checkAll2() {         return null;     }     public string SelectedValue{get;set;}     public string SelectedObject{get;set;}     public List<SelectOption> lstofObj{get;set;}     public List<SelectOption> lstofAllselectedObj{get;set;}     public List<string> lstofAllfieldAndName{get;set;}     public List<WrapperClass> lstofStandardField{get;set;}     public List<WrapperClass> lstofCustomField{get;set;}     public List<string> lstofselectedfield{get;set;}     public string allselfield{get;set;}     public List<SObject> lstgetresult{get;set;}     public List<String> lstgetresult1{get;set;}    

Populate Objects in Drop down and on Selection redirect on standard creation page

Image
Requirement : Show a drop down on which there are standard and custom object will be appear when select any object it should redirect to standard new creation page Class Code: public class SobjectListcls  {      set<string> salesforceObjectSet = new set<string>();     Map<Id,List<ObjectPermissions>> permissionsetIdAndlstObjectPermissions = new Map<Id,List<ObjectPermissions>>();         public string strSobjectName{get;set;}     public SobjectListcls()     {       onlyReadPerrmission();     }     public void onlyReadPerrmission()     {         String userid = UserInfo.getUserId();         User thisUser = [select id, profile.Name from User where id=:userid];              permissionset perset = [select id from permissionset where PermissionSet.Profile.id =:thisUser.profileId];         PermissionSetAssignment[] lstPermissionSetAssignment =[SELECT AssigneeId,PermissionSetId FROM PermissionSetAssignment where AssigneeId =:UserInfo.getU

Added Multiple Row Dynamically on VF Page

Image
Requirement : Added Multiple row based on provided a numeric value in text box  Solution: Controller Class: public class multiRowAddedDynamicallyController {    public integer rowsnum { get; set; }   public List<Account> lstofaccount {get; set;}    public multiRowAddedDynamicallyController()   {      lstofaccount = new List<Account>();       lstofaccount.add(new Account());       }    public void addRows() {     for(integer i=0;i<rowsnum  ;i++)         {           lstofaccount.add(new Account());             }               }   public PageReference saveClose()   {   insert lstofaccount;      PageReference pgrefernce = new PageReference('https://ap1.salesforce.com/001/o');      pgrefernce .setRedirect(true);      return pgrefernce ;   } } VF Page: <apex:page controller="multiRowAddedDynamicallyController" sidebar="false">  <apex:form > <apex:sectionHeader title="" subtitle="Acc

Pagination On Visual force Page Using StandardSetController

Image
Requirement:  Need to create a visual force page and add processed the records on selection of check boxes Solution: Class Name: public class ContactController {     Public class WrapperContactCls     {         public Contact con{get;set;}         public boolean isSelected{get;set;}         public WrapperContactCls(Contact c,boolean isSelected)         {             this.con = c;             this.isSelected = isSelected;         }     }       public String size { get; set; }     //This is Our collection of the class/wrapper objects WrapperContactCls     Public List<WrapperContactCls> wrapperlist;     Public Integer noOfRecords{get; set;}     // Create a new Map to verify whether the contact is already added in the Map     Map <id,Contact> MapOfSelectedcontactIDToContactObj = new Map <id,Contact>();     public boolean display{get;set;}     public list<Contact> selectedList {get;set;}     // instantiate the StandardS

Send Quote Pdf to Contact Person and Save the Quote PDF in attachement

Requirement: Need to create the save and send Quote Pdf custom button on Quote detail page and when user click on this button quote pdf as attachment send to quote contact person and pdf attached in attachment under quote Solution: 1) Need to create web service class  2 ) Create a custom button as a Detail page button and  Behavior as Execute Java Script and content source is as onClick Java Script and call the web service class. WebServiceClass Name: global class clsSaveQuotePDFInAttachmentUnderQuote {      webservice static String AttachPDFToQuote(string Id){                string strResponse = '';         try         {             PageReference pageRef = new PageReference('/apex/VFPageName?Id='+Id);                          Blob content;             if(!Test.isRunningTest())                 content = pageRef.getContent();             else                 content = Blob.valueOf( EncodingUtil.urlEncode('abc', 'UTF-8'));