Friday 19 September 2014

Data Access On VF Page From Custom Component

                              

In a scenario I was using a custom component on a custom visualforce page. That custom component was containing pick list and populating data from component controller using dynamic soql query.

But the case was that I need to access pick list selected value on page side. I did little bit struggle with it but final get way that is following :-

<apex:component controller="LookUpListUtil">

<apex:attribute type="string" assignTo="{!QueryObject}" name="LookUpObject" description="Pick list data query on which object." required="true"/>

<apex:attribute type="string" assignTo="{!labelField}" default="name" name="label" description="which field of LookUpObject you want to populate in pick list " required="true"/>

<apex:attribute type="sobject" assignTo="{!objAssignTo}" name="AssignToObject" description="Object name on which you want to set selected value of pick list " required="true" />

<apex:attribute type="string" assignTo="{!AssignToField}" name="AssignToFieldname" description="field name of objAssignTo Object on which you want to set selected value of pick list " required="true" />
  
    <apex:selectList id="LookUpControl" value="{!PicklistData()}"    size="1" multiselect="false" >
        <apex:selectOption itemValue="" itemLabel="--Please Select--"/>
        <apex:selectoptions value="{!LookUpDataList}" >
    
    </apex:selectoptions>
 <apex:actionSupport event="onchange"  action="{!onValuechange}" rerender="sdf" />
</apex:selectList>



// Custom controller for lookup control. 

public with sharing class LookUpListUtil 
{
   
    
  
    public string QueryObject{get;set;}
    public string labelField{get;set;}

    public string groupBy{get;set;}
    
    public List<selectOption> LookUpDataList{get; private set;}
    
    public string lookUpSelectedValue{get;set;}
    public sobject objAssignTo{get;set ;}
    public string AssignToField{get;set;}
    
    public new  List<selectOption> GetPicklistData()
    {
        LookUpDataList=new  List<selectOption>();

        try
        {
// fetching to populate in pick list
            string soqlQuery;
            if(groupBy=='')
                soqlQuery='SELECT ID,'+labelField+' FROM '+ type.forname(QueryObject).getName();
            else 
                soqlQuery='SELECT ID,'+labelField+','+ groupBy+' FROM '+ type.forname(QueryObject).getName()+' ORDER BY '+groupBy;
             string itemVal;
                for(sobject obj:DataBase.query(soqlQuery))
                {
                    if(groupBy=='')
                        LookUpDataList.Add(new selectOption(string.ValueOf(obj.get('id')),string.Valueof(obj.get(labelField))));
                    else
                    {
                       itemVal=string.Valueof(obj.get(groupBy))+'_'+string.Valueof(obj.get(labelField));
                       LookUpDataList.Add(new selectOption(string.ValueOf(obj.get('id')),itemVal));
                    }
                }
             
         }
         catch(exception ex)
         {
              apexPages.AddMessage(new apexPages.Message(ApexPages.severity.Error,'Can\'t able to fetch data in PickList. There is an issue. '+ex.getmessage()));
         }

    }
    
    public void onValuechange()
    {
try
{
        objAssignTo.put(AssignToField,lookUpSelectedValue);
}
catch(exception ex)
         {
              apexPages.AddMessage(new apexPages.Message(ApexPages.severity.Error, ex.getmessage()));
         }
        
    }

  
   
}


Here I am using parameters in custom component which is objAssignTo  and AssignToField 
objAssignTo  is sobject data type parameters. And updating value in sobject's field. which is passing from vf page. So I am able to access values on vf page from custom component. 


<apex:page controller="LookUpListUtilTestPagecontroller" >


  <br/> <br/>
  <apex:form >
  <c:LookUp LookUpObject="Account" AssignToObject="{!acc}" AssignToFieldname="name" label ="name"/>
  
  <br/>
   
  <apex:commandButton action="{!Button_click}" title="Button" style="width:50px;"  value="Page Btn"> </apex:commandButton>
</apex:form>

</apex:page>




public with sharing class LookUpListUtilTestPagecontroller 
{
    public LookUpListUtilTestPagecontroller ()
    {
        acc=new account();
    }

    public account acc{get;set;}

    public pagereference Button_click()
    {
        
   
       system.assert(false,' Selected value is ='+acc.name);
        return null;
    }
    
  
    public LookUpListUtilTestPagecontroller GetThis(){ return this;}
}




Wednesday 10 September 2014

ForURL() Method On VisaulForce page

                                      URLFOR()  Method

URLFOR() method is use to access the url in visualforce page with respect to passed method parameter's.

Here I am going to demonstrate for URLFOR method with some scenario . Some time we have requirement to redirect on page,redirect on action of particular object, perform a action with return url and access a resources.

1. Access css from zipfile resource.

                   <apex:stylesheet value="{!URLFOR($Resource.Bootstrap,'bootstrap-3.2.0-dist/css/bootstrap.min.css')}"/>

2. Access css file resource.
                   <apex:stylesheet value="{!URLFOR($Resource.Bootstrap)}"/>     

3. Redirect on customPage.

                 <a href="{!URLFOR($Page.SetUp)}">Accounting Hub</a>

4.  Redirect on Action.
               <a tabindex="-1" href="{!URLFOR($action.BankAccount__c.New,$ObjectType.BankAccount__c)}">Bank Account</a>.

5.  Redirect on page with return url.

                <apex:commandButton action="{!URLFOR($Action.Account.view, ID, [retURL=myRet])}" value="New Opportunity" id="theButton"/>
           



Tuesday 9 September 2014

Mini Page Layout Using Apex Code


Suppose to we need to show a salesforce mini page layout on link tag in VF page. Here I showing some line of code which will be responsible to show a mini page layout.

e.g.

    <a href=”/{!acc.Id}” id=”{!acc.Id}” onblur=”LookupHoverDetail.getHover(‘{!acc.Id}’).hide();” onfocus=”LookupHoverDetail.getHover(‘{!acc.Id}’, ‘/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1′).show();” onmouseout=”LookupHoverDetail.getHover(‘{!acc.Id}’).hide();” onmouseover=”LookupHoverDetail.getHover(‘{!acc.Id}’, ‘/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1′).show();”>{!acc.Name}</a>


In above the code LookupHoverDetail.getHover().hide() and LookupHoverDetail.getHover().show() these method will show and hide mini page layout.

Here I am showing pagelayout onfocus and onMousOver on link. and hiding on onblur and onmouseout();



Salesforce Basic Knowledge

  Life Cycle of Salesforce Rules Execution



Salesforce reules execution order is following

  1. Validation rules
  2. Assignment rules
  3. Auto-response rules
  4. Workflow rules(with immediate actions)
  5. Escalation rules
Tip:- (Logic VAAWE)

Monday 8 September 2014

Salesforce LIMITS

Salesforce LIMITS

  • VF page size is 15 mb. 
  • page view state size is 135kb.
Summer 14 updates

  • The maximum number of relationship fields per object has been increased from 25 to 40 fileds. and external id Fields from 3 fields per object to 7 fields per object.
  • Rules limit were raised from 300 to 500 per object. And from 1000 to 2000 per orgianization. but these limit are combination of active and inactive workfolw ,assignment,auto-response,escalation rules. But number of active rules hasn't changed it remains at 50 rules per object.
  • No more limits on GetDescribe().

Dynamic Component

<apex:dynamicComponent ComponentValue="{!ComponentData}"/>             



public class MyController 
{
public transient ApexPages.Component ComponentData { get; private set; }
public MyController() 
Type t = Type.forName('Component.c.MyCustomComponent');
if(t != null) 
this.ComponentData = (ApexPages.Component)t.newInstance(); 
}
}