You need to sign in to do that
Don't have an account?
sudhirn@merunetworks.com
Redirect to same page with page refresh
Hi,
I have writted a controller to check if attached is added or not on a custom object if not added it will show a message else submit for approval.
I want to redirect to same page where the user clicked the button from with page refresh I added below code but it is not working please suggest me how to modify the code.
I have writted a controller to check if attached is added or not on a custom object if not added it will show a message else submit for approval.
I want to redirect to same page where the user clicked the button from with page refresh I added below code but it is not working please suggest me how to modify the code.
public class check_spr_coterm { Integer count = 0; String PageID; public check_spr_coterm() { SPR__c SP; //OpportunityLineItem OLI; SP = [select id,Opportunity__c from SPR__c where Id = : ApexPages.currentPage().getParameters().get('id') limit 1]; PageID = ApexPages.currentPage().getParameters().get('id'); List<AggregateResult> OLI = [select count(id) from OpportunityLineItem where opportunityid = :SP.Opportunity__c and name like '%COTERM%' ]; List<AggregateResult> ATH = [select count(id) athcnt from Attachment where parentid = :ApexPages.currentPage().getParameters().get('id')]; count = (Integer)ATH[0].get('athcnt'); } public void pageAction(){ if(count ==0){ ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'You cannot submit as this record dont have attachment')); } else { Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest(); req.setObjectId(PageID); Approval.ProcessResult result = Approval.process(req); //ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'Sucessfully submitted for approval')); redirectpage(); } } public PageReference redirectpage() { PageReference pageRef = new PageReference(PageID); pageRef.setRedirect(true); return pageRef; } }
Please use below code then you would be able to solve your problem.
And believe PageID would be your record id.
Please mark as a best answer if it resolve your probelom.
PageReference pageRef = new PageReference('/'+PageID);
pageRef.setRedirect(true);
return pageRef;
Thanks,
Anurag