2

I have create a custom object in which i have a custom button to send email. I was able to send email. Until i packaged it. My code before package:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var r = confirm("Do you want to email this position to CM-Focus.");
if(r == true)
{ 
sforce.apex.execute("ctrl_sendEmail_ToCM","sendEmail",{jId:"{!Position__c.Id}"});
alert("Thanks for sending email to CM-Focus.");
}

after package the code get changed and the namespace get added to the code CMSR__ with Position__c.Id. I installed the package the installed package do not contain the namespace so from there i am able to send email. But in the development env i am getting an error that:

A problem with the OnClick JavaScript for this button or link was encountered: {faultcode:'soapenv:Client', faultstring:'No operation available for request {http://soap.sforce.com/schemas/package/ctrl_sendEmail_ToCM}sendEmail, please check the WSDL for the service.', }

The only difference between the developer env code and installed env code is the namespace. Dose this namespace make any difference. Or this issue is due to any other reason. My apex class code:

  webservice static void sendEmail(string jId){

    //generateEmailContent();

    //set all the contents for email
    //String[] toaddress = new String[]{'positionemailtolead@t-1j7i9bcxptr0wlspn7vozeowvb1447pr9gl6vxszhawlzi3n9m.a-h3zcmac.na7.apex.salesforce.com', 'anuraj@cm-focus.com'};  

   /* Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
    msg.setTemplateId('00X90000000EFl1');
    msg.setToAddresses(new String[] {'anuraj@'});
    msg.setTargetObjectId('0039000000snaAK');
    msg.setWhatId(posDetails.id);
    //msg.setSaveAsActivity(false);
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { msg });
    */
    //emailpostiontoleads@29tb66orqct63bbvol8oksrk6ck7g3e8bn7899wsb3xnwzg4w1.i-k9dqeai.na15.apex.salesforce.com



    Id jobID;// To get the position ID from URL
    Position__c posDetails = new Position__c();   // To get the all the records releted to jobID


    jobID = jId;       
    //jobID = ApexPages.currentPage().getParameters().get('Id'); // Getting the postion Id from URL  


     //SOQL position
    posDetails = [SELECT Name, Account__r.Name, Country__c, Departments__c,Job_Description__c,
                    Job_Type__c, Location__c, Location_State__c, Max_years_of_Exp__c, Min_Years_of_Exp__c,
                    Required_Qualifications_and_Skills__c, Responsibilities__c, Summary__c, Skills_Required__c
                    FROM Position__c WHERE id =:jobID];



    //Email Body 
    emailBody = 'Position Name :' + posDetails.Name+'\n----------------- Account Name :' + posDetails.Account__r.Name+'\n----------------- Country :'+posDetails.Country__c+'\n----------------- Departments :'
                 +posDetails.Departments__c+'\n----------------- Job Description :'+posDetails.Job_Description__c+'\n----------------- Job Type :' + posDetails.Job_Type__c+'\n----------------- Location :'
                 +posDetails.Location__c+'\n----------------- Location State :'+posDetails.Location_State__c+'\n----------------- Max Exp :'+posDetails.Max_years_of_Exp__c+'\n----------------- Min Exp :'
                 +posDetails.Min_Years_of_Exp__c+'\n----------------- Required Qualifications :'+ posDetails.Required_Qualifications_and_Skills__c+'\n----------------- Responsibilities :'+ posDetails.Responsibilities__c
                 +'\n----------------- Summary :'+posDetails.Summary__c+'\n----------------- Skills :'+posDetails.Skills_Required__c;


    //emailBody = emailBodyInweb;

    String[] toaddress = new String[]{'anuraj@cm-focus.com'};
    //String[] toaddress = new String[]{'positionemailtolead@t-1j7i9bcxptr0wlspn7vozeowvb1447pr9gl6vxszhawlzi3n9m.a-h3zcmac.na7.apex.salesforce.com'};
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();     
    mail.setToAddresses(toaddress);
    mail.setsubject('Job postion ');
    mail.setPlainTextBody (emailBody);  
   // system.debug('Email body before sending ' + emailBody);

    //send email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });           


}

This is a global class. Please help me to get this issue solved.

3

Your apex webservice invocation will also need a namespace prefix added, from

sforce.apex.execute("ctrl_sendEmail_ToCM","sendEmail",{jId:"{!Position__c.Id}"});

to

sforce.apex.execute("CMSR.ctrl_sendEmail_ToCM","sendEmail",{jId:"{!CMSR__Position__c.Id}"});

Note the difference in how apex classes are referenced (namespace followed by a .) is different than how SObjects are (namespace followed by double underscore).

|improve this answer|||||
  • Look again, you need the namespace on the apex class name as well. CSMR.ctrl_... – ca_peterson Mar 26 '14 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.