0

I am facing issue on click of a Javascript Button. Getting the below error fault string:

No such parameter param defined for the operation, please check the WSDL for the service

Below is the code:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")} 

var callout = "" + sforce.apex.execute(
    "AnalyzeObjectExportCtrl",
    "exportToExcel",
    {param:"{!Object_Analysis__c.Id}"}); 

if (callout == 'OK') { 
    alert("Your Request is Successful. Click OK and please wait while the page refreshes"); 
    window.location.reload(); 
} 
else { 
    alert("Request Failed " + callout ); 
}

global class AnalyzeObjectExportCtrl {

  public AnalyzeObjectExportCtrl(){

  }
    public static void exportMultipleToExcel(List selectedIDs){
        List objAnalysisList = new List();
        objAnalysisList =  [select name,Field_Count__c,Filter__c,Object_Label__c,Object_Name__c,Record_Count__c,Record_Types_Count__c,
                        (select name,Label__c,Populated_On__c,Populated_On_per__c,Type__c from Field_Analysis__r order by Populated_On__c DESC ) 
                            from Object_Analysis__c where id IN :selectedIDs ]; 
        string excelXML = prepareHeaderAndStyles();
        for(Object_Analysis__c obj : objAnalysisList){
            excelXML += prepareWorkSheet(obj);
        }
        excelXML += '';  
        Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
        attach.setFileName('MultipleObjectAnalysis.xls');
        attach.setInline(false);
        attach.setBody(Blob.valueof(excelXML));

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setUseSignature(false);

        User u = [select email from user where id=:userinfo.getUserId()];
      mail.setToAddresses(new List{u.email});
        mail.setSubject('Object Analysis : Multiple Record Analysis Export');
        string mailBody = '

Hi,

Your Request for Multiple Object Analysis export to Excel file is completed. please find the attachment.

'; mailBody += 'Regards,
Object Analysis'; mail.setHtmlBody(mailBody); mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach }); // Send the email Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); /*Blob bv = Blob.valueof(excelXML); Attachment d = new Attachment(); d.name = 'MultipleObjectAnalysis.xls'; d.ContentType = 'application/vnd.ms-excel'; d.Body = bv; d.ParentId = objAnalysisList[0].id; insert d;*/ } WebService static String exportToExcel(String objAnlyID) { if(String.isNotBlank(objAnlyID)) { try{ Object_Analysis__c objAny = [select name,Field_Count__c,Filter__c,Object_Label__c,Object_Name__c,Record_Count__c,Record_Types_Count__c, (select name,Label__c,Populated_On__c,Populated_On_per__c,Type__c from Field_Analysis__r order by Populated_On__c DESC ) from Object_Analysis__c where id =:objAnlyID ]; string filter = (!string.isBlank(objAny.Filter__c)) ? objAny.Filter__c : ''; string s = prepareHeaderAndStyles(); s += prepareWorkSheet(objAny); s += ''; Blob bv = Blob.valueof(s); Attachment d = new Attachment(); d.name = objAny.name + '.xls'; d.ContentType = 'application/vnd.ms-excel'; d.Body = bv; d.ParentId = objAny.id; insert d; return 'OK'; }catch (Exception e) { return 'ERROR Message:' + e.getMessage(); } }else { return 'ERROR Message: Object Analysis record ID is not specified '; } } public static string prepareWorkSheet(Object_Analysis__c objAny){ string filter = (!string.isBlank(objAny.Filter__c)) ? objAny.Filter__c : ''; string s = ''; s += ''; //Object Analysis details s += 'Object Analysis : ' + objAny.name + ' '; s += 'Object Analysis Name ' + objAny.name + ' '; s += 'Object Label ' + objAny.Object_Label__c + ' '; s += 'Object Name ' + objAny.Object_Name__c + ' '; s += 'Field Count ' + objAny.Field_Count__c + ''; s += 'Row Count ' + objAny.Record_Count__c + ''; s += 'Filter ' + filter + ' '; s += 'Field Analysis '; // header row START ==================> s += 'Field Label'; s += 'Field Name'; s += 'Field Type'; s += 'Populated On'; s += 'Populated On %'; s += ''; // header row END ==================> // DATA ROWS for(Field_Analysis__c fieldAny : objAny.Field_Analysis__r){ s += '' + fieldAny.Label__c + ''; s += '' + fieldAny.Name + ''; s += '' + fieldAny.Type__c + ''; s += '' + fieldAny.Populated_On__c + ''; s += '' + fieldAny.Populated_On_per__c + ''; } s += ''; s += ''; s += ''; //s += ''; s += 'False'; s += 'False'; s += ''; s += ''; return s; } public static string prepareHeaderAndStyles(){ string s = ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; s += ''; return s; } }
2
  • Could you also post code for "AnalyzeObjectExportCtrl"? Feb 4, 2016 at 14:36
  • Hi Shailesh, I have added the controller -- AnalyzeObjectExportCtrl
    – user28476
    Feb 4, 2016 at 14:39

1 Answer 1

1

Please add,

var Object_Analysis = sforce.sObject("Object_Analysis__c");

after

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")} 

The error you are having is because the parameter you are passing should be "objAnlyID" and not "param". So change it to :

"exportToExcel",
    {objAnlyID:"{!Object_Analysis.Id}"}); 

where Object_Analysis is the variable we got from the first line.

Please refer this for more info: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_and_ajax.htm

2
  • Hi Shailesh, Thank you for the response I am facing a diffrenent issue now. It says Sforce is not a function Please help
    – user28476
    Feb 4, 2016 at 15:05
  • Please try changing the versions of the libraries that you have added: {!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")} Feb 5, 2016 at 6:26

You must log in to answer this question.

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