function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kevin NguyenKevin Nguyen 

Send a URL with an Apex Class

Hi all,

I want to know if my problem is possible.

This is the scenario : I receive an email in my Mail service and i store it in a personnal object : Mail.

But, i want to see my object in an application.

So i wanted to know if it is possible to send an URL from my Apex Class to my application for use it. Is it possible ?  If it is, how can i do it ?

 

Sorry i am new in salesforce and sorry for my english not well.

crop1645crop1645

Kevin -- I'm not 100% clear about your requirements here. But here are some tips.

 

Assuming your application is outside of SFDC, then you have several integration choices

  • Use Workflows and outbound messaging
  • Use APEX and make an HTTP callout

 

An outbound message is a workflow, approval, or milestone action that sends the information you specify to an endpoint you designate, such as an external service. An outbound message sends the data in the specified fields in the form of a SOAP message to the endpoint.

 

An Apex callout enables you to tightly integrate your Apex with an external service by making a call to an external Web service or sending a HTTP request from Apex code and then receiving the response. Apex provides integration with Web services that utilize SOAP and WSDL, or HTTP services (RESTful services).

 

Kevin NguyenKevin Nguyen

Eric,

I have tried Workflows Solution but it doesn't matter.

For Http callout , I tried too but it is the same.

I just want to call an URL like http://192.168.1.1:54551/InsertTask?Id=...

It's for insert a task in my other application with a GET in my URL.

Can you help me with some code please ? Or can you explain me the way for Workflow ' solution please ?

 

Kevin

crop1645crop1645

Kevin

 

From the APEX developers guide:

public class HttpCalloutSample {

// Pass in the endpoint to be used using the string url
  public String getContent(String url) {

// Instantiate a new http object
    Http h = new Http();

// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
    HttpRequest req = new HttpRequest();
    req.setEndpoint(url);
    req.setMethod('GET');

// Send the request, and return a response
    HttpResponse res = h.send(req);
    return res.getBody();
  }
}

 Use this code and replace variable 'url' with the URL you need to use.

 

Then read the Apex Developers Guide on how to write test methods for HTTP callouts as a testmethod won't actually invoke the callout since it can't rollback any updates done by the callout; 

Kevin NguyenKevin Nguyen

Eric

 

Thanks for your code i will try with this solution. Nevertheless, is it possible in Workflow to send a GET ?

 

Edit : I tried This but it didn't do anything

trigger EmailTriggerSF on Mail__c (after insert) {

@future (callout=true)

static void HTTPCallOut(){
// Instantiate a new http object
    Mail__c[] TriggMail = Trigger.new;
    Http h = new Http();    
    String url='http://192.168.1.14:28741/insertTask?serviceID=54/'+TriggMail[0].Id;
// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
    HttpRequest req = new HttpRequest();
    req.setEndpoint(url);
    req.setMethod('GET');
    
// Send the request, and return a response
    HttpResponse res = h.send(req);
}

}

 

crop1645crop1645

Kevin --

 

SFDC workflow outbound messaging sends SOAP messages - your end point must be set up to handle SOAP messages if you use this route

 

In your code example - how did this even compile?

 

  • You can't have methods inside of triggers
  • Future methods don't have access to Trigger context variables in the future method's scope - they have to be passed as arguments