10

There is a custom object called Competitor. For this object there is a field called "Primary Competitor (Data type:Check Box)".

Requirement:if primary competitor=checked-->then before saving it has to check if there are any primary competitors has present.If so it has to display an error message in a popup with "yes" "no" buttons on it.As shown in image

Popup

If yes then it has to add new competitor else remain same.

Workaround: for this i created a vf page and added it to pagelayout but it's not firing .

<apex:page standardController="Competitor__c">

<script type="text/javascript">
if(Competitor__c.Primary_Competitor__c=="True")

document.body.style.cursor="auto";
var box=new SimpleDialog("Test", true);
box.setTitle("Is Primary Competitor");
box.createDialog();
    box.setContentInnerHTML("<b>There is a primary Competitor existing, setting this Competitor as primary will remove the primary check on the other Competitor. Please confirm if you want to go ahead?</b><input type=\"button\" value=\"Yes\"  onclick=\"javascript:box.hide();\" /> <input type=\"button\" value=\"No\"  onclick=\"No();\" />");
box.show();
function No()
{
Competitor__c  c =new Competitor__c();
c.Primary_Competitor__c=False;
}
</script>

</apex:page>

Need help. Thank you in advance

2
  • 1
    I would approach this via javascript remoting or action function as i see need for DML on this . Oct 25, 2013 at 7:47
  • This can be solved without Javascript by using either: salesforcegeneral.com/salesforce-modal-dialog-box or tehnrd.com/visualforce-pop-up. The trick is by using a conditionally rendered outputPanel styled by CSS with a zIndex to make it popup. Your controller decides when to make it visible (you'll need an actionSupport on the inputField for Primary Competitor)
    – cropredy
    Dec 24, 2013 at 17:56

2 Answers 2

2

Your code will fire as soon as the page is loaded and only generate the alert if the initial value of primary competitor is true.

When you say have added it to the page layout, is that as an embedded Visualforce page in the record view? The Visualforce will only be present for the view page, not for the edit page.

There's no supported way to achieve what you are attempting using standard pages - you either need to go completely Visualforce or use some JavaScript in a sidebar HTML component to attach your code to the save button - this is not supported by Salesforce though and could break at any time.

0
0

One error in your code is

"if(Competitor__c.Primary_Competitor__c=="True")" This line should be "if({!Primary_Competitor__c=="True"})"

I feel you need to use JavaScript to identify if checkbox is checked. It is not Visualforce but Javascript that you need to think about.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .