目录
Invocable actions 将业务逻辑操作封装到一个方法中,用@InvocableMethod注解标注该方法,这样在salesforce的流中就可以被当作action元素使用。
@InvocableMethod
常用的属性
label:在flow builder里面,action的名字。默认是方法名。
description:在flow builder里面,action的描述。
callout:表明方法是否call外部系统,默认是false。
category:在flow builder里面,action的category。
使用注意
- 方法必须是 static和public或global,方法所在的类必须是outer class。
- 在一个类里面只能有一个方法是InvocableMethod注解的。
- 其它注解和InvocableMethod注解不能一起使用。
示例代码
public class AccountQueryAction {
@InvocableMethod(label='Get Account Names' description='Returns the list of account names corresponding to the specified account IDs.' category='Account')
public static List<String> getAccountNames(List<ID> ids) {
// do something
}
}
@InvocableVariable
InvocableVariable注解用作InvocableMethod方法的invocable action的输入或输出参数。
示例代码
public with sharing class GetFirstFromCollection {
@InvocableMethod
public static List <Results> execute (List<Requests> requestList) {
List<SObject> inputCollection = requestList[0].inputCollection;
SObject outputMember = inputCollection[0];
//Create a Results object to hold the return values
Results response = new Results();
//Add the return values to the Results object
response.outputMember = outputMember;
//Wrap the Results object in a List container
//(an extra step added to allow this interface to also support bulkification)
List<Results> responseWrapper= new List<Results>();
responseWrapper.add(response);
return responseWrapper;
}
public class Requests {
@InvocableVariable(label='Records for Input' description='yourDescription' required=true)
public List<SObject> inputCollection;
}
public class Results {
@InvocableVariable(label='Records for Output' description='yourDescription' required=true)
public SObject outputMember;
}
}