function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RReddyRReddy 

How t o replace SControls By VF Pages



Hi all,

 

   we are going to replace SControls by VF Pages.we are overriden  New Opportunity button on Account Detail Page.

Could you please help how to write code in VFpage and Controller.Is there any other ways to solve this problem.

Please Feel free to write comment on this ..

 

 Opporunity SControl Code

 

html
<body>
<script type="text/javascript">

//This condition restricts the new opportunity to be created under Inactive accounts
if (("{!Account.Status__c }"=="Inactive" ) ){
alert( 'You do not have sufficient rights to Create / Update an Opportunity against an Inactive Account. Please contact Customer Data Team for any assistance.');
window.parent.location.href ="{!URLFOR( $Action.Account.View , Account.Id, null, true)}";
}
else

/* This S control will override the Opportunity New Button with the SaveURL and retURL specified which overrride the Save and Cancel action.SaveURL include the relative URL for the Opportunity Product Page therefore so User on saving the New opportuntiy will be taken to the Add Product Page.
*/

window.parent.location.href ="{!URLFOR($Action.Opportunity.New,Account.Id,[saveURL='/apex/OpportunityProducts?requestFlag=1', retURL=URLFOR($Request.retURL, null,null,true)],True) }"

</script>
</body>
/html

kiranmutturukiranmutturu

simply create a vf page with the standard controller that you are working and copy paste the html code in the script tag of the vf page.. it will work as before

RReddyRReddy

Thx kiran for fast reply...but i was tried like that..i am getting the following error kiran...

 

 

Error: Unknown property 'OpportunityStandardController.Account'

 

 

Status__c is field in the Account object.

RReddyRReddy

how can we solve this by using pagereference....i tried but i didnt get the solution..could you plz let me know the solution.

 

i tried through VF Page also  but i am getting the Error : Unknown property 'OpportunityStandardController.Account'

 

VF Pege Code

 

<apex:page standardController="Opportunity">
  <apex:form>
    <script type="text/javascript">

        //This condition restricts the new opportunity to be created under Inactive accounts
        if(("{!Account.Status__c }"=="Inactive" ) ){
            alert( 'You do not have sufficient rights to Create / Update an Opportunity against an Inactive Account. Please contact Customer Data Team for any assistance.');
            window.parent.location.href ="{!URLFOR($Action.Account.View , Account.Id, null, true)}";
        }
        else

            /* This VF Page will override the Opportunity New Button with the SaveURL and retURL specified which overrride the Save and Cancel action.SaveURL include the relative URL for the Opportunity Product Page therefore so User on saving the New opportuntiy will be taken to the Add Product Page.
            */

            window.parent.location.href ="{!URLFOR($Action.Opportunity.New,Account.Id,[saveURL='/apex/OpportunityProducts?requestFlag=', retURL=URLFOR('$Request.retURL',null,null,true)],True) }"

    </script>
  </apex:form>
</apex:page>

kiranmutturukiranmutturu

you have to use like this Opportunity.Account.Status__c but here you want to redirect to account view in if block and opp view in else block..if you have the standardcontroller as Opportunity you can't use like this {!URLFOR($Action.Account.View , Account.Id, null, true)}";

 

so you have to construct the url.....and set to  window.parent.location.href 

 

like  window.parent.location.href  = 'https://https://na2.salesforce.com/'+Opportunity.account.id;..some thing like this....

 

hope you got the point

RReddyRReddy

I tried like that but still having prob,

 

Could you plz tell me ,how can we solve this by using pageReference.

 

how can we write URLFOR in apex.

1) window.parent.location.href ="{!URLFOR($Action.Account.View , Account.Id, null, true)}";

2) window.parent.location.href ="{!URLFOR($Action.Opportunity.New,Account.Id,[saveURL='/apex/OpportunityProducts?requestFlag=', retURL=URLFOR('$Request.retURL',null,null,true)],True) }"

 

i written like this

 

1) public PageReference init(){
      PageReference pageRef=null;
      System.debug(' success...');         
      pageRef = new PageReference('/Id='+account.Id);   [ bcoz it is redirecting to account pagelayout if the condition is true]     
      pageRef.setRedirect(true);                  
      return pageRef;
    }