The users of my org have a needs but I don't know how to help them. In my Organization there are two objects Opportunity and P&L. Every Opportunity have one and only one P&L where the agents insert more information about the Opportunity's products. The problem is that: The users can add Opportunity's products after the P&L is created. They want an Alert that says :"P&L already exists, go and modify it."

My question is: Can I add an alert on the button "add product" that pops up only when P&L already exists?


If the Add Product is a custom button, you can make it a JavaScript button and add your validation logic similar to below:


var queryResult = sforce.connection.query("SELECT Id from P_AND_L_OBJECT_API_NAME where Opportunity__c ='{!Opportunity.Id}' limit 1");

records = queryResult.getArray("records"); 

   alert('P&L already exists');
   //navigate to page for adding new Opportunity Product

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.