1

I've created a custom button called "Convert to Service Catalogue" that should mark a checkbox called "convert_to_service_catalogue__c" as TRUE when clicked providing the running user is a sys admin, service/project owner, or a specific user.

However it's firing an error message when I click the button, that is along the lines of

"A problem with the OnClick JavaScript for this button or link was encountered: faultcode: 'soapenv:Client', faultstring:'No such parameter product2 defined for the operation, please check the WSDL for the service.',)

Below is the code for my button;

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

var result = sforce.apex.execute("ProductAction","convertToService",

{Product2:"{!Product2.Id}"});

window.location.href = '/'+result[0].Id+'/e';

And below is my apex class, what do I need to change to get this working?

global class ProductAction {
  WebService static String convertToService(Id product2) {
    string result; // Return a string telling us if this worked or not
    Id currentProfile = UserInfo.getUserId(); // Get the current user profile Id
    Id CurrentUser = UserInfo.getUserId(); // Get the current user Id

    Set<Id> allowedProfiles = new Set<Id>(); // Create a new set to profile Ids
    for (Profile p: [SELECT Id, Name FROM Profile WHERE Name = 'System Administrator']) {// Get the System Administrator profile
        allowedProfiles.add(p.Id); // Add them to the set
    }

    Set<Id> allowedUsers = new Set<Id>(); // Create a new set to store User Ids
    for (User u: [SELECT Id FROM User WHERE Id = '005w0000004j93kAAA' OR Id = '005w0000004Noi6']) {//Select Joy Palmer and Andy McGregor Id's and select Jeremey Sharp and Mark O'Leary once they're in SF}
        allowedUsers.add(u.Id);// Add them to the set
    }
    Product2 prod = [SELECT Convert_to_Service_catalogue__c, R_D_Service_Owner__r.id , Project_Owner__r.Id From Product2 WHERE Id = :product2]; // Get the product

    if( //If...
        (currentUser == prod.R_D_Service_Owner__r.id) || // They own it
        (currentUser == prod.Project_Owner__r.id) || // They own it 
        (allowedProfiles.contains(currentProfile)) || //They're a system admin
        (allowedUsers.contains(currentUser))// They're a specific user
        ) {
            //Do stuff!
            prod.Convert_to_Service_Catalogue__c = true;

            UPDATE prod;

            result = 'Success!';

        }   
    else {// Otherwise...
          // Do nothing
          result = 'Go Away!';
        }  
       // Return a message
       return result;
    }

}

1 Answer 1

1

The web service method that this toolkit calls is case sensitive. Change the script to use product2 instead of Product2.

var result = sforce.apex.execute("ProductAction","convertToService", {product2:"{!Product2.Id}"});

You must log in to answer this question.

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