+ Start a Discussion
Deepika GulatiDeepika Gulati 

How do i create an error message on Top of Detail Page??

Hi,

I have a requirement in which when i click on a custom button "generate eID" eID is generated.  A Vf page is used as mediator to call the controller method with the taskid of the current task  and the eID is generated and populated.

 

Now if the eID is already available and still we click on the button i want to display the error message on the top of the Detail page of current task.

 

Currently i have displayed the message on the VF page and with the Link to go back to the current task. but that takes to much time.

 

 

The Controller Class

 

public class eIDController {
public string theID{get; set;} 
public Boolean errorAlert=false;
private final Task o;
// Constructor used to fetch the current Record   
public eIDController(ApexPages.StandardController stdController) 
{    
    this.o = (Task)stdController.getRecord();    
}            
   
//Method making the callout to WrapperDummy class
public PageReference autoRun() 
{    
    List<ID> TaskIds=new List<ID>();
//It extracts the Id of the Current Record
    String theId = ApexPages.currentPage().getParameters().get('id');
    if(theId!=null)    
    {     
        for(Task t:[select ID,Activity__c,CustomerIdentity__c from Task where id=:theId])      
        {
//It checks if the Activity  is null
            if(t.Activity___c==null && t.CustomerIdentity__c != null){
            TaskIds.add(t.ID);
            }
//If it is Not Null it Throws An Error message
            else if(t.Activity__c!=null && t.CustomerIdentity__c != null){
                errorAlert=true;
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Activity already exists'));
                return null;
            }
            else if(t.Activity_TRN__c==null && t.Customer_CIDN__c == null){
                errorAlert=true;
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Customer Identity is Null'));
                return null;
            }
        }
        update TaskIds;

     }                        
    PageReference pageRef = new PageReference('/' + theId);        
    pageRef.setRedirect(true);            
    return pageRef;
    }
}

 

 

 

 

VF page:

 

<apex:page standardController="Task" extensions="eIDController" tabStyle="Task" action="{!autoRun}">
<apex:form >
<apex:sectionHeader title="Auto-Running Apex Code"/>  
<apex:pageblock >
<apex:pageMessages >
</apex:pageMessages>
<apex:outputPanel >
     Click <apex:outputLink value="/{!$CurrentPage.parameters.id}"> Here </apex:outputLink> to return to the Custom object record
  </apex:outputPanel>

</apex:pageblock>
</apex:form>
</apex:page>

 

 

 i want to display the error message in the form of alert box on the Detail Page or in the form of error on the top of Detail page.

 

addError, javascript can be an option but not sure how to implement it

Best Answer chosen by Deepika Gulati
bob_buzzardbob_buzzard

TehNerd posted up an example of using the sidebar to manipulate buttons on the page.  It should be straightforward to repurpose that:

 

http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/

All Answers

bob_buzzardbob_buzzard

The problem you have here is the error is raised by the visualforce page transaction, so you can't redirect to the detail page and "retain" the error.  In order to use addError you'd need to be adding the error to the task, which means you'd be trying to save it via the UI, which you aren't doing.

 

You could probably use a sidebar component with javascript and put the error information on the URL.  It would be an open mechanism though, and thus has the potential to be abused.

Deepika GulatiDeepika Gulati

Hi   bob_buzzard (Moderator),

 

Thanks but can you please Provide more Details on this solution or any sample code if possible.

 

 

Thanks.

bob_buzzardbob_buzzard

TehNerd posted up an example of using the sidebar to manipulate buttons on the page.  It should be straightforward to repurpose that:

 

http://www.tehnrd.com/show-and-hide-buttons-on-page-layouts/

This was selected as the best answer