0

I'm not sure what I'm doing wrong but I have a column where I am trying to send an ID to the controller to delete it from the database and pageBlockTable.

enter image description here

The problem is when I call the removeThisTeamMember() method - the otIdValue value is always null. What am I doing wrong? I'm not sure I have my actionSupport method set up correctly...

Page:

    <apex:page controller="OperationalTeamController">
    <apex:form >
        <apex:pageBlock title="Operational Team Mass Update" >
            <apex:pageBlockButtons >
                <apex:commandButton id="update" action="{!quickUpdat}" value="Quick Update Roles"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable id="pageblocktableid" value="{!ot}" var="o">
                <apex:inlineEditSupport showOnEdit="update, cancelButton" 
 hideOnEdit="editButton" event="ondblclick" 
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
                <apex:column headerValue="Delete">

                    <!--heres the action support-->
                    <apex:actionSupport event="onclick" action="{!removeThisTeamMember}" reRender="pageblocktableid">
                        <apex:commandLink onclick="if(confirm('Are you sure you want to delete this Team Member?')) {return true;} else return false;">
                            <img style="" src="/img/func_icons/remove12_on.gif" alt="X"/>
                            <apex:param name="otIdValue" value="{!o.id}" assignTo="{!otIdValue}"/>
                        </apex:commandLink>
                    </apex:actionSupport>


                </apex:column>
                <apex:column headerValue="Operational Team Name">
                    <apex:outputfield value="{!o.name}"/>
                </apex:column>
                <apex:column headerValue="Team Member Role">
                    <apex:outputfield value="{!o.Team_Member_Role__c}"/>
                </apex:column>
                <apex:column headerValue="Last Modified Date">
                    <apex:outputfield value="{!o.LastModifiedDate}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:

public class OperationalTeamController {
    public list <Operational_Team__c> ot {get;set;}
    public Map <Id, String> oldData = new Map<Id, String>();
    public list <Operational_Team__c> otToUpdate = new list <Operational_Team__c>();
    public String message{get;set;}
    public String otIdValue {get;set;} //capture value from assignTo
    public OperationalTeamController(){

        Id oppId = ApexPages.currentPage().getParameters().get('id');       
        //string searchquery='select name,Team_Member_Role__c from Operational_Team__c WHERE ID = \'a1Z0t000000W4e7\'';
        ot = [select id, name, Team_Member_Role__c, LastModifiedDate from Operational_Team__c WHERE Opportunity__c = :oppId ];
        for(Operational_Team__c o : ot){
            oldData.put(o.Id,o.Name+';'+o.Team_Member_Role__c);
        }
    }
    public PageReference removeThisTeamMember(){
        System.debug(otIdValue); //this is always null

        //to-do: get the record in question and delete it
        return null;
    }

    public PageReference quickUpdat(){
        try{
            //loop through values and only update names that were actually changed
            for(Operational_Team__c o : ot){
                if(o.Name+';'+o.Team_Member_Role__c != oldData.get(o.Id)){
                    otToUpdate.add(o);
                }
            }
            update otToUpdate;
            PageReference pageRef = ApexPages.CurrentPage();
            pageRef.setRedirect(true);
            return pageRef;
            }catch(Exception e){
            message='Data Base error during saving...';
            ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR,      message));
            return null;
        }
    }
}

If my approach is way off and there is a better way to do this, I'm all ears. I personally think a wrapper is overkill for this, hence why I'm sending individual rows to the controller. Thanks!!

2 Answers 2

1

apex:actionSupport is meant to be inside other elements, not outside; the click handler actually ends up bubbling up to include the entire table cell because of this. Also, since the param was on the link, the apex:actionSupport doesn't get the parameter. Instead, drop the apex:actionSupport entirely and call the method from the apex:commandLink instead:

<apex:commandLink action="{!removeThisTeamMember}" reRender="pageblocktableid"
                  onclick="if(!confirm('Are you sure you want to delete this Team Member?')) return false;">
    <img style="" src="/img/func_icons/remove12_on.gif" alt="X"/>
    <apex:param name="otIdValue" value="{!o.id}" assignTo="{!otIdValue}"/>
</apex:commandLink>
2
  • Perfect! Thanks Fox! Is there a "right" way to rerender the "pageblocktableid" to reflect the deleted Opportunity while still keeping changes in-tact? The deleted opps still show up on the pageBlockTable even when I loop through the List<Operational_Team__c> ot and delete the element.
    – rmarq423
    Commented Jun 7, 2018 at 15:21
  • @rmarq423 You need to remove it from the list (ot.remove(index)). This will leave the other changes in place while removing the item.
    – sfdcfox
    Commented Jun 7, 2018 at 15:31
1

You need to add rerender attribute in commandLink. Also you don't need actionsupport here you can easily do using apex:commandLink.

<apex:commandLink rerender="none"
1
  • I tried that, but the debug doesn't fire at all without the apex:actionSupport, as if the method wasn't fired.
    – rmarq423
    Commented Jun 7, 2018 at 14:32

You must log in to answer this question.

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