Json Webservice致电Apex Salesforce

时间:2014-07-16 06:38:34

标签: json salesforce apex

任何人都可以共享端到端示例,以便在Salesforce中通过Apex(Visual Force页面和控制器)调用JSON Web服务。 非常像我们在HTML5中做的那样,Jquery by Ajax!

1 个答案:

答案 0 :(得分:2)

在调用REST Web服务的文档中有一些示例。

来自HTTP Classes

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();
  }
}

您可以将方法更改为以下之一:

  

GET,POST,PUT,DELETE,TRACE,CONNECT,HEAD和OPTIONS

HTTP (RESTful) Services

提供了一个更完整的示例

还支持JSON deserialization

不要忘记使用Remote Site Settings打开对目标域的访问权限。

对于SOAP Web服务,您可以define Apex classes from a WSDL

相关问题