• Mukesh Verma 21
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

I have a controller which aids in displaying a visualforce page with the Edit & delete functionality.However, my delete doesn't seem to work.

Kindly assist.Am using this post as a guide:

public class OrderDealsExtension {
	
	public List<Deals__c> deals {get;set;}
	public String SelectedDealId {get;set;}
	
	public OrderDealsExtension() {
		loadData();
	}
		
	public void loadData() {
			
		deals = [Select id,Name,Deal_Start_Date__c,Candidates__c,Contact__c,Deal_End_Date__c,Deal_Type__c,Deal_Buy_Price__c,Deal_Client_Rate__c,CreatedDate from Deals__c Order By CreatedDate desc];
	}
	
	public void deleteDeal(){
		if(SelectedDealId == null){
			return;
		}
		//find the deal record within the collection
		Deals__c tobeDeleted = null;
		for(Deals__c d :deals){
			if(d.Id == SelectedDealId){
				tobeDeleted = d;
				break;
			}
			
			//if deal record found delete it
			if(tobeDeleted != null){
				Delete tobeDeleted;
			}
			
			//refresh the data
			loadData();
		}
	}
	
}

Visualforce Page.

<apex:page controller="OrderDealsExtension">
<apex:form id="form" >
<apex:pageBlock title="Deals">
  <apex:pageMessages ></apex:pageMessages>
  <apex:pageBlockTable value="{!deals}" var="d">
     <apex:column >
       <apex:outputLink title="" value="/{!d.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
       <a href="javascript&colon;if (window.confirm('Are you sure?')) deleteDeal('{!d.Id}');" style="font-weight:bold">Del</a>
     </apex:column>
    <apex:column headervalue="Order Number" >
	<apex:outputLink value="/{!d.id}">
	<apex:outputField value="{!d.Name}"/>
	</apex:outputLink>
</apex:column>
<apex:column value="{!d.Candidates__c}" />
<apex:column value="{!d.Contact__c}" />
<apex:column value="{!d.Deal_Start_Date__c}" />
<apex:column value="{!d.Deal_End_Date__c}" />
<apex:column value="{!d.Deal_Buy_Price__c}" />
<apex:column value="{!d.Deal_Client_Rate__c}" />
  </apex:pageBlockTable>
</apex:pageBlock>

<apex:actionFunction action="{!deleteDeal}" name="DeleteDeal" reRender="form" >
   <apex:param name="dealid" value="" assignTo="{!SelectedDealId}"/>
</apex:actionFunction>
</apex:form>
</apex:page>