我正在从Java应用程序向salesforce写一个休息请求。我的终点可能会不时改变他们的领域。所以我想通过xml或属性文件进行请求体字段名称配置,这样如果在端点侧添加了body,我们将在我们的属性中添加相同的内容,并且工作将以最小的更改完成。任何人都可以建议我是否要创建如下所示的属性文件,如何从核心Java应用程序中设置此值$ {recodeTypeID}?
config.properties
RecordTypeId=${recodeTypeID}
FirstName=${FirstName}
或其他在xml中,其中显示标记具有字段名称和输入值。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<leads>
<fields>
<field>
<display>"ID DATA SOURCE"</display>
<input>ID_DATA_SOURCE</input>
</field>
<field>
<display>"CPF"</display>
<input>CPF</input>
</field>
<field>
<display>"NM PERSON"</display>
<input>NM_PERSON</input>
</field>
<field>
<display>"TP GENDER"</display>
<input>TP_GENDER</input>
</field>
<field>
<display>"DT BIRTH DATE"</display>
<input>DT_BIRTH_DATE</input>
</field>
</leads>
我的RequestBody如下:
JSONObject leads = new JSONObject();
leads.put("RecordTypeId","0126A000000BAIzQAO");
leads.put("FirstName", "Prabhat");
leads.put("Company", "Tests Enterprises");
leads.put("LeadProfile__c", "");
leads.put("Email", "test@email.com");
leads.put("Phone", "1155550000");
leads.put("MobilePhone", "11955550000");
leads.put("ContactPreference__c", "Email");
leads.put("CNPJ__c", "10212469000148");
leads.put("CPF__c", "");
leads.put("Street", "");
leads.put("PostalCode", "");
leads.put("City", "");
leads.put("State", "");
leads.put("Country", "");
leads.put("DealerCode__c", "04659");
leads.put("TMA__c", "KHC");
leads.put("Catalog__c", "KAA8");
leads.put("ModelYear__c", "2018");
leads.put("Color__c", "");
leads.put("InternalFinish__c", "");
leads.put("LeadSource", "Web");
leads.put("LeadSubSource__c", "Website");
leads.put("InterestType__c", "");
leads.put("AgreeReceiveContact__c", "true");
感谢。
答案 0 :(得分:0)
属性文件值通常是硬编码的,如:RecordTypeId=0126A000000BAIzQAO
,如果这是您正在寻找的。
只有当我们知道手头有不同的数据时,才能将它们加载到带有@Value的java中。
对于您的用例,我建议在属性文件中使用逗号分隔值,例如
config.properties
JSONElements=RecordTypeId, FirstName, Company, LeadProfile__c, Email ....
然后在JAVA代码中
@value("JSONElements")
String jsonElements;
String [] elements = jsonElements.split(",");
List<String> values; // This would have values like 0126A000000BAIzQAO, Prabhat, Tests Enterprises
int itr;
for(itr = 0;itr < elements.length: itr++) {
JSONObject leads = new JSONObject();
leads.put(elements[itr], values[itr]);
}
答案 1 :(得分:0)
如果可能,为记录对象创建一个新类,并在类中使用getRequestBody()方法。如果API请求正文发生更改,您只需更改getRequestBody方法,而不是维护单独的XML或属性文件。
前:
public class Record
{
private String name;
private String email;
private String phone;
private String country;
public JSONObject getRequestBody()
{
JSONObject requestBody = new JSONObject();
requestBody.put("FirstName", name);
requestBody.put("EmailId", email);
requestBody.put("PhoneNumber", phone);
requestBody.put("CountryCode", country);
}
}