+ Start a Discussion
JaggyJaggy 

standard controller deleting child records

Hi,

 

I have a VF page which uses standard controller and controller extension. Standard object is Account and I am displaying Contacts in standard way. I've delete button on every contact row which in turn call an action and passes record id of contact as param. But deletion is not working.

VF

                    <apex:pageblockTable value="{!Account.Contacts}" var="r"  styleClass="inline-editable" >
                        <apex:column headerValue="Action" width="50">
                            <apex:commandLink action="{!onDeleteContact}" rerender="iprs-id" 
                                            status="preloader2" onclick="var con = confirm('Are you sure?');if(con==false)return false;">
                                <apex:image url="{!URLFOR($Resource.icons,'delete_icon.gif')}" title="delete" />
                                <apex:param name="OwnerId" value="{!r.id}" />
                            </apex:commandLink> 
                        </apex:column>

                        <apex:column headerValue="Contact Name">
                        <apex:outputField value="{!r.Name}" />
                            
                        </apex:column>

                       
                    </apex:pageblockTable>

 Controller code

	public void onDeleteContact() {

		Id cId = ApexPages.currentPage().getParameters().get('CId');
		
		Integer i = -1;
		Boolean flag = false;
		for (Contact c : acc.contacts) {
			i++;
			if (c.Id == cId) {
				flag = true;
				break;
			}
		}
		
		System.debug('i-' + i);
		
		if(flag) {
			System.debug('Owners1-' + acc.contacts);
			delete acc.contacts.remove(i);
			System.debug('Owners2-' + acc.contacts);
			update acc.contacts;
		}
		
	}

 

here acc is reference to account (acc = (Account)stdcon.getRecord();)

I am using rerender on VF page. I just want to table to referesed only. But my deletes the contact record but account.contacts does not get updated. I don't know how to do this. But when I remove rerendering then it works fine. Can anyone tell me what I am missing here.

Devendra@SFDCDevendra@SFDC
Hi,
<apex:outputpanel id="op">
<apex:form>
<apex:pageblockTable value="{!Account.Contacts}" var="r"  styleClass="inline-editable" >
                        <apex:column headerValue="Action" width="50">
                            <apex:commandLink action="{!onDeleteContact}" rerender="op" 
                                            status="preloader2" onclick="var con = confirm('Are you sure?');if(con==false)return false;">
                                <apex:image url="{!URLFOR($Resource.icons,'delete_icon.gif')}" title="delete" />
                                <apex:param name="OwnerId" value="{!r.id}" />
                            </apex:commandLink> 
                        </apex:column>

                        <apex:column headerValue="Contact Name">
                        <apex:outputField value="{!r.Name}" />
                            
                        </apex:column>

                       
                    </apex:pageblockTable>
</apex:form>
</apex:outputpanel>
 

 

If your delete functionality is working, then try this changes in your code.

 

Thanks,

Devendra