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;
}
}
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
Post a Comment