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;
   }
}

No comments:

Post a Comment