You need to sign in to do that
Don't have an account?
Ben Merton 15
Add a 'choice' button and then delete a related list if yes or continue if no
I have a class wherein an error is currently thrown if the records contained in a related list already exist when a clone button is pressed:
If the user selects yes, then all the existing records in the list should be deleted, before the rest of the class is performed. If they select No, then it should return to the existing record without any changes.
Any ideas?
//////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 afterI am looking to convert this to a popup warning that states "Overwrite Existing Material Requests?", with a Yes/No choice.
If the user selects yes, then all the existing records in the list should be deleted, before the rest of the class is performed. If they select No, then it should return to the existing record without any changes.
Any ideas?
Yes, this can easily be acheived by following the below mentioned steps :
1. Add an onclick event on your "Clone" button.
2. Call a javascript function in this onclick event.
3. In this javascript function show a confirmation window to user.
4. Now based on the selection of User on that confirmation window you can perform the further actions by calling an action function from your JS function.
I am providing you a sample code below which can help you to get started on this : Please let me know if you need more information or help on this.
Thanks,
Abhishek Bansal.
Can you confirm the process? Do I not need to point the button to a VF page if I am to use this?
The flow should be:
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
Ben
Sorry for responding you so late as i was busy with new year celebrations.
The code written between <script> and </script> is define as the javascript code for the VF page.
Yes i completely understand your flow and you can easily achieve this by the steps mentioned by me in first post.
Fist of all when you press the button than an action will be called which will check for existing records and if there are not any than it will call the clone method.
But if there are any existing records than it will set a boolean variable as true and return to the VF page which will than call JS method that will show the popup.
Sample code :
If you want more help on this than please share your VF page and controller class code here or contact me on my gmail or skype :
Gmail : abhibansal2790@gmail.com
Skype : abhishek.bansal2790
Wish you a very Happy New Year :)
Thanks,
Abhishek Bansal.