You need to sign in to do that
Don't have an account?

I want to throw error while creating new opportunity
Account having a checkbox field if that flag value is true then clicking on newopportunity button it should throw error?
You need to sign in to do that
Don't have an account?
Both approaches are pretty quick, but Javascript is definitely faster if it is an option for you. Just check for your field's value off Account and if true, display a Javascript alert button to the end-user. If false, then redirect user to the standard Opportunity create page. (/006/e).
For Ligthning, override the New button with a Visualforce page. Use the standard Controller. Use apex:outputPanel to either render an error or to redirect them to the Opportunity create page. It would look something like this (replacing reference to LDS, field name and error message).
Hope that helps!
"New Opportunity" Button in related list of Account page layout.
Javascript code:
if({!Account.checkbox_field_api_name})
window.location = '/006/e?retURL={!Account.Id}&accid={!Account.Id}';
else
alert('Field is not checked');
If you want to pass some parameter also do below
window.location = '/apex/VF_Page_Name?accId={!Account.Id}';
Else do this
window.location = '/apex/VF_Page_Name';
if({!Account.checkbox_field_api_name})
window.location = '/apex/VF_Page_Name';
else
alert('Field is not checked');
Thanks for the solution , here i have different record types in Opportunity, Already this new button is overrided with Vf page.
Now i want to add my logica on Same method and want to call this method on another new vf page and show the error message
public class NewOpportunity {
String recordId;
String oppAcctId = ApexPages.currentPage().getParameters().get('accid');
public NewOpportunity(ApexPages.StandardController controller) {
this.recordId = controller.getId();
}
public PageReference redirect() {
f(oppAcctId == null)
{
PageReference pr1 = new PageReference('/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL=%2F006%2Fo&save_new_url=%2F006%2Fe%3FretURL%3D%252F006%252Fo');
pr1.getParameters().put('nooverride','1');
return pr1;
}
else
{
PageReference pr2 = new PageReference('/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL=%2F0011100000pm5gT&save_new_url=%2F006%2Fe%3FretURL%3D%252F' + oppAcctId + '%26accid%3D' + + oppAcctId);
pr2.getParameters().put('nooverride','1');
return pr2;
}
}
}
public PageReference redirect() {
if(oppAcctId == null)
{
PageReference pr1 = new PageReference('/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL=%2F006%2Fo&save_new_url=%2F006%2Fe%3FretURL%3D%252F006%252Fo');
pr1.getParameters().put('nooverride','1');
return pr1;
}
else
{
Account acc = [Select Checkbox_field From Account Where id =: oppAcctId] ;
if(acc.Checkbox_field != true){
//Redirect to new VF page
}
else{
PageReference pr2 = new PageReference('/setup/ui/recordtypeselect.jsp?ent=Opportunity&retURL=%2F0011100000pm5gT&save_new_url=%2F006%2Fe%3FretURL%3D%252F' + oppAcctId + '%26accid%3D' + + oppAcctId);
pr2.getParameters().put('nooverride','1');
return pr2;
}
}
}