Skip to main content

Customize the columns in the Items to Approve section on home page

We can customize the items to approve section with the help of custom visualforce page.
All you need to do is create the below page with your object and respected fields to be displayed and then add the page to a new home page component.

Page:

<apex:page controller="itemstoApprovecontroller" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Incidents/Service Request To Approve">
            <apex:pageBlockTable value="{!items_to_approve}" var="item_to_approve">
                <apex:column headerValue="Action" width="160 px" >
                                    <apex:commandLink target="_top" value="Reassign |" action="{!REASSIGNnavigation}" style="text-decoration:none;color: #015ba7;" styleClass="cactionLink">
                                                       <apex:param name="myParam" value="{!item_to_approve.approvalid }" />
                                                                                           
                                                                    </apex:commandLink>

                    <apex:commandLink target="_top" value=" Approve / Reject" action="{!ApproveRejectnavigation}" style="text-decoration:none;color: #015ba7;"  >

                   <apex:param name="myParam" value="{!item_to_approve.approvalid }" />
                </apex:commandLink>

       
                </apex:column>
             
           
                <apex:column headerValue="Column 1" width="200 px">
                    <apex:outputtext >{!item_to_approve.Field1}
                      </apex:outputtext>
                </apex:column>
                <apex:column headerValue="Column 2" width="200 px">
                    <apex:outputtext >{!item_to_approve.Field2}
                      </apex:outputtext>
                </apex:column>
                <apex:column headerValue="Column 3" width="150 px">
                    <apex:outputtext >{!item_to_approve.Field3}
                      </apex:outputtext>
                </apex:column>
                <apex:column headerValue="Column 4" width="50 px">
                    <apex:outputtext >{!item_to_approve.Field4}
                      </apex:outputtext>
                </apex:column>
                <apex:column headerValue="Column 5" width="200 px">
                    <apex:outputtext >{!item_to_approve.Field5 }
                      </apex:outputtext>
                </apex:column>
                <apex:column headerValue="Column 6" width="100 px">
                    <apex:outputtext >{!item_to_approve.Field6 }
                      </apex:outputtext>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

------------------------------------------------------------------------

Controller:

public class itemstoApprovecontroller {

    ApexPages.standardController stdController= null;
    public itemstoApprovecontroller(ApexPages.StandardController controller) {
        stdController=controller;
    }
    public Object__c ObjectIncident {get; set;}
    public List<Object__c> incToApprove {get; set;}
    ID Oppyid;
    Set<ID> incIds=new Set<ID>();

    public class item_wrapper {
        public item_wrapper(id id,string name,string objtype,String DateSubmited,string tcmeetingcomments, id approvalid, string Field1, string Field2,
                            string Field3, string Field4, Decimal Field5, string Field6) {
            this.id = id;
            this.name = name;
            this.objtype = objtype;
            this.DateSubmited = DateSubmited;
            this.tcmeetingcomments=tcmeetingcomments;
            this.approvalid =approvalid ;
            this.Field1 = Field1;
            this.Field2 = Field2;
            this.Field3 = Field3;
            this.Field4 = Field4;
            this.Field5 = Field5;
this.Field6 = Field6;
        }
        public id id { get; set; }
        public string name { get; set; }
        public string objtype { get; set; }
        public String DateSubmited { get; set; }
        public string tcmeetingcomments{ get; set; }
        public id approvalid { get; set; }
        public string Field1{get;set;}
        public string Field2 {get; set;}
        public string Field3 {get; set;}
        public string Field4 {get; set;}
        public Decimal Field5 {get; set;}
public string Field6 {get; set;}
    }

    public list<item_wrapper> items_to_approve { get; set; }

    public itemstoApprovecontroller() {
        items_to_approve = new list<item_wrapper>();
   
        map<id,ProcessInstanceWorkItem> mpaPIWIdToPIW = new map<id,ProcessInstanceWorkItem>();
        list<ProcessInstanceWorkItem> lstPIWI = [select processinstance.targetobjectid,CreatedDate ,processinstance.targetobject.name,ProcessInstance.TargetObject.type
        from processinstanceworkitem where actorid in  :actorIds() Order by CreatedDate Desc];
        system.debug('@@@@@@lstPIWI '+lstPIWI);
        if(!lstPIWI.isEmpty()){
            for(ProcessInstanceWorkItem item: lstPIWI) {
                incIds.add(item.processinstance.targetobjectid);
                if(!mpaPIWIdToPIW.containsKey(item.processinstance.targetobjectid)){
                    mpaPIWIdToPIW.put(item.processinstance.targetobjectid,item);
                }
            }
        }
   
        map<id,Object__c> mapoptyIdtoMeetingnotes = new map<id,Object__c>();
   
        if(incIds.size()>0){
            incToApprove=[select id,name, Field1, Field2, Field3, Field4, Field5
                          from Object__c where id in : incIds];
            if(!incToApprove.isEmpty()){
                for(Object__c objInc:incToApprove){
                    mapoptyIdtoMeetingnotes.put(objInc.id,objInc);
                }
            }
        }
        if(!lstPIWI.isEmpty()){
       
            for(ProcessInstanceWorkItem item: mpaPIWIdToPIW.values()) {
                String dateTimeValue = item.CreatedDate.format('MM/dd/yyyy hh:mm a');
                system.debug(dateTimeValue +'Debug2 dateTimeValue ');
                if(item.processinstance.TargetObject.type == 'Objetc1'){
                                    system.debug(item.processinstance.targetobjectid +'Debug2 dateTimeValue ');

                    items_to_approve.add(new item_wrapper(item.processinstance.targetobjectid,item.processinstance.targetobject.name,
                                        item.processinstance.TargetObject.type,dateTimeValue ,
                                        mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).name,
                                        mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field1,
                                        mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field2,
                                        mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field3,
                                        mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field4,
                                        mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field5));
                }else{
                   system.debug(item.processinstance.targetobjectid +'Debug2 dateTimeValue ');


                    String sObjName = item.processinstance.targetobjectid.getSObjectType().getDescribe().getLabel();
                                                           system.debug(sObjName +'sObjNameValue ');

                    items_to_approve.add(new item_wrapper(item.processinstance.targetobjectid,item.processinstance.targetobject.name,sObjName ,dateTimeValue ,'',item.id ,
                    mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field1,
                    mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field2,
                    mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field3,
                    mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field4,
                    mapoptyIdtoMeetingnotes.get(item.processinstance.targetobjectid).Field5));
                }
            }
        }
    } 
    public  static String ApproveRejectnavigation() {
        String url='';
        string myParam = apexpages.currentpage().getparameters().get('myParam');
        url='https://'+ System.URL.getSalesforceBaseUrl().getHost() +
            '/p/process/ProcessInstanceWorkitemWizardStageManager?id=' + myParam ;   
   
        return url;
   
    }
    public  static String REASSIGNnavigation() {
        String url='';
        string myParam = apexpages.currentpage().getparameters().get('myParam');
        url='https://'+ System.URL.getSalesforceBaseUrl().getHost()+'/'+ myParam +'/e?et=REASSIGN';   
        return url;
   
    }
 
    public set<id> actorIds()
    {
        set<id> actorIds=new set<id>{UserInfo.getUserId()};
        for(Group grouprec:[SELECT Id , (select UserOrGroupId from GroupMembers where UserOrGroupId=:UserInfo.getUserId() ) FROM Group where type='Queue'])
        {
          system.debug('@@@@@grouprec'+grouprec.Id +'groupmembers '+grouprec.groupmembers);
            if(grouprec.groupmembers!=NULL &&  grouprec.groupmembers.size()>0 ){
       
              actorIds.add(grouprec.Id);
          }
        }
     
   
        return actorIds;
 
    }

}

Comments

Popular posts from this blog

Track Field History for more than 20 fields - Salesforce

All of us would have come across a situation when we need to track more than 20 fields for an object in salesforce. We have raised this Idea around 8 years ago in the success community. But sill it has't implemented by salesforce. But for now, we can achieve it partially with the following workaround. Approach: This approach uses a custom Text field which stores values of multiple other individual fields. Then enabling field history tracking of this field would allow you to track changes for multiple sets of other individual fields. Thus even though remaining within the count limit 20, yet track changes of more than 20 fields. Let us in this example take “Account ”  object and apply the steps to track change in Account Name, Phone, Parent Account and Billing Address all together. Steps: Step 1:  Add a new custom field. Setup -> Customize -> Accounts -> Fields Create a new Text (255) field “ Track FieldHistory ” (Or give any other n...

Kanban view for Lightning

Tired of list views? Looking for a dynamic views to show your cases or opportunities in all new way? Here we go,  Salesforce introduced Kanban views for us to have better visibility  of our cases/opportunities and their journey from opening to closure. A case kanban allows you to visually summarize all of the cases for your agents,  by status or priority. It's not only a board, but also a  drag and drop  tool that will help agents keep their cases moving towards resolution. Similarly an opportunity Kanban display opportunities from a particular sales path Let's take a closer look at what all we can do with Kanban Track a Deal with Path Display opportunities by Sales path Move an Opportunity to the Next Stage Take Action on Your Records