+ Start a Discussion
SubbehSubbeh 

Invoking external webservices using WSDL file

Hi,

 

I'm very new to Salesforce, Cloud development, Apex etc. but I'm trying to setup the following:

 

We have a registration webform that communicates with salesforce through web to lead. As soon as a user submits the form, a new Lead is created in Salesforce.

As soon as the new Lead is created, a connection needs to be made to the CMS system where a username and password will be created and returned to Salesforce.

 

There is an API for the CMS system with available WSDL file which I used to create an Apex class.

I created a trigger for Leads called testCallout invoking the ValidateUserPassword method:

 

 

trigger TestCallout on Lead (after insert) {
    for (Lead a : Trigger.new) {
        ComWebservices.CMS_x0020_Live_x0020_ServicesSoap stub = new ComWebservices.CMS_x0020_Live_x0020_ServicesSoap();
        String input = 'Test';
        String output = stub.ValidateUserPassword(input);
    }
}

 This gives me:

"Error: Compile Error: Method does not exist or incorrect signature: stub.ValidateUserPassword(String)"

 

The Apex class is setup like this:

 

 

public class ComWebservices {
    ...
    public class CMS_x0020_Live_x0020_ServicesSoap {
        ...
        public Boolean ValidateUserPassword(Integer userId,String userLogin,String password) {
            ComWebservices.ValidateUserPassword_element request_x = new ComWebservices.ValidateUserPassword_element();
            ComWebservices.ValidateUserPasswordResponse_element response_x;
            request_x.userId = userId;
            request_x.userLogin = userLogin;
            request_x.password = password;
            Map<String, ComWebservices.ValidateUserPasswordResponse_element> response_map_x = new Map<String, ComWebservices.ValidateUserPasswordResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://website.com/webservices/ValidateUserPassword',
              'http://website.com/webservices/',
              'ValidateUserPassword',
              'http://website.com/webservices/',
              'ValidateUserPasswordResponse',
              'ComWebservices.ValidateUserPasswordResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.ValidateUserPasswordResult;
        }
    ...
    }
    ...
}

 

 

 

I tried many different approaches, but as I've never worked with any object oriented language it doesn't really make sense to me.

Is this the right way to invoke webservices?

 

Please help, I've been struggling with this for days now :smileymad:.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
MandyKoolMandyKool

Hi,

 

Please check the method that you used in Trigger; which is

 

stub.ValidateUserPassword(input); // this takes single arguement.

 

and the signature of the method in Apex Class ValidateUserPassword(Integer userId,String userLogin,String password) //this takes 3 arguements.

 

Also check the return type of ValidateUserPassword(), it is boolean and in trigger you are collecting it in "String".

 

Hope, this will solve your problem.

 

 

Thanks,

Kulkarni.