You need to sign in to do that
Don't have an account?

When we click on button in one org it will automatically create contact in another org by using Soap API Callout
Hi folks,
I have written one class in org1.I generated wsdl file and partner wsdl of that class. I login to other salesforce org2 and import those two files into this org. I created one stub class in org2 and using this class i have called those classes and methods and callout this stub class using developer console. While executing this class it throws an error [System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://login.salesforce.com/services/Soap/u/34.0]. I have pasted login url in Remote site settings in org 2.
Apex class in Org1:
global class webservicesoap1
{
webservice static string createcontact(string Fname,string Lname,String phone)
{
list<contact> conlist=[select id from contact where firstname =:fname and lastname =:lname and phone =:phone];
if(conlist.size()!=0)
{
return 'contact already exists';
}
else{
contact c=new contact();
c.firstname=fname;
c.lastname=lname;
c.phone=phone;
insert c;
return c.id;
}
}
}
Stub Class i implemented in org2:
public class soapcallout
{
public soapcallout(ApexPages.StandardController controller) {
}
public soapcallout()
{
partnerSoapSforceCom.soap spc=new partnerSoapSforceCom.soap();
string username ='sfgt@283.com';
string password ='radhekrishna***AIyGjqKUpuRnKaBzoX6XRUnzH';
partnerSoapSforceCom.loginresult loginresult = spc.login(username, password);
system.debug(loginresult.sessionid);
soapSforceComSchemasClassWebservice.webservicesoap1 websrvc= new soapSforceComSchemasClassWebservice.webservicesoap1();
soapSforceComSchemasClassWebservice.SessionHeader_element sessionheader =new soapSforceComSchemasClassWebservice.SessionHeader_element();
sessionheader.sessionid = loginresult.sessionid;
websrvc.timeout_x = 120000;
websrvc.sessionheader = sessionheader;
string s = websrvc.createcontact('Mahesh','Krishna','9526389523');
}
}
I have written one class in org1.I generated wsdl file and partner wsdl of that class. I login to other salesforce org2 and import those two files into this org. I created one stub class in org2 and using this class i have called those classes and methods and callout this stub class using developer console. While executing this class it throws an error [System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint = https://login.salesforce.com/services/Soap/u/34.0]. I have pasted login url in Remote site settings in org 2.
Apex class in Org1:
global class webservicesoap1
{
webservice static string createcontact(string Fname,string Lname,String phone)
{
list<contact> conlist=[select id from contact where firstname =:fname and lastname =:lname and phone =:phone];
if(conlist.size()!=0)
{
return 'contact already exists';
}
else{
contact c=new contact();
c.firstname=fname;
c.lastname=lname;
c.phone=phone;
insert c;
return c.id;
}
}
}
Stub Class i implemented in org2:
public class soapcallout
{
public soapcallout(ApexPages.StandardController controller) {
}
public soapcallout()
{
partnerSoapSforceCom.soap spc=new partnerSoapSforceCom.soap();
string username ='sfgt@283.com';
string password ='radhekrishna***AIyGjqKUpuRnKaBzoX6XRUnzH';
partnerSoapSforceCom.loginresult loginresult = spc.login(username, password);
system.debug(loginresult.sessionid);
soapSforceComSchemasClassWebservice.webservicesoap1 websrvc= new soapSforceComSchemasClassWebservice.webservicesoap1();
soapSforceComSchemasClassWebservice.SessionHeader_element sessionheader =new soapSforceComSchemasClassWebservice.SessionHeader_element();
sessionheader.sessionid = loginresult.sessionid;
websrvc.timeout_x = 120000;
websrvc.sessionheader = sessionheader;
string s = websrvc.createcontact('Mahesh','Krishna','9526389523');
}
}
Here is the below sample code which will create contact using REST API
Thanks,
Karan
Could you paste the code of Apex Class that you have generated from WSDL file
Step 2 [Authorization Provider]:
Now move into the another org from where you are going to send information and create the Authorization provider.
- Navigate to “Setup | Administer | Security Controls | Auth. Providers | Create New”. Select “Salesforce” as provider Type.
- We need to provide “Consumer Key” and “Consumer Secret” created in previous step.
- Also one important setting is “Default Scope“, it should have value as “refresh_token full”. “refresh_token” and “full” should be separated by space.
- Authorize Endpoint URL should be something like “https://login.salesforce.com/services/oauth2/authorize” and Token Endpoint URL “https://login.salesforce.com/services/oauth2/token“.
- Click save which will generate the some client configuration URLs, copy the Call back URL from the Authorization provider and paste it in the 'Callback URL' section of 'Connected Apps'
Step3 [Named Credentials]:Now create the Named Credentials. Navigate to “Setup | Administer | Security Controls | Named Credentials | New Named Credential “
- Label and Name Any suitable value. We will refer that name in the Apex code
- URL URL of Salesforce instance where we want to Connect
- Identity Type - Named Principal
- Authentication - Protocol OAuth 2.0
- Authentication Provider - Select Authentication Provider created in step 2
- Scope - refresh_token full
Now run the code which I shared in the previous comment in the anonymous window of developer console to verify.