Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Salesforce 顶点:命令按钮可以';你什么也不还吗?_Salesforce_Apex Code_Visualforce - Fatal编程技术网

Salesforce 顶点:命令按钮可以';你什么也不还吗?

Salesforce 顶点:命令按钮可以';你什么也不还吗?,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我有: 它不起作用(返回401),但如果我写: public String whatever(){ return 'ok'; } 很好 问题是:如何向这个调用返回内容(JSON或页面) 谢谢不是真的。看 至于我,我使用了返回PageReference变量的方法 最好这样做: public void whatever(){ // some code } 关于返回页面-查看。不真实。看 至于我,我使用了返回PageReference变量的方法 最好这样做: public void

我有:

它不起作用(返回401),但如果我写:

public String whatever(){
    return 'ok';
}
很好

问题是:如何向这个调用返回内容(JSON或页面)

谢谢

不是真的。看 至于我,我使用了返回PageReference变量的方法

最好这样做:

public void whatever(){
    // some code
}
关于返回页面-查看。

不真实。看 至于我,我使用了返回PageReference变量的方法

最好这样做:

public void whatever(){
    // some code
}

关于返回页面-查看。

命令按钮用于在服务器上执行一些代码,它们返回页面引用,而不是字符串/json值

public PageReference whatever(){
    PageReference pageRef = null; // null won't refresh page at all if I'm not mistaken
    // some cool logic goes here
    if(toNavigate) {
      pageRef = new PageReference('here is some URL to which user must be navigated');
    } else if(toRefreshCurrent) {
      pageRef = ApexPages.currentPage();
    }

    return pageRef;
}
视觉力

public class myController {
    public string Result {get;set;}

    public PageReference whatever() {
        // do your work here
        Result = DateTime.Now();
        return null;
    }
}
在您的示例commandbutton代码中,您使用了rerender,因此不需要返回非空的PageReference。另一方面,如果在单击commandbutton时希望转到另一个页面,则不会设置rerender属性,并且需要返回非空的PageReference, 即


CommandButtons用于在服务器上执行一些代码,它们返回一个PageReference,而不是string/json值

public PageReference whatever(){
    PageReference pageRef = null; // null won't refresh page at all if I'm not mistaken
    // some cool logic goes here
    if(toNavigate) {
      pageRef = new PageReference('here is some URL to which user must be navigated');
    } else if(toRefreshCurrent) {
      pageRef = ApexPages.currentPage();
    }

    return pageRef;
}
视觉力

public class myController {
    public string Result {get;set;}

    public PageReference whatever() {
        // do your work here
        Result = DateTime.Now();
        return null;
    }
}
在您的示例commandbutton代码中,您使用了rerender,因此不需要返回非空的PageReference。另一方面,如果在单击commandbutton时希望转到另一个页面,则不会设置rerender属性,并且需要返回非空的PageReference, 即

<script>    
    function processJSON(val) {
    var res = JSON.parse(val);
    // do your work here
    }
</script>

<apex:outputpanel id="sectionX">
<script>
 processJSON("{!Result}");
</script>
</apex:outputpanel>
public PageReference whatever() {
    return Page.MyVisualforcePage;
}