zoukankan      html  css  js  c++  java
  • Salesforce Apex页面中调用远端网络服务

    本文介绍了Salesforce Apex页面中调用远端网络服务的实现过程。

    注册远端网络服务

    在使用Apex代码调用远端网络服务之前,首先需要在Salesforce中注册远端网络服务地址, 本文使用librarything.com提供的一个API, 输入为ISBN, 返回其对应的语言。

    登录Salesforce后,选择Setup > Administer > Security Controls > Remote Site Settings

    然后输入远端网络服务地址并保存

    实现Apex Controller

    Controller代码如下, isbn用于接收UI的输入, language向UI返回API的输出。

    checkLanguage方法实现API的调用。

        public class BookController {
            public String isbn { get; set; }
            public String language { get; set; }
            
            public void checkLanguage() {
                
                Http http = new Http();
                
                String url = 'http://www.librarything.com/api/thingLang.php?isbn=' + isbn;
                HttpRequest req = new HttpRequest();
                req.setEndpoint(url);
                req.setMethod('GET');
                
                HttpResponse res = http.send(req);
                language = res.getBody();
            }
        }
    

    Apex页面

    页面代码如下

        <apex:page controller="BookController" showChat="false" showHeader="false">
            <apex:form >
                ISBN : <apex:inputText value="{! isbn}" />
                <apex:commandButton action="{! checkLanguage}" value="Check Language" reRender="result"/>
            </apex:form> 
    
            Language : <apex:outputText id="result" value="{! language}"/>
        </apex:page>
    
  • 相关阅读:
    CSS3 Media Queries 片段
    针对移动设备的CSS3布局
    移动Web界面样式-CSS3
    em与px区别-CSS教程
    webApp添加到iOS桌面
    字典(dick)
    元组(Tuple)
    列表(list)
    字符串的常用方法
    运算符
  • 原文地址:https://www.cnblogs.com/huyouhengsf/p/6180293.html
Copyright © 2011-2022 走看看