You need to sign in to do that
Don't have an account?

i am getting view state error when i choose no.of records to 50 in my vf page.showing size is more than 135 kb.i have used Transient keyword and checked. still i m getting the error
<apex:page controller="RTV_ApprovalController" id="pageid" tabstyle="RTV_Approvals__tab">
<script>
function cvCheckAllOrNone(allOrNoneCheckbox) {
// Find parent table
var container = allOrNoneCheckbox;
while (container.tagName != "TABLE") {
container = container.parentNode;
}
// Switch all checkboxes
var inputs = container.getElementsByTagName("input");
var checked = allOrNoneCheckbox.checked;
for (var i = 0; i < inputs.length; i++) {
var input = inputs.item(i);
if (input.type == "checkbox") {
if (input != allOrNoneCheckbox) {
input.checked = checked;
}
}
}
}
</script>
<!-- Define Tab panel .css styles -->
<apex:stylesheet value="/sCSS/21.0/sprites/1297816277000/Theme3/default/gc/versioning.css" />
<apex:stylesheet value="/sCSS/21.0/sprites/1297816277000/Theme3/default/gc/extended.css" />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"/>
<script type="text/javascript">
j$ = jQuery.noConflict();
function showLoadingDiv() {
var newHeight = j$("[id$=pblkIds]").css("height");//Just shade the body, not the header
j$("[id$=loading-curtain-div]").css("background-color", "black").css("opacity", 0.35).css("height", newHeight).css("width", "80%");
}
function hideLoadingDiv() {
j$("[id$=loading-curtain-div]").css("background-color", "black").css("opacity", "1").css("height", "0px").css("width", "80%");
}
function getSelectedTabName() {
if (RichFaces) {
var tabs = RichFaces.panelTabs['pageid:form:tabpanel'];
for (var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
if (RichFaces.isTabActive(tab.id + '_lbl')) {
return tab.name;
}
}
}
return null;
}
function setSelectedTabOnController() {
selectTabActionFunction(getSelectedTabName());
}
function select1(){
sel2();
}
function select2(){
sel2();
}
</script>
<style>
.activeTab {background-color: #236FBD; color:white; background-image:none}
.inactiveTab { background-color: black; color:black; background-image:none}
#loading-curtain-div {
height:0px;
width:100%;
position:absolute;
z-index:5;
-webkit-transition: all 0.30s ease-out;
-moz-transition: all 0.30s ease-out;
}
.no-js #loader { display: none; }
.js #loader { display: block; position: absolute; left: 100px; top: 0; }
.se-pre-con {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: URLFOR($Resource.preloader,'simple-pre-loader\images\loader-32x\loader1.gif') center no-repeat #fff;
}
</style>
<apex:tabPanel switchType="client" styleClass="theTabPanel" tabClass="theTabPanel" contentClass="tabContent" activeTabClass="activeTab" inactiveTabClass="inactiveTab" selectedTab="name1" id="tabpanel" >
<apex:tab label="RTV - To Submit for Approval" name="name1" reRender="pbIds" id="tabOne" style="bachground-blend-mode:color-burn; background-color:white">
<div id="loading-curtain-div"/>
<apex:form id="form" >
<apex:outputPanel id="pnlId" layout="none" >
<apex:pageBlock title="RTV - To Submit for Approval" id="pblkIds" >
<b>Select Region</b>
<apex:selectList value="{!selectedRegion}" size="1" title="Select Region" label="Select Region">
<apex:actionSupport event="onchange" action="{!getrefreshGrid}" status="statusMsg" reRender="pblkIds,pbIds"/>
<apex:selectOptions value="{!lstSelectOptions}"/>
</apex:selectList>
<b>No. of records per page:</b>
<apex:selectList value="{!pageSize}" size="1" title=" No. of records per page" label="No. of records per page">
<apex:actionSupport event="onchange" action="{!getrefreshGrid}" status="statusMsg" reRender="pblkIds,pbIds"/>
<apex:selectOption itemLabel="10" itemValue="10" />
<apex:selectOption itemLabel="20" itemValue="20" />
<apex:selectOption itemLabel="50" itemValue="50" />
<apex:selectOption itemLabel="100" itemValue="100" />
</apex:selectList><br/><br/>
<b> Filter Text</b>
<apex:inputText value="{!searchText}" />
<apex:commandButton value="Filter" action="{!search}" reRender="pnlId" >
</apex:commandButton>
<I>*Please use Refresh button to reset the filter applied. </I><br/>
<apex:pageBlockSection title="RTV - To be submitted for Approval" collapsible="false" id="sect" columns="1">
<apex:outputPanel layout="none" style="overflow:auto;height:380px" id="iddf" >
<apex:pageMessages id="ff" />
<apex:pageBlockTable value="{!lstSetController}" var="obj" Id="pbtblids">
<apex:column >
<apex:facet name="header">
<apex:outputText > Action</apex:outputText>
<apex:inputCheckbox label="Action" onclick="cvCheckAllOrNone(this)" title="Toggle All Rows"/>
</apex:facet>
<apex:inputCheckbox value="{!obj.isSelected}"/>
</apex:column>
<apex:repeat value="{!$ObjectType.Return_To_Vendor__c.FieldSets.RTVApprovalFieldSet}" var="f">
<apex:column >
<apex:variable value="{!SUBSTITUTE(f.fieldPath,'__c', '__r.Name')}" var="Name" rendered="{!if(f.type=='reference',true,false)}"/>
<apex:outputLink value="/{!obj.rtv[f]}" rendered="{!if(f.type=='reference', true, false)}" > {!obj.rtv[Name]}</apex:outputLink>
<apex:outputLink value="/{!obj.rtv['Id']}" rendered="{!if(f.FieldPath=='Name', true, false)}" > {!obj.rtv[f]}</apex:outputLink>
<!--<apex:outputtext value="{!obj.rtv[f]}" rendered="{!if(f.type=='reference' || f.FieldPath=='Name', false, true)}" />-->
<apex:outputField value="{!obj.rtv[f]}" rendered="{!if(f.type=='reference' || f.FieldPath=='Name', false, true)}" />
<apex:facet name="header">
<apex:commandLink value="{!f.Label}" status="statusMsg" action="{!sort}" reRender="pnlId">
<apex:param name="{!f.fieldPath}" assignTo="{!field}" value="{!f.FieldPath}"/>
<apex:param name="{!f.fieldPath+f.type}" assignTo="{!fieldType}" value="{!f.type}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:outputText value="{!obj.rtv[f]}" /><br/>
</apex:repeat>
</apex:pageBlockTable>
<apex:commandButton value="<<Previous" action="{!previous}" status="statusMsg" rendered="{!hasPrevious}" reRender="pnlId" />
<apex:commandButton value="Next >>" action="{!next}" status="statusMsg" rendered="{!hasNext}" reRender="pnlId" />
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockButtons location="top">
<apex:actionStatus onstart="showLoadingDiv();" onstop="hideLoadingDiv();" id="statusMsg">
<apex:facet name="start" >
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
<apex:commandButton action="{!SubmitForApproval}" value="Submit for Approval" status="statusMsg" reRender="pnlId,statusMsg "/>
<apex:commandButton action="{!refresh}" status="statusMsg" value="Refresh" rerender="pnlId"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:tab>
<apex:tab label="Items to Approve" name="name2" style="bachground-blend-mode:color-burn; background-color:white">
<apex:iframe src="/apex/RTV_My_Pending_Approvals" scrolling="true" id="theIframe" />
</apex:tab>
</apex:tabpanel>
</apex:page>
<script>
function cvCheckAllOrNone(allOrNoneCheckbox) {
// Find parent table
var container = allOrNoneCheckbox;
while (container.tagName != "TABLE") {
container = container.parentNode;
}
// Switch all checkboxes
var inputs = container.getElementsByTagName("input");
var checked = allOrNoneCheckbox.checked;
for (var i = 0; i < inputs.length; i++) {
var input = inputs.item(i);
if (input.type == "checkbox") {
if (input != allOrNoneCheckbox) {
input.checked = checked;
}
}
}
}
</script>
<!-- Define Tab panel .css styles -->
<apex:stylesheet value="/sCSS/21.0/sprites/1297816277000/Theme3/default/gc/versioning.css" />
<apex:stylesheet value="/sCSS/21.0/sprites/1297816277000/Theme3/default/gc/extended.css" />
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"/>
<script type="text/javascript">
j$ = jQuery.noConflict();
function showLoadingDiv() {
var newHeight = j$("[id$=pblkIds]").css("height");//Just shade the body, not the header
j$("[id$=loading-curtain-div]").css("background-color", "black").css("opacity", 0.35).css("height", newHeight).css("width", "80%");
}
function hideLoadingDiv() {
j$("[id$=loading-curtain-div]").css("background-color", "black").css("opacity", "1").css("height", "0px").css("width", "80%");
}
function getSelectedTabName() {
if (RichFaces) {
var tabs = RichFaces.panelTabs['pageid:form:tabpanel'];
for (var i = 0; i < tabs.length; i++) {
var tab = tabs[i];
if (RichFaces.isTabActive(tab.id + '_lbl')) {
return tab.name;
}
}
}
return null;
}
function setSelectedTabOnController() {
selectTabActionFunction(getSelectedTabName());
}
function select1(){
sel2();
}
function select2(){
sel2();
}
</script>
<style>
.activeTab {background-color: #236FBD; color:white; background-image:none}
.inactiveTab { background-color: black; color:black; background-image:none}
#loading-curtain-div {
height:0px;
width:100%;
position:absolute;
z-index:5;
-webkit-transition: all 0.30s ease-out;
-moz-transition: all 0.30s ease-out;
}
.no-js #loader { display: none; }
.js #loader { display: block; position: absolute; left: 100px; top: 0; }
.se-pre-con {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: URLFOR($Resource.preloader,'simple-pre-loader\images\loader-32x\loader1.gif') center no-repeat #fff;
}
</style>
<apex:tabPanel switchType="client" styleClass="theTabPanel" tabClass="theTabPanel" contentClass="tabContent" activeTabClass="activeTab" inactiveTabClass="inactiveTab" selectedTab="name1" id="tabpanel" >
<apex:tab label="RTV - To Submit for Approval" name="name1" reRender="pbIds" id="tabOne" style="bachground-blend-mode:color-burn; background-color:white">
<div id="loading-curtain-div"/>
<apex:form id="form" >
<apex:outputPanel id="pnlId" layout="none" >
<apex:pageBlock title="RTV - To Submit for Approval" id="pblkIds" >
<b>Select Region</b>
<apex:selectList value="{!selectedRegion}" size="1" title="Select Region" label="Select Region">
<apex:actionSupport event="onchange" action="{!getrefreshGrid}" status="statusMsg" reRender="pblkIds,pbIds"/>
<apex:selectOptions value="{!lstSelectOptions}"/>
</apex:selectList>
<b>No. of records per page:</b>
<apex:selectList value="{!pageSize}" size="1" title=" No. of records per page" label="No. of records per page">
<apex:actionSupport event="onchange" action="{!getrefreshGrid}" status="statusMsg" reRender="pblkIds,pbIds"/>
<apex:selectOption itemLabel="10" itemValue="10" />
<apex:selectOption itemLabel="20" itemValue="20" />
<apex:selectOption itemLabel="50" itemValue="50" />
<apex:selectOption itemLabel="100" itemValue="100" />
</apex:selectList><br/><br/>
<b> Filter Text</b>
<apex:inputText value="{!searchText}" />
<apex:commandButton value="Filter" action="{!search}" reRender="pnlId" >
</apex:commandButton>
<I>*Please use Refresh button to reset the filter applied. </I><br/>
<apex:pageBlockSection title="RTV - To be submitted for Approval" collapsible="false" id="sect" columns="1">
<apex:outputPanel layout="none" style="overflow:auto;height:380px" id="iddf" >
<apex:pageMessages id="ff" />
<apex:pageBlockTable value="{!lstSetController}" var="obj" Id="pbtblids">
<apex:column >
<apex:facet name="header">
<apex:outputText > Action</apex:outputText>
<apex:inputCheckbox label="Action" onclick="cvCheckAllOrNone(this)" title="Toggle All Rows"/>
</apex:facet>
<apex:inputCheckbox value="{!obj.isSelected}"/>
</apex:column>
<apex:repeat value="{!$ObjectType.Return_To_Vendor__c.FieldSets.RTVApprovalFieldSet}" var="f">
<apex:column >
<apex:variable value="{!SUBSTITUTE(f.fieldPath,'__c', '__r.Name')}" var="Name" rendered="{!if(f.type=='reference',true,false)}"/>
<apex:outputLink value="/{!obj.rtv[f]}" rendered="{!if(f.type=='reference', true, false)}" > {!obj.rtv[Name]}</apex:outputLink>
<apex:outputLink value="/{!obj.rtv['Id']}" rendered="{!if(f.FieldPath=='Name', true, false)}" > {!obj.rtv[f]}</apex:outputLink>
<!--<apex:outputtext value="{!obj.rtv[f]}" rendered="{!if(f.type=='reference' || f.FieldPath=='Name', false, true)}" />-->
<apex:outputField value="{!obj.rtv[f]}" rendered="{!if(f.type=='reference' || f.FieldPath=='Name', false, true)}" />
<apex:facet name="header">
<apex:commandLink value="{!f.Label}" status="statusMsg" action="{!sort}" reRender="pnlId">
<apex:param name="{!f.fieldPath}" assignTo="{!field}" value="{!f.FieldPath}"/>
<apex:param name="{!f.fieldPath+f.type}" assignTo="{!fieldType}" value="{!f.type}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:outputText value="{!obj.rtv[f]}" /><br/>
</apex:repeat>
</apex:pageBlockTable>
<apex:commandButton value="<<Previous" action="{!previous}" status="statusMsg" rendered="{!hasPrevious}" reRender="pnlId" />
<apex:commandButton value="Next >>" action="{!next}" status="statusMsg" rendered="{!hasNext}" reRender="pnlId" />
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockButtons location="top">
<apex:actionStatus onstart="showLoadingDiv();" onstop="hideLoadingDiv();" id="statusMsg">
<apex:facet name="start" >
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
<apex:commandButton action="{!SubmitForApproval}" value="Submit for Approval" status="statusMsg" reRender="pnlId,statusMsg "/>
<apex:commandButton action="{!refresh}" status="statusMsg" value="Refresh" rerender="pnlId"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:tab>
<apex:tab label="Items to Approve" name="name2" style="bachground-blend-mode:color-burn; background-color:white">
<apex:iframe src="/apex/RTV_My_Pending_Approvals" scrolling="true" id="theIframe" />
</apex:tab>
</apex:tabpanel>
</apex:page>
yes the problem is with RTVWrapper class. It is giving 3000+recotds in a list. PF beloe class. Here i have used Public Transisent Return_to_vendor__C .but when click on next page by selecting record per page 10 , nin next page the records are not coming
public class RTVWrapper implements comparable{
public static string order{get;set;}
public Boolean isSelected {get;set;}
public Return_to_vendor__c rtv{get;set;}
Public static integer inte =0;
public Id rtvId {get; set;}
// For Pending approvals
public Id processInstWItmId {get;set;}
public Id recordId {get;set;}
public String recordName {get;set;}
public String approvalInstanceId {get;set;}
public String approvalStepId {get;set;}
public String sObjectLabel {get;set;}
public String sObjectName {get;set;}
public String submiterName {get;set;}
public String submitDate {get;set;}
public boolean firstOfSObjectType {get;set;}
public RTVWrapper(Return_to_vendor__c tempRTV,ProcessInstanceWorkitem p,Boolean isSelected)
{
this.isSelected= isSelected;
if(tempRTV!=null){
this.rtv= tempRTV;
this.rtvId=tempRTV.Id;
}
if(p!=null){
this.processInstWItmId=p.Id;
this.recordId = p.ProcessInstance.TargetObjectId;
this.recordName = p.ProcessInstance.TargetObject.Name;
this.approvalInstanceId = p.ProcessInstanceId;
this.sObjectName = p.ProcessInstance.TargetObject.Type;
this.submiterName = p.ProcessInstance.CreatedBy.Name;
}
}
public Integer CompareTo(object comparedTo){
RTVWrapper compareWrap= (RTVWrapper)comparedTo;
Integer returnValue = 0;
Integer OrderNumGrt;
Integer OrderNumLes;
String field;
String fieldType;
if(processInstWItmId!=null){
field=RTV_PendingApprovalsController.field;
fieldType=RTV_PendingApprovalsController.fieldType;
}
else{
field=RTV_ApprovalController.field;
fieldType=RTV_ApprovalController.fieldType;
}
if(order=='asc' ){
OrderNumGrt=1;
OrderNumLes=-1;
}
else if(order=='desc' ){
OrderNumGrt=-1;
OrderNumLes=1;
}
else{
OrderNumGrt=1;
OrderNumLes=-1;
}
// The return value of 0 indicates that both elements are equal.
if(fieldType!=null){
if( fieldType=='datetime' ){
DateTime basedt;
DateTime comparedt;
basedt=(DateTime)rtv.get(field);
comparedt=(DateTime)compareWrap.rtv.get(field);
if (basedt > comparedt ) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if (basedt < comparedt) {
// Set return value to a negative value.
returnValue = OrderNumLes;
}
}
else if( fieldType=='date'){
/* Date baseDate=(Date)rtv.get(field);
Date compareDate=(Date)compareWrap.rtv.get(field);
if (baseDate> compareDate) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if (baseDate< compareDate) {
// Set return value to a negative value.
returnValue = OrderNumLes;
} */
}
else if( fieldType=='boolean'){
Boolean basebool;
Boolean compareBool;
basebool=(Boolean)rtv.get(field);
compareBool=(Boolean)compareWrap.rtv.get(field);
if (basebool ==true && compareBool==false) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if (basebool ==false && compareBool==true) {
// Set return value to a negative value.
returnValue = OrderNumLes;
}
}
else if( fieldType=='long' ){
/* Long baseLong=(Long)rtv.get(field);
Long compareLong=(Long)compareWrap.rtv.get(field);
if (baseLong > compareLong) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if (baseLong < compareLong) {
// Set return value to a negative value.
returnValue = OrderNumLes;
}*/
}
else if( fieldType=='double'){
Double baseDouble;
Double compareDouble;
baseDouble=(Double)rtv.get(field);
compareDouble=(Double)compareWrap.rtv.get(field);
if (baseDouble > compareDouble) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if (baseDouble < compareDouble) {
// Set return value to a negative value.
returnValue = OrderNumLes;
}
}
else if( fieldType=='integer' ){
Integer baseInteger;
Integer compareInteger;
baseInteger=(Integer)rtv.get(field);
compareInteger=(Integer)compareWrap.rtv.get(field);
if (baseInteger > compareInteger) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if (baseInteger < compareInteger) {
// Set return value to a negative value.
returnValue = OrderNumLes;
}
}
else if( fieldType=='reference' ){
Id baseId=(Id)rtv.get(field);
Id compareId=(Id)compareWrap.rtv.get(field);
if (baseId > compareId) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if (baseId < compareId) {
// Set return value to a negative value.
returnValue = OrderNumLes;
}
}
else if( fieldType=='string' ){
String baseString;
String compareString;
baseString=(String)rtv.get(field);
compareString=(String)compareWrap.rtv.get(field);
if ((String)rtv.get(field) > (String)compareWrap.rtv.get(field)) {
// Set return value to a positive value.
returnValue = OrderNumGrt;
} else if ((String)rtv.get(field) < (String)compareWrap.rtv.get(field)) {
// Set return value to a negative value.
returnValue = OrderNumLes;
}
}
}
return returnValue;
}
}
private static Integer pageSizeOPLI = 5;
public Static Map<Id, Return_To_Vendor__c> getRTVMap(Set<Id> rtvIds){
String query=CommonsObjUtils.getSelectFromFSAndObj('RTVApprovalFieldSet','Return_To_Vendor__c');
query=query +' where Id IN :rtvIds';
Map<Id,Return_to_Vendor__c> RTVmap=new Map<Id,Return_to_Vendor__c>((List<Return_To_Vendor__c>)Database.query(query));
return RTVMap;
}
public static List<ProcessInstanceWorkitem> getApprovalRecords(String[] sObjectTypeList,
String status, String sortOrder, String actionType){
List<ProcessInstanceWorkitem> approvals = new List<ProcessInstanceWorkitem>();
Set<Id> memberofQueueIds=RTVService.getmemberofQueueIds(new String[] {UserInfo.getUserId()} );
Set<Id> submittedRTVs=new Set<Id>();
String query = 'select ProcessInstanceId, ProcessInstance.TargetObjectId, '
+ ' ProcessInstance.TargetObject.Name, ProcessInstance.TargetObject.Type, ProcessInstance.CreatedBy.Name, '
+ ' ProcessInstance.CreatedDate, ProcessInstance.CreatedBy.SmallPhotoUrl from ProcessInstanceWorkitem '
+ ' where isDeleted=false '
+ ' and ProcessInstance.status= :status '
+ ' and ProcessInstance.TargetObject.Type IN : sObjectTypeList ';
if(actionType=='Approve' || actionType==null){
if( RTVSelector.getProfileNamefromId(UserInfo.getProfileId())!='StoreBoard - System Administrator'){
Set<Id> psIds=new Set<Id>();
for(PermissionSetAssignment psa: [Select AssigneeId, PermissionSetId from PermissionSetAssignment where assigneeId=:UserInfo.getUserId()]){
psIds.add(psa.PermissionSetId);
}
ObjectPermissions[] ps = [Select id, parentId from ObjectPermissions where parentid in: psIds and sObjectType='Return_to_Vendor__c'
and PermissionsModifyAllRecords=true ];
if(ps.size()>0){
/*if(getRoleNamefromId(UserInfo.getUserRoleId())=='EM: Brazil'){
// query=query+ ' and ProcessInstance.TargetObject.RecordTypeId = \'012U0000000E7L6IAK\' ';
}
else if(getRoleNamefromId(UserInfo.getUserRoleId())=='EM: SOCO'){
query=query+ ' and ProcessInstance.TargetObject.Sales_Org__c in ( \'9000\' , \'9200\' ) ';
}*/
}
else{
query=query+ ' and ActorId in :memberofQueueIds ';
}
}
}
else if(RTVService.checkUserIsInGroup(UserInfo.GetUserId(),'RTV Submitters') ||
RTVSelector.getProfileNamefromId(UserInfo.getProfileId())=='StoreBoard - System Administrator' ){
for(Return_to_Vendor__c rtv: [Select Id, Name from Return_to_vendor__c where status__c ='Submitted for Approval'
or status__c ='Submitted for Initial Approval' or status__c ='Submitted for Final Approval']){
submittedRTVs.add(rtv.Id);
}
query=query+ ' and ProcessInstance.TargetObjectId in :submittedRTVs ';
}
else{
Id currentUserId=UserInfo.getUserId();
for(Return_to_Vendor__c rtv:[Select Id, Name from Return_to_vendor__c
where (status__c ='Submitted for Approval' or status__c ='Submitted for Initial Approval'
or status__c ='Submitted for Final Approval' ) and
(CreatedById=:currentUserId or ownerId=:currentUserId) ]){
submittedRTVs.add(rtv.Id);
}
query=query+ ' and ProcessInstance.TargetObjectId in :submittedRTVs ';
}
if(Sortorder!=null)
query=query+ ' order by ' + sortOrder;
approvals=(List<ProcessInstanceWorkitem>) Database.query(query);
return approvals;
}
public static List<Return_to_Vendor__c> getRecordsthroughFieldSet(String fieldSetName, String orderBy, String selectedRegion,Integer pageSize){
Integer OffsetSize = pageSizeOPLI *PageSize;
system.debug('OffsetSize'+OffsetSize);
// Form the query based on the where condition and sortorder
String selectQuery=CommonSobjUtils.getSelectFromFSAndObj(fieldSetName, 'Return_To_Vendor__c');
// Get the where condition based on the region
String wherecond=getWhereClause(selectedRegion,pageSize,OffsetSize);
// RTV List to be returned
List<Return_to_Vendor__c> rtvRecords= new List<Return_to_vendor__c>();
String query;
if(selectQuery!=null){
query=selectQuery;
if(wherecond!=null){
query=query + ' where '+ wherecond;
}
if(orderBy!=null){
query=query +' order by ' + orderBy;
}
// Query RTV Records
rtvRecords=Database.query(query);
}
pagesize=rtvRecords.size();
system.debug('pagesize'+pagesize);
// If No RTV Records available for the given criteria then display a message
if(rtvRecords.size()==0){
Apexpages.addmessage(new Apexpages.message(Apexpages.severity.info,'No records to display'));
}
return rtvRecords;
}
public static String getWhereClause(String selectedRegion,Integer PageSize,Integer OffsetSize){
system.debug('pagesize'+PageSize+'OffsetSize'+OffsetSize);
String WhereCond;
if(selectedRegion == 'Argentina'){
WhereCond=' Sales_Org__c =\'9000\' and '+
'Order_Reason__c in (\'120\', \'220\') ' +
'and Status__c=\'Invoice Validated (Create)\' ';
}
else if(selectedRegion == 'Chile'){
WhereCond= ' Sales_Org__c =\'9200\' and ' +
'Order_Reason__c in (\'120\', \'121\', \'123\', \'220\', \'221\') and '+
'Status__c=\'Invoice Validated (Create)\' limit '+pageSize+'OFFSET '+OffsetSize;
}
else if(selectedRegion == 'Mexico'){
WhereCond= ' Sales_Org__c =\'9900\' and '+
'Order_Reason__c in (\'120\', \'121\', \'123\', \'125\', \'128\', \'220\', \'221\') and ' +
'Status__c=\'Invoice Validated (Create)\'';
}
else if(selectedRegion == 'Brazil'){
WhereCond=' Sales_Org__c=\'8000\' and ' +
'Order_Reason__c in (\'120\',\'121\',\'122\',\'123\',\'124\',\'125\',\'126\',\'127\',\'128\',\'130\',\'220\',\'221\',\'322\',\'323\',\'325\') ' +
'and Status__c in (\'Invoice Validated (Create)\', \'Logistics Review Complete\') ';
}
else if(selectedRegion == 'FArgentina'){
WhereCond= ' Sales_Org__c = \'9000\' and ' +
'RecordType.Name=\'Argentina Chile Mexico - Approved\' '+
'and Status__c in (\'Final Approval Required\', \'Recalled\', \'Rejected\') ';
}
else if(selectedRegion == 'FChile'){
WhereCond= ' Sales_Org__c = \'9200\' and ' +
'RecordType.Name=\'Argentina Chile Mexico - Approved\' '+
'and Status__c in (\'Final Approval Required\', \'Recalled\', \'Rejected\') ';
}
else if(selectedRegion == 'FMexico'){
WhereCond= ' Sales_Org__c = \'9900\' and '+
'RecordType.Name=\'Argentina Chile Mexico - Approved\' '+
'and Status__c in (\'Final Approval Required\', \'Recalled\', \'Rejected\') ';
}
else {
WhereCond = ' RecordType.Name=\'None\' ';
}
String currentUserProfileName=getProfileNamefromId(UserInfo.getProfileId());
Id currentUserId=UserInfo.getUserId();
if(WhereCond!= ' RecordType.Name=\'None\' ' && WhereCond!=null
&& !RTVService.checkUserIsInGroup(UserInfo.GetUserId(),'RTV Submitters')
&& currentUserProfileName!='StoreBoard - System Administrator'){
Wherecond=WhereCond +' and (CreatedById = \''+ CurrentUserId +'\' or ownerId = \''+ CurrentUserId+'\' ) ';
}
return WhereCond;
}
public Static String getRoleNamefromId(Id RoleId){
UserRole[] roleList=[Select Id, name from UserRole where Id=:RoleId];
String roleName;
if(roleList!=null && roleList.size()>0){
roleName=roleList[0].Name;
}
return roleName;
}
public Static String getProfileNamefromId(Id profileId){
Profile[] profileList=[Select Id, name from Profile where Id=:profileId];
String profileName;
if(profileList!=null && profileList.size()>0){
profileName=profileList[0].Name;
}
return profileName;
}
}