0

I have a small list of items which are presented to the user in the Opportunity page, but instead of using the standard list, I'm using a visualforce that presents itself as a list of products.

Note: I need this because I need to sort the items in a specific order, and Salesforce doesn't provide a way to sort the items in the default related list.

So, my code is as simple as having a form with a pageblock and a pageblocktable inside, that have the items, like the following:

<apex:pageBlockTable value="{!itens}" var="item" rows="5">
    <apex:column >
        <apex:commandLink value="Remove" action="{!deleteProduct}" status="loading" oncomplete="console.log('olá mundo');">
            <apex:param name="items id" assignTo="{!item_to_manipulate}" value="{!item.Id}"></apex:param>
        </apex:commandLink>
    </apex:column>
    <apex:column value="{!item.Product2.Name}"></apex:column>
    <apex:column value="{!item.Item__c}"></apex:column>
    <apex:column value="{!item.Quantity}"></apex:column>
</apex:pageBlockTable>

This is just part of the code, but the pageblocktable is inside a pageBlock, which is inside a form.

public void deleteProduct() {
    delete [SELECT Id FROM OpportunityLineItem WHERE Id = :item_to_manipulate];
    this.loadItems();
}

And this is the method invoked when I click the 'Remove' button. I wanted it to reload the items on the list (if I remove an item in a list of 3 items, then the list will show only two items after clicking on the link).

At first I thought the rerender wasn't working because it was an inner Visualforce, but it doesn't work when the page is opened in another tab too.

How can I rerender this?

6
  • This may sound silly but did you check if the OLI is really deleted?
    – javanoob
    Commented Dec 13, 2016 at 22:40
  • add rerender attribute in the commandLink Commented Dec 13, 2016 at 22:44
  • 1
    But the OP says, he is seeing issue even when he is opening in new tab. So how is this a rerender issue?
    – javanoob
    Commented Dec 13, 2016 at 22:49
  • @javanoob I know it is deleted because when I reload the page, the item is no longer there (just as I would expect if the page reloaded automatically as I want to). Commented Dec 13, 2016 at 23:15
  • Ok. Did you try giving id attribute to the pageblock table and refering that in the rerender attribute of commandlink?
    – javanoob
    Commented Dec 13, 2016 at 23:26

2 Answers 2

2

I created a simple example in my developer edition org and it is working:

conRelatedList.page

<apex:page standardController="Account" extensions="ConRelatedList">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockTable value="{!conList}" var="conObj" id="pb-id">
                <apex:column headerValue="Delete">
                    <apex:commandLink value="Remove" action="{!deleteContact}" reRender="pb-id">
                        <apex:param name="conId" assignTo="{!id_to_delete}" value="{!conObj.Id}"></apex:param>
                    </apex:commandLink>
                </apex:column>
                <apex:column headerValue="Name">{!conObj.Name}</apex:column>
                <apex:column headerValue="Id">{!conObj.Id}</apex:column>
            </apex:pageBlockTable>          
        </apex:pageBlock>
    </apex:form>
</apex:page>

conRelatedList.cls

public class ConRelatedList {

    public Account accObj;
    public List<Contact> conList{get;set;}
    public Id id_to_delete{get;set;}

    public ConRelatedList(ApexPages.StandardController stdControllerObj){
        this.accObj = (Account)stdControllerObj.getRecord();
        conList = [SELECT Id,Name FROM Contact WHERE AccountId =: accObj.Id];
    }

    public PageReference deleteContact(){
        //ApexPages.currentPage().getParameters().get('conId')
        delete [SELECT Id FROM Contact WHERE Id =: id_to_delete];
        conList = [SELECT Id,Name FROM Contact WHERE AccountId =: accObj.Id];
        return NULL;
    }

}
1
  • I am not sure if it was because of the PageReference being returned from the method that was called from the button, of if it was because I changed the position of the id, from the form tag to the pageblocktable tag. Anyway, now it works. Thanks! Commented Dec 14, 2016 at 19:45
-1

Rerender the pageblocktable id in commandlink, this should work!

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .