Salesforce 想要将列表中的值传递给 JSON 以调用 API
Salesforce want to pass values from list to JSON to call API
您好 Salesforce 开发人员,
从我在下面的代码中创建的 SOQL 列表,我想将电子邮件和名称传递给我已经序列化的 json。请让我知道为什么我无法通过
顶点:
public class SampleMaroPost {
public static string sendEmailThroughMaro(string myInpEmail) {
string successContacts = '';
string failureContacts = '';
Date d = Date.Today().addDays(15);
list<Account> conts = new list<Account> ([SELECT name, Email_FLP_com__c from account where ID IN
(select Distributor__c from Stripe_Subscripton__c where Start_Date__c = TODAY AND Actual_End_Date__c = : d AND Status__c='active' ) AND Email_FLP_com__c != NULL LIMIT 1]);
overallEmail myEmail = new overallEmail();
for(Account c : conts){
myEmail.email.campaign_id = 172;
myEmail.email.contact.Email = c.Email_FLP_com__c;
myEmail.email.contact.first_name = c.name;
system.debug('#### Input JSON: ' + JSON.serialize(myEmail));
JSON 使用:
{
"email": {
"campaign_id": 172,
"contact": {
"email": "x1testa@gmail.com",
"first_name": "Test_naresh"
}
}
}
这是与硬编码名称和电子邮件一起使用时的完整代码,这是有效的想查询我们的记录并插入 "Name" "Email",然后分批发送。
public class sampleMaroPost1 {
public list<Account> autorenewal {set;get;}
public void renewal(){
Date d = Date.Today().addDays(15);
autorenewal = [SELECT ID, Email__c, name, Provision_Date__c, Email_FLP_com__c from account where ID IN
(select Distributor__c from Stripe_Subscripton__c where Actual_End_Date__c = :d AND Status__c='active' ) AND Email_FLP_com__c != NULL limit 1];
}
public static maroResponse sendEmailThroughMaro(string myInpEmail) {
//Contact c = [SELECT Id ,LastName, Email FROM Contact WHERE Email = 'vineeth.anirush@gmail.com'];
string resultBodyGet = '';
overallEmail myEmail = new overallEmail();
myEmail.email.campaign_id = 174;
myEmail.email.contact.email = 'shrikant.bhise@nextsphere.com'; //c.Email;
myEmail.email.contact.first_name = 'Swetha'; //c.LastName;
Map<String, String> tags = new Map<String, String>();
tags.put('firstName', 'Swetha');
myEmail.email.tags = tags;
system.debug('#### Input JSON: ' + JSON.serialize(myEmail));
String endpoint = 'http://api.maropost.com/accounts/1173/emails/deliver.json?auth_token=j-V4sx8ueUT7eKM8us_Cz5JqXBzoRrNS3p1lEZyPUPGcwWNoVNZpKQ';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setHeader('Accept', 'application/json');
req.setHeader('Content-type', 'application/json');
req.setbody(JSON.serialize(myEmail));
Http http = new Http();
try{
system.debug('Sending email');
HTTPResponse response = http.send(req);
system.debug('sent email');
resultBodyGet = response.getBody();
system.debug('Output response:' + resultBodyGet);
maroResponse myMaroResponse = new maroResponse();
}
catch (exception e){
system.debug('#### exception: ' + e.getMessage());
}
maroResponse myMaroResponse = new maroResponse();
if(resultBodyGet != null && resultBodyGet != '')
{
myMaroResponse = (maroResponse) JSON.deserialize(resultBodyGet, maroResponse.class);
}
system.debug('#### myMaroResponse: ' + myMaroResponse);
return myMaroResponse;
}
public class maroResponse {
public string message {get;set;}
}
public class overallEmail {
public emailJson email = new emailJson();
}
public class emailJson {
public Integer campaign_id;
public contactJson contact = new contactJson();
public Map<String, String> tags;
}
public class contactJson {
public string email;
public string first_name;
}
}
第16天没有数据。我用了
Date d = Date.Today().addDays(14);
而不是
Date d = Date.Today().addDays(15);
谢谢
您好 Salesforce 开发人员,
从我在下面的代码中创建的 SOQL 列表,我想将电子邮件和名称传递给我已经序列化的 json。请让我知道为什么我无法通过
顶点:
public class SampleMaroPost {
public static string sendEmailThroughMaro(string myInpEmail) {
string successContacts = '';
string failureContacts = '';
Date d = Date.Today().addDays(15);
list<Account> conts = new list<Account> ([SELECT name, Email_FLP_com__c from account where ID IN
(select Distributor__c from Stripe_Subscripton__c where Start_Date__c = TODAY AND Actual_End_Date__c = : d AND Status__c='active' ) AND Email_FLP_com__c != NULL LIMIT 1]);
overallEmail myEmail = new overallEmail();
for(Account c : conts){
myEmail.email.campaign_id = 172;
myEmail.email.contact.Email = c.Email_FLP_com__c;
myEmail.email.contact.first_name = c.name;
system.debug('#### Input JSON: ' + JSON.serialize(myEmail));
JSON 使用:
{
"email": {
"campaign_id": 172,
"contact": {
"email": "x1testa@gmail.com",
"first_name": "Test_naresh"
}
}
}
这是与硬编码名称和电子邮件一起使用时的完整代码,这是有效的想查询我们的记录并插入 "Name" "Email",然后分批发送。
public class sampleMaroPost1 {
public list<Account> autorenewal {set;get;}
public void renewal(){
Date d = Date.Today().addDays(15);
autorenewal = [SELECT ID, Email__c, name, Provision_Date__c, Email_FLP_com__c from account where ID IN
(select Distributor__c from Stripe_Subscripton__c where Actual_End_Date__c = :d AND Status__c='active' ) AND Email_FLP_com__c != NULL limit 1];
}
public static maroResponse sendEmailThroughMaro(string myInpEmail) {
//Contact c = [SELECT Id ,LastName, Email FROM Contact WHERE Email = 'vineeth.anirush@gmail.com'];
string resultBodyGet = '';
overallEmail myEmail = new overallEmail();
myEmail.email.campaign_id = 174;
myEmail.email.contact.email = 'shrikant.bhise@nextsphere.com'; //c.Email;
myEmail.email.contact.first_name = 'Swetha'; //c.LastName;
Map<String, String> tags = new Map<String, String>();
tags.put('firstName', 'Swetha');
myEmail.email.tags = tags;
system.debug('#### Input JSON: ' + JSON.serialize(myEmail));
String endpoint = 'http://api.maropost.com/accounts/1173/emails/deliver.json?auth_token=j-V4sx8ueUT7eKM8us_Cz5JqXBzoRrNS3p1lEZyPUPGcwWNoVNZpKQ';
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setHeader('Accept', 'application/json');
req.setHeader('Content-type', 'application/json');
req.setbody(JSON.serialize(myEmail));
Http http = new Http();
try{
system.debug('Sending email');
HTTPResponse response = http.send(req);
system.debug('sent email');
resultBodyGet = response.getBody();
system.debug('Output response:' + resultBodyGet);
maroResponse myMaroResponse = new maroResponse();
}
catch (exception e){
system.debug('#### exception: ' + e.getMessage());
}
maroResponse myMaroResponse = new maroResponse();
if(resultBodyGet != null && resultBodyGet != '')
{
myMaroResponse = (maroResponse) JSON.deserialize(resultBodyGet, maroResponse.class);
}
system.debug('#### myMaroResponse: ' + myMaroResponse);
return myMaroResponse;
}
public class maroResponse {
public string message {get;set;}
}
public class overallEmail {
public emailJson email = new emailJson();
}
public class emailJson {
public Integer campaign_id;
public contactJson contact = new contactJson();
public Map<String, String> tags;
}
public class contactJson {
public string email;
public string first_name;
}
}
第16天没有数据。我用了
Date d = Date.Today().addDays(14);
而不是
Date d = Date.Today().addDays(15);
谢谢