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
Ebi AmabebeEbi Amabebe 

trying to make Apex button into a custom button possible?

So I have this Command command button on a inline visual force page. 

 
<apex:commandButton id="urlButton" title="Send selected file(s) to MCA" value="Send selected file(s) to MCA" onclick="SendObject();return false;"/>
  <apex:commandButton id="sendurlbutton" title="Send to MCA with Docs" value="Send to MCA with Docs" onclick="generateUrls();return false;"/>
  </apex:form>
it calls the function generateUrls, the function is:
 
function generateUrls()
    {
        var isSelected = false;
        var inputElem = document.getElementsByTagName("input");
        var selectedIds = new Array();
        for(var i=0; i<inputElem.length; i++)
        {   
            if(inputElem[i].id.indexOf('checkedone')!=-1)
            {
                if(inputElem[i].checked)
                {
                    var checkedElement = document.getElementById(inputElem[i].id);
                    var closedTr = $j(checkedElement).closest('tr');
                    var menuForSelectedItem = $j(closedTr).find(".menubutton");
                    if(menuForSelectedItem)
                    {
                        selectedIds.push($j(menuForSelectedItem).attr('id').split('_')[1]);
                    }
                }
            }       
        }
        if(selectedIds.length == 0)
        {
            alert('Please select a file(s) before uploading!');
        }
        else
        {   
            var htmlText = '<div style="margin-bottom:10px;"><strong>Sending selected file(s) to MCA.</strong></div><div>Please wait for file status to appear...</div>';
            var dlg = $j('<div title="MCA File Upload Status..." />').html(htmlText).dialog({ width: 500, height: 250 });
            
            Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.GenerateUrlExtension.submitDocumentsToMCA}',
            selectedIds, 
            '{!MCA_Submission__c.Opportunity__c}', 
            '{!MCA_Submission__c.id}',
            '{!MCA_Submission__c.App_Id__c}',
            function(result, event){
                var updateText;
                if (event.status) {
                    updateText = '<div><strong>Upload Results:</strong></div><ul>';
                    for(var i=0; i < result.length; i++) {
                        updateText += '<li style="margin-bottom:10px;">' + result[i] + '</li>';
                    }
                    updateText += '</ul><div><strong>Process Complete.</strong></div>';
                    dlg.html(updateText);
                } else if (event.type === 'exception') {
                    alert('Exception' + event.message); 
                } else {
                    alert('Error' + event.message); 
                }
            }, 
            {escape: true}
        );

 So I have a custom button, and I'm trying to execute the same method however I'm not sure how I can get the attachmentids in a custom button. My question is it is possible? What am I missing. Here is what I am trying...
 
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/26.0/apex.js")}

var mca_id = "{!MCA_Submission__c.Id}";
var app_id = "{!MCA_Submission__c.App_ID__c}";
var sub_id = "{!MCA_Submission__c.Opportunity__c}";




var upload = sforce.apex.execute("GenerateUrlExtension","submitDocumentsToMCA",{sub_id,mca_id,app_id,  });



alert("Result: " + mca_request + upload);
document.location.reload(true);

in a custom button. I'm just not sure how to get the attach ment Ids in a var and then to the method. 
Best Answer chosen by Ebi Amabebe
Eric AnEric An
Hi,

You can have a look in RemoteAction or actionFunction, they provide the custom and async method to transfer the data to back end.