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
Ben Merton 15Ben Merton 15 

Add a button to delete a related list if you press yes

I am trying to incorporate a button that does the following:

1.  Press Button
2.  Check if there are existing records
3.  If there aren't existing records, run the controller to execute the clone
4.  If there are existing records, give a choice "Yes" or "No"
5.  If Yes, run the controller to execute the clone]
6.  If no, close the box and don't do anything

I need to incorporate it on this code:
 
//////Class before

List<Material_Request__c> womaterialrequest = [select Indent_Quantity__c, Good_Service__c from Material_Request__c where Work_Order__c = :workorderid];
        if(womaterialrequest.size() != 0)
        {
        ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.ERROR, 'Indents already on the Work Order.  Please delete before Adding Indent Again'));
        return null;
        }

///////Class after

Any help
Best Answer chosen by Ben Merton 15
pconpcon
I'm sorry for my original reaction, we get a lot of people posting to the community wanting people here to do work for them.  I echo what Andy says, and would recommend doing the Visualforce route.  I would also recommend reading over this article [1].  You'd do the same steps but instead of creating the Salesforce1 Action you'd create a custom button that used the Visualforce page.

[1] http://blog.deadlypenguin.com/blog/2016/01/03/salesforce1-actions-with-visualforce/

All Answers

pconpcon
It sounds like you're looking for someone to write the code for this project. These forums are not meant for that; you'll want to post over on the AppExchange site [1] where you can match up with a developer looking to work on your project.   If you have any specific problems please feel free to include the code you have any the problems you are facing with that code.

[1] https://appexchange.salesforce.com/developers
Ben Merton 15Ben Merton 15
No.  I am looking for an outline on the methodology, not for someone to write the code.  I am trying to understand how to link this code to the button.  My assumption is that this would need to be a Visualforce page with a controller that points at this code, but I don't know how this links.
Andy BoettcherAndy Boettcher
Ben,

If that's the case absolutely no worries on that front - we are a helping community, not a doing community.  =)

There are two ways to connect code to a button:
1) A VF page using the target object's standardController button.  You can either immediate fire a method via the ACTION attribute of the apex:page tag, or have a UI on the VF page that the users interact with
2) API activation via Javascript.  I wouldn't recommend this approach as with the coming of LEX all bets are off on exact forward compatibility.
Andy BoettcherAndy Boettcher

CORRECTION on #1 - "A VF page using the target object's controller in the "standardController" attribute of the apex:page tag.  You can add a controller extension via the "extensions" attribute.

Example:

<apex:page standardController="Account" extensions="yourClass" action="{!yourMethod}">
pconpcon
I'm sorry for my original reaction, we get a lot of people posting to the community wanting people here to do work for them.  I echo what Andy says, and would recommend doing the Visualforce route.  I would also recommend reading over this article [1].  You'd do the same steps but instead of creating the Salesforce1 Action you'd create a custom button that used the Visualforce page.

[1] http://blog.deadlypenguin.com/blog/2016/01/03/salesforce1-actions-with-visualforce/
This was selected as the best answer
Ben Merton 15Ben Merton 15
No problem guys.  I am a Newbie to this and this basically answers my questions completely.

Would really appreciate it if you could also explain how the hell I connect a trigger to a class:

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000MJtNIAW

You will probably notice a pattern - once I have been able to figure out the method for solving a problem, I can extend it out, remember it, modify it and UNDERSTAND it.  Until then, I look like an idiot and will keep posting.   I am possibly unusual for most people on these Boards as I run my own manufacturing business and am building a product out of an instance I have evolved over the past five years on my own.

The issue is that there isn't a whole lot on that on these boards that explains the methodology for solving problems to new developers.  The assumption is that you can launch straight into the code, but that isn't the case for us mere mortals.  Am really just looking for guidance, not a shortcut.

However, I have noticed some of my developer co-workers spend HOURS trying to solve a problem that just needs a little explanation, where my reaction is just to post to the admin boards.  Maybe this doesn't work for developers, or maybe I am just coming at development from a different perspective......

Ben