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
Afrose AhamedAfrose Ahamed 

How to show number of records in Confirm prompt before action method on VF

Hi All,

This is just snippet of code that i want to acheive. My apologise if its not understandable im a beginner. I want show a prompt in that  i want show number of records counts from apex class before deleting action happened.Somehow  prompt is showing but Deleting records count is not showing. Please refer the below code and advise how can i acheive this. it will be a great help..

<apex:page sidebar="false" showHeader="false" controller="OldDataController" standardstylesheets="false">
 <script>
    function changeComplete(){
    	alert('{!numberOfRecDeleted}');    
    }
	</script>

 <apex:commandLink oncomplete="changeComplete();" onclick="if(!confirm('Do you want to proceed? {!numberOfRecDeleted}')) return false;"  action="{!DeloldRecords}" status="loadingStatus"  style="margin-left:4px;"><span class="glyphicon glyphicon-file"></span> Delete Records</apex:commandLink>
                          
</apex:page>
public with sharing class OldDataController {

public static Integer numberOfRecDeleted {get;set;}

public static void delController(List<Records__c> DelRecs){
list<String> DelRecsNames = new List<String>();
for(Records__c DelRec : DelRecs)
{
DelRecsNames.add(DelRec.name);
}
numberOfRecDeleted = DelRecsNames.size();
DMLManager.deleteAsuser([Select id from Records__c where id:DelRecsNames]);
System.debug('Number of Records Deleted'+numberOfRecDeleted);
}


User-added image

Regards,

Afrose Ahamed M.G

PriyaPriya (Salesforce Developers) 
Hi Afrose,

You can take the reference fromt this code to insert the number of record in popup message :-

https://salesforce.stackexchange.com/questions/79761/how-to-display-no-of-records-inserted-in-a-popup-visualforce-page
 

Kindly mark it as the best answer if it works for you.

 

Thanks & Regards,

Priya Ranjan