Showing posts with label Page Layout. Show all posts
Showing posts with label Page Layout. Show all posts

Friday, June 1, 2012

Override Standard Button and Page Layout Concept


Override Standard Button and Page Layout
        Override the Standard Button means we can define the custom button or use the standard button action and perform the custom action. Same as for page layout like we need to display the specific page on record type on standard page layouts.
       Here we can write condition on before standard page loading and forward to the any of custom or standard page.

1. View overridden:
Go to Set Up>Custom Object > Standard Buttons and Links >Click on Edit of View
Select with Override and select any S-Control or Visual force page than SAVE.

S-Control HTML Body:
 /apex/Sales_Page_Redirect?id={!Sales__c.Id}

VF page (Sales_Page_Redirect):
<apex:page action="{!view}" controller="SalesController">
</apex:page>

Controller:
public class SalesController {

public PageReference view(){

 //Write here logic and return to page.
Retrun page;
 }

}

2. New overridden:
  We have requirement check which user (Partner/Standard) logged in and view the page and perform the New Button action.

S-Control:
<html>
<head>
<!--Load the ajax drivers-->
<script type="text/javascript" src="/js/functions.js"></script>
<script src="/soap/ajax/12.0/connection.js"></script>
<script src="/js/dojo/0.4.1/dojo.js"></script>
<script src="/soap/ajax/10.0/apex.js"></script>
<script type="text/javascript">
try{
// get the current login user.
var isPortealUser=sforce.apex.execute('CheckedUser','isPartnerUser',{});
// if it is portal user it directed to account search visual force page.else it is directed to recordtype selection page.
if(isPortealUser=='true'){
top.location.href='/apex/Sales_Menu_Partner?standAlone=yes';
}else {
alert("Please raise the request either from Account");
window.parent.location.href="/a1e/o";
}
}catch(Error){
alert(Error);
}
</script>
</head>
<body>
</body>
</html>

 Apex class CheckedUser:

global class CheckedUser {

  WebService static boolean isPartnerUser(){
    boolean isPartnerUser=false;
    //Query to user object to get contact Id of current login user.
    User objUser=[Select Id,contactID from User where Id=:userinfo.getuserid()];
    //check contact Id is not null.
    if(objUser.contactID!=null){
    //if contact is not null,then current login user is partner user.Make isPartnerUser flag true.
        isPartnerUser=true;
     }
    return isPartnerUser;
   }
}

How to Add VisualForce page in Standard Page Layout


Requirement: We have requirement when lead saved/created by Partner user then show popup alert message like Lead is saved not submitted.

Technical: Partner portal user creates Lead and Save it so it will open Lead standard page. So we need to add Alert message on this Standard page. We have two options given below:
Open 1: We can override the Lead’s View which is in
Setup>Object (Lead)>Standard Button and Link>View>Edit
First you have to create visualforce page which is getting the window on load alert message. Add this page to View override in Lead.

Open 2: We have another option like if we have visualforce page and add in to Page Layout. Which checks the Lead Status = ‘Draft’and Lead Category = ‘Opportunity Registration’ then show alert message to Portal user. We have created Visualforce page which satisfy above criteria and show alert message.

Visualforce Page OppRegAlertPage:

<apex:page standardController="Lead" tabStyle="Lead" >
<apex:form >
<apex:inputHidden value="{!Lead.Lead_Category__c}" id="LeadCategoryId"/>
<apex:inputHidden value="{!Lead.Status}" id="StatusId"/>
</apex:form>
<script language="javascript">
  var LdCategory;
  var LdStatus;
      LdCategory=document.getElementById('j_id0:j_id1:LeadCategoryId').value;
      LdStatus=document.getElementById('j_id0:j_id1:StatusId').value;    
   window.onload = function() {
    if( LdCategory == 'Opportunity Registration' && LdStatus =='Draft'){
           alert(‘Lead Saved but not Submitted!');
           }
   }
</script>
</apex:page>

I)   Setting>Go to Lead> Page Layout>Select page layout for Portal user>Edit
II)  Click on Edit Layout> Click on Visualforce pages>Select page > Drag and Drop in to Page
III) section>Double click on Page>
IV) Open Visualforce Page Properties> Width (in pixels or %)s=10%
                                                         Height (in pixels) = 0
                                                         Save Page Layout.