You need to sign in to do that
Don't have an account?
How to give error msg on VF page, overriding the standard button with vf and redirect based on record type
I have override the standerd Edit button with VF page this VF page will redirect to other VF page based on the record type, the redirection is working properly but i want to give an error messsage on this this page.
In the below class line number 26 error message is not diplaying if i add "return null" it is redirectiong to standerd page if i remove this line it stay in the page and showes "Attempt to De-reference null object" error. Need help ASAP
Thanks in advance
here c.Sys_Ticket_Count__c is grater than 0
Apex Class:
In the below class line number 26 error message is not diplaying if i add "return null" it is redirectiong to standerd page if i remove this line it stay in the page and showes "Attempt to De-reference null object" error. Need help ASAP
Thanks in advance
here c.Sys_Ticket_Count__c is grater than 0
Apex Class:
public with sharing class escaEditBtnController { public escaEditBtnController(ApexPages.StandardController controller) { this.controller = controller; } public PageReference getredirect() { Escalation__c c = [Select id, recordtypeid,Sys_Ticket_Count__c From Escalation__c Where Id = :ApexPages.currentPage().getParameters().get('id')]; PageReference newPage; if (c.recordtypeid == Constants_PicklistVariables.TICKET_RECORDTYPE_ID) { newPage = new PageReference('/apex/TicketEdit?retURL=%2F'+c.id); newPage.getParameters().put('id', c.id); newPage.getParameters().put('editMode', 'true'); } else { if(c.Sys_Ticket_Count__c <= 0 ){ newPage = new PageReference('/apex/EscalationEdit?retURL=%2F'+c.id); newPage.getParameters().put('id', c.id); newPage.getParameters().put('editMode', 'true'); newPage.getParameters().put('nooverride', '1'); }else{ System.debug('c.Sys_Ticket_Count__c'+c.Sys_Ticket_Count__c); ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.Error,'Ticket has been rised for this escalation you do not have access to edit this Escalation, Please contact the system admin')); return null; } } return newPage.setRedirect(true); } private final ApexPages.StandardController controller; }VF page:
<apex:page standardController="Escalation__c" extensions="escaEditBtnController" action="{!nullValue(redirect.url, urlFor($Action.Escalation__c.Edit, Escalation__c.id, null, true))}"> <apex:pageMessages /> </apex:page>
The reason that you're getting "Attempt to De-reference null object" error is because in the case where the control goes inside the if loop in line:26, the PageReference object newPage is not initialized.
And then you are doing newPage.setRedirect(true); in line: 32 which throws a null reference error.
Hope this helps.
Regards,
Lakshmi.
All Answers
The reason that you're getting "Attempt to De-reference null object" error is because in the case where the control goes inside the if loop in line:26, the PageReference object newPage is not initialized.
And then you are doing newPage.setRedirect(true); in line: 32 which throws a null reference error.
Hope this helps.
Regards,
Lakshmi.
PS: Mark it as solution if this solves your problem.
Thanks @Sumitkumar_Shingavi iam getting the record but, still the code you have sent helped me in understanding the code
Thansk a ton mates