我创建了一个自定义的visualforce页面。 在控制器类中,我想在下拉列表中获取所有工作区的列表,以便用户可以选择在何处发布数据
有人可以就如何实现这一目标提供一些指导。
感谢任何帮助。 :)
答案 0 :(得分:2)
您需要查询内容工作区,然后将它们放入选择选项列表中,然后可以在visualforce页面中引用。
Apex Controller:
public Id selectedWorkspaceId { get; set; }
private List<SelectOption> workspaceOptions;
public List<SelectOption> getWorkspaceOptions() {
if(workspaceOptions == null) {
for(ContentWorkSpace workspace : [select id, name from ContentWorkspace]) {
workspaceOptions.addNewSelectOption(
new SelectOption(workspace.id, workspace.name);
}
}
}
return workspaceOptions;
}
Visualforce页面:
<apex:selectList value="{!selectedWorkspaceId}" size="1">
<apex:selectOptions value="{!workspaceOptions}"/>
</apex:selectList>
文档:
答案 1 :(得分:0)
下面是Java代码(从代码重新开始)到查询Salesforce CRM Content中的工作区列表。将下面的代码翻译成顶点,它应该可以工作。
package com.sforce;
import org.apache.axis.client.Stub;
import com.sforce.soap.enterprise.*;
import com.sforce.soap.enterprise.sobject.*;
public class QueryWorkspace {
/**
* @param args
*/
public static void main(String[] args) {
QueryWorkspace queryWorkspace = new QueryWorkspace();
try {
queryWorkspace.queryAvailableWorkspaces();
} catch (Exception ex) {
ex.printStackTrace(System.err);
}
}
private void queryAvailableWorkspaces() throws Exception {
SforceServiceLocator sforceServiceLocator
= new SforceServiceLocator();
SoapBindingStub binding
= (SoapBindingStub) sforceServiceLocator.getSoap();
// Login
LoginResult lr = binding.login("user@jstest.org",
"password");
binding._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY,
lr.getServerUrl());
// Create a session header for subsequent calls
_SessionHeader sessionHeader = new _SessionHeader();
sessionHeader.setSessionId(lr.getSessionId());
binding.setHeader(sforceServiceLocator.getServiceName()
.getNamespaceURI(), "SessionHeader",
sessionHeader);
QueryResult query
= binding.query("select Id, Name from"
+ " ContentWorkspace");
SObject[] records = query.getRecords();
if (records != null) {
for (int i = 0; i < records.length; i++) {
ContentWorkspace contentWorkspace =
(ContentWorkspace)records[i];
System.out.println("Workspace Id:"
+ contentWorkspace.getId() + " Name:"
+ contentWorkspace.getName());
}
}
}
}