You need to sign in to do that
Don't have an account?
Ravi kumar 292
How to hit the URL
Hi all,
I want to hit the URL(http://test.com/callback.ashx?lead_id=ld121212&contact_id=234234&application_id=IL2342343&status=Approved&amount=100000) when i click on a custom button. How can i do this. Please help.
Thanks
I want to hit the URL(http://test.com/callback.ashx?lead_id=ld121212&contact_id=234234&application_id=IL2342343&status=Approved&amount=100000) when i click on a custom button. How can i do this. Please help.
Thanks
can you try this https://success.salesforce.com/answers?id=90630000000hBg6AAE
Thanks for your reply.
But I have to send a post request to some other server from apex controller and get the response back.
Help on this..
You can refer to following link to execute Apex methode from javascript which will execute when user will click on Custom button.
You have to declare your class as global and your methode as Webservice.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_and_ajax.htm
This is my APex class code:
public with sharing class LDController {
String LeadId;
String Status;
Decimal Amount;
String ApplicationId;
public LoanDecisionController(ApexPages.StandardController controller) {
LeadId=ApexPages.currentPage().getParameters().get('id');
Lead l =[select id,LastName,Amount_in_Rs__c,Status,Application_Id__c from Lead where id=:LeadId];
system.debug('Lead id--'+l.id);
List<Contact> c = [select id,FirstName,LastName from Contact where LastName=:l.LastName];
system.debug('contact id --'+c[0].id);
Status = l.Status;
Amount =l.Amount_in_Rs__c;
ApplicationId =l.Application_Id__c;
}
public Void CallBack(){
String body ='LeadId='+LeadId+'&Status='+Status+'&Amount='+Amount+'&ApplicationID='+ApplicationId+'';
system.debug('------'+body);
// Get the XML document from the external server
Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setEndpoint('http://test/callback.ashx');
req.setMethod('POST');
req.setbody(body);
try{
res = http.send(req);
String response=res.getBody();
System.debug('Response '+response);
}catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
}
}
}
When i hit the Endpoint URL with Leadid,Status,Amount and ApplicationID then i will get a mail from client side that i am hitting their URL. But now am not getting any mail from their end. Please check the code and tel me if i have change the code.
Thanks..
req.setEndpoint('http://test/callback.ashx' + body );
req.setMethod('GET');
I did the same but am not getting any mail from their end.
I have one doubt please clarify it. In order to hit the client URL do we need to pass any username and password??
There are different Authentication mechanisms like oAuth 2.0 or UserName Password based authentication etc.