+ Start a Discussion
Ram@sfdcRam@sfdc 

How to call webservice callout from another webservice class method.

Hi,

In salesforce I have a webservice class containing method.
Through this method I am creating records.

Again after creation of records from webservice method. I need to call PHP webservice class method.

I am calling PHP webservice class from salesforce webservice class method.

I dont know is it right or wrong. Can you suggest how to handle these type of scenarios.
krish99krish99
@Ram,

      Can you post your code..


Ram@sfdcRam@sfdc
Hi Krish,

From External service, they will call the salesforce webservice first, after creating account from salesforce webservice. I am calling PHP webservice. Please Observe bold letter code. Is this is the correct way of calling webservice method from other webservice method.


Salesforce webservice class
global class Create_Account_class
{

    webservice static string CreateWebAccount(string name)
     {
            Account ac=new account(name=name);
             insert ac;
            server s=new server();
// calling PHP webservice method
server.serverPort sp=new server.serverPort();
string str=sp.AddUserRecord(123465,'test','tstpswd','9865243568','Test 1434','Test Address','Hyd','Bihar','India','515621','testemail1345@gmail.com','Test comment',1,0,1,'test group',2564,'15486235','true',20181295);

    }
}



PHP webservice wsdl file generated Apex class:
public class server {
    public class AddUserRecordRequestType {
        public Integer login1;
        public String loginpassword;
        public String password_investor;
        public String password_phone;
        public String name;
        public String address;
        public String city;
        public String state;
        public String country;
        public String zipcode;
        public String email;
        public String comment;
        public Integer enable;
        public Integer enable_change_password;
        public Integer enabled_read_only;
        public String group_x;
        public Integer leverage;
        public String phone;
        public String status;
        public Integer agent_account;
        private String[] login1_type_info = new String[]{'login1','urn:server',null,'1','1','false'};
        private String[] loginpassword_type_info = new String[]{'loginpassword','urn:server',null,'1','1','false'};
        private String[] password_investor_type_info = new String[]{'password_investor','urn:server',null,'1','1','false'};
        private String[] password_phone_type_info = new String[]{'password_phone','urn:server',null,'1','1','false'};
        private String[] name_type_info = new String[]{'name','urn:server',null,'1','1','false'};
        private String[] address_type_info = new String[]{'address','urn:server',null,'1','1','false'};
        private String[] city_type_info = new String[]{'city','urn:server',null,'1','1','false'};
        private String[] state_type_info = new String[]{'state','urn:server',null,'1','1','false'};
        private String[] country_type_info = new String[]{'country','urn:server',null,'1','1','false'};
        private String[] zipcode_type_info = new String[]{'zipcode','urn:server',null,'1','1','false'};
        private String[] email_type_info = new String[]{'email','urn:server',null,'1','1','false'};
        private String[] comment_type_info = new String[]{'comment','urn:server',null,'1','1','false'};
        private String[] enable_type_info = new String[]{'enable','urn:server',null,'1','1','false'};
        private String[] enable_change_password_type_info = new String[]{'enable_change_password','urn:server',null,'1','1','false'};
        private String[] enabled_read_only_type_info = new String[]{'enabled_read_only','urn:server',null,'1','1','false'};
        private String[] group_x_type_info = new String[]{'group','urn:server',null,'1','1','false'};
        private String[] leverage_type_info = new String[]{'leverage','urn:server',null,'1','1','false'};
        private String[] phone_type_info = new String[]{'phone','urn:server',null,'1','1','false'};
        private String[] status_type_info = new String[]{'status','urn:server',null,'1','1','false'};
        private String[] agent_account_type_info = new String[]{'agent_account','urn:server',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
        private String[] field_order_type_info = new String[]{'login1','loginpassword','password_investor','password_phone','name','address','city','state','country','zipcode','email','comment','enable','enable_change_password','enabled_read_only','group_x','leverage','phone','status','agent_account'};
    }
    public class serverPort {
        public String endpoint_x = 'http://tfserver.forexwebsolutions.com/tfserver.php';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'urn:server', 'server'};       
        public String AddUserRecord(Integer login1,String loginpassword,String password_investor,String password_phone,String name,String address,String city,String state,String country,String zipcode,String email,String comment,Integer enable,Integer enable_change_password,Integer enabled_read_only,String group_x,Integer leverage,String phone,String status,Integer agent_account) {
            server.AddUserRecordRequestType request_x = new server.AddUserRecordRequestType();
            server.AddUserRecordResponseType response_x;
            request_x.login1 = login1;
            request_x.loginpassword = loginpassword;
            request_x.password_investor = password_investor;
            request_x.password_phone = password_phone;
            request_x.name = name;
            request_x.address = address;
            request_x.city = city;
            request_x.state = state;
            request_x.country = country;
            request_x.zipcode = zipcode;
            request_x.email = email;
            request_x.comment = comment;
            request_x.enable = enable;
            request_x.enable_change_password = enable_change_password;
            request_x.enabled_read_only = enabled_read_only;
            request_x.group_x = group_x;
            request_x.leverage = leverage;
            request_x.phone = phone;
            request_x.status = status;
            request_x.agent_account = agent_account;
            Map<String, server.AddUserRecordResponseType> response_map_x = new Map<String, server.AddUserRecordResponseType>();
            response_map_x.put('response_x', response_x);
            if(loginpassword!=null && loginpassword!='')
            {
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'urn:server#AddUserRecord',
              'urn:server',
              'AddUserRecord',
              'urn:server',
              'AddUserRecordResponse',
              'server.AddUserRecordResponseType'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.return_x;
            }
            Else
            return null;
        }
    }
    public class AddUserRecordResponseType {
        public String return_x;
        private String[] return_x_type_info = new String[]{'return','urn:server',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:server','true','false'};
        private String[] field_order_type_info = new String[]{'return_x'};
    }
}


Please share me you views if I am wrong..