I am trying to find a workaround for an issue using Javascript and Visualforce, but I am not very familiar with Javascript. Essentially, when a user creates a new Opportunity or tries to edit an existing Opportunity whose related Account is a certain type and a particular field on the Opportunity is empty, the user should be re-directed to a Visualforce page. Otherwise, they should just be directed to the standard edit page for the Opportunity. I am doing it this way rather than replacing the Edit button with a VF page because I want to also maintain the ability of in-line editing on the Opp, which cannot be done if the edit button is overridden. So I am trying to embed the VF page below in my Opp to fire whenever the Opp is edited and the conditions are met. It's not working, as it doesn't do anything. Does anyone see an issue why it would not pull up the VF page?
<apex:page standardController="Opportunity">
<apex:includeScript value="/soap/ajax/34.0/connection.js" />
<script type="text/javascript">
var AgeAdv = new Object();
AgeAdv.openWizard = function(){
if(
{!(Opportunity.Account.Type == 'Ag') &&
ISBLANK(Opportunity.Ad__c) &&
CONTAINS(Opportunity.RecordType.Name,'New')
}
)
{
window.parent.location.href = "/apex/OpportunityEditOverride?Id={!Opportunity.Id}"; );
}else
{
window.parent.location.href = "/{!Opportunity.Id}/e?retURL=%2F{!Opportunity.Id}";
}
return this;
};
AgeAdv.openWizard();
</script>
</apex:page>
);
over on the far right of your post; if that is in your page it will stop the JavaScript from working. Check your browser's console for JavaScript errors.