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
Desk APIDesk API 

Use of apex:actionsupport with apex:commandButton

Hi everyone. I am trying to develop a VisualForce page which will allow users to selectively send Case attachments to an external service. The way I'm doing this is by selecting all ContentDocumentLinks related to the Case, then displaying them in a table with a "Send" button next to each one.

I thought about using apex:actionSupport as a way to store the ID of the specific ContentDocumentLink, however the variable I'm using to store the ContentDocumentLink is NULL after clicking.

Here is the relevant portion of my VF page:
<apex:pageBlockTable value="{!cdls}" var="cdl">
    <apex:column>
        <apex:facet name="header">Documents</apex:facet>
        <apex:outputText value="{!cdl.ContentDocument.Title}"/>
        <apex:form>
            <apex:commandButton value="Send">
                <apex:actionSupport event="onclick" action="{!sendCdl}">
                    <apex:param name="cdlToSend" value="{!cdl.Id}" assignTo="{!cdlToSend}"/>
                </apex:actionSupport>
            </apex:commandButton>
        </apex:form>
    </apex:column>
</apex:pageBlockTable>

And here is the relevant portion of my controller:
public class SendToV1_Button {

    ...

    public Id cdlToSend {get; set;}

    ...

    public PageReference sendCdl() {
        System.debug(cdlToSend);
        return redirect();
    }
}

Any help would be greatly appreciated.​​​​​​​
Best Answer chosen by Desk API
SRKSRK
that prarm is getting created inside a loop muliple time when you submit it will not able to define which varable need to send there is no region it is submittting complete form

you can try using region it might solve it not 100% sure 
<apex:pageBlockTable value="{!cdls}" var="cdl">
    <apex:column>
        <apex:facet name="header">Documents</apex:facet>
        <apex:outputText value="{!cdl.ContentDocument.Title}"/>
        <apex:form>
            <apex:actionRegion>
                <apex:commandButton value="Send">
                    <apex:actionSupport event="onclick" action="{!sendCdl}">
                        <apex:param name="cdlToSend" value="{!cdl.Id}" assignTo="{!cdlToSend}"/>
                    </apex:actionSupport>
                </apex:commandButton>
            </apex:actionRegion>
        </apex:form>
    </apex:column>
</apex:pageBlockTable>


if region did not work then action funcation will work 

    <apex:pageBlockTable value="{!cdls}" var="cdl">
    <apex:column>
        <apex:facet name="header">Documents</apex:facet>
        <apex:outputText value="{!cdl.ContentDocument.Title}"/>
        
    <apex:actionFunction action="{!sendCdl}" name="methodOneInJavascript">
        <apex:param name="cdlToSend" assignTo="{!cdlToSend}" value="" />
    </apex:actionFunction>
        <apex:form>
            <apex:actionRegion>
                <apex:commandButton value="Send" onclick="MYJSFuncation({!cdl.Id})"/>
                </apex:commandButton>
            </apex:actionRegion>
        </apex:form>
    </apex:column>
</apex:pageBlockTable>
<script>
funcation MYJSFuncation(RecordId)
{
    methodOneInJavascript(RecordId);
    //return false; // if it do anything funny try return false
}
 

All Answers

SRKSRK
that prarm is getting created inside a loop muliple time when you submit it will not able to define which varable need to send there is no region it is submittting complete form

you can try using region it might solve it not 100% sure 
<apex:pageBlockTable value="{!cdls}" var="cdl">
    <apex:column>
        <apex:facet name="header">Documents</apex:facet>
        <apex:outputText value="{!cdl.ContentDocument.Title}"/>
        <apex:form>
            <apex:actionRegion>
                <apex:commandButton value="Send">
                    <apex:actionSupport event="onclick" action="{!sendCdl}">
                        <apex:param name="cdlToSend" value="{!cdl.Id}" assignTo="{!cdlToSend}"/>
                    </apex:actionSupport>
                </apex:commandButton>
            </apex:actionRegion>
        </apex:form>
    </apex:column>
</apex:pageBlockTable>


if region did not work then action funcation will work 

    <apex:pageBlockTable value="{!cdls}" var="cdl">
    <apex:column>
        <apex:facet name="header">Documents</apex:facet>
        <apex:outputText value="{!cdl.ContentDocument.Title}"/>
        
    <apex:actionFunction action="{!sendCdl}" name="methodOneInJavascript">
        <apex:param name="cdlToSend" assignTo="{!cdlToSend}" value="" />
    </apex:actionFunction>
        <apex:form>
            <apex:actionRegion>
                <apex:commandButton value="Send" onclick="MYJSFuncation({!cdl.Id})"/>
                </apex:commandButton>
            </apex:actionRegion>
        </apex:form>
    </apex:column>
</apex:pageBlockTable>
<script>
funcation MYJSFuncation(RecordId)
{
    methodOneInJavascript(RecordId);
    //return false; // if it do anything funny try return false
}
 
This was selected as the best answer
Desk APIDesk API
Hi SRK. Unfortunately that didn't work for me, but I was able to fix my issue by refactoring the pageBlockTable into a selectList instead
SRKSRK
Awsome have a good day 
SRKSRK
HI Desk 

If you like mark this as sovled i belive that will keep the community clean