I have created 3 classes.
- APex Class
- Callout Class
- JSON Parser Class
In that "apex class" I'm calling the JSON class. It shows the error"Invalid type: templateAttributes1" Line number 29. Please find the below code.
Apex Class:
global with sharing class Deliquientdays {
global List<loan__Loan_Account__c> Deliquientdaynotice(){
set<id> Deliquient75;
set<id> Deliquient87;
set<id> Deliquient108;
String templateId1 = 'Template87';
String templateId2 = 'Template108';
String endpoint = 'http://172.31.77.142:8080/de-service/api/trigger/email';
// Deliquientdaycallout da = new Deliquientdaycallout();
// da.doPostMethod('endPoint');
List<loan__Loan_Account__c> llaList = [select loan__Contact__r.name,loan__Contact__r.Email,name, loan__Number_of_Days_Overdue__c, loan__Oldest_Due_Date__c,loan__Loan_Status__c
from loan__Loan_Account__c
where loan__Number_of_Days_Overdue__c in (75,87,108)
AND loan__Loan_Status__c = 'Active - Bad Standing'];
for(loan__Loan_Account__c lla: llaList){
// if(lla.loan__Number_of_Days_Overdue__c == 75 || lla.loan__Number_of_Days_Overdue__c == 87 || lla.loan__Number_of_Days_Overdue__c == 108){
if(lla.loan__Number_of_Days_Overdue__c == 75){
String templateId = 'Template75';
String Promocode = 'TESTPROMO123';
String FName = lla.loan__Contact__r.FirstName;
String LName = lla.loan__Contact__r.LastName;
String Email = lla.loan__Contact__r.Email;
String contactid = lla.loan__Contact__c;
String HomeURL = 'http://172.31.77.142:8080/de-service/api/trigger/email';
/* etTemplateBody parent = new etTemplateBody(lla.loan__Contact__r.Email, templateId, lla.loan__Contact__c);
parent.tas.add(new templateAttributes1(FName, LName, HomeURL, Promocode));*/
etTemplateBody parent = new etTemplateBody(Email, templateId,contactid );
parent.tas.add(new templateAttributes1(FName, LName, HomeURL, Promocode));
}
}
String jsonPayload = JSON.serialize(parent);
Deliquientdaycallout da = new Deliquientdaycallout();
da.doPostMethod(endpoint, jsonPayload);
/* if(lla.loan__Number_of_Days_Overdue__c == 87){
Deliquient87.add(lla.Id);
}
if(lla.loan__Number_of_Days_Overdue__c == 108){
Deliquient108.add(lla.Id);
}
*/
// }
}
}
JSON Wrapper Class:
public class etTemplateBody {
public String toAddress, templateId, contactId;
public templateAttributes1[] tas;
public etTemplateBody(String toAddress, String templateId, String contactId) {
this.toAddress = toAddress;
this.templateId = templateId;
this.contactId = contactId;
tas = new templateAttributes1[0];
}
public class templateAttributes1 {
//For APPROVED_NEED_TO_ESIGN_WITH_PROMOCOD
public String FirstName, LastName, HomeURL, Promocode;
public templateAttributes1(String FirstName, String LastName, String HomeURL, String Promocode) {
this.FirstName = FirstName;
this.LastName = LastName;
this.HomeURL = HomeURL;
this.Promocode = Promocode;
}
}
}
Callout Class:
global with sharing class Deliquientdaycallout {
global void doPostMethod(String endPoint, String jsonBody) {
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
System.debug('****Trying to reach the URL:' + endPoint);
req.setHeader('Authorization','Basic VEVTVEVSOlRFU1RFUg==');
req.setHeader('Content-Type','application/json');
req.setEndpoint(endPoint);
req.setMethod('POST');
System.debug(jsonBody);
req.setBody(jsonBody);
try
{
res = http.send(req);
if(res.getStatusCode()==200)
{
System.debug(res.getStatusCode());
System.debug(res.getStatus());
}
}
catch(System.CalloutException e)
{
System.debug('Callout error: '+ e);
System.debug(res.toString());
}
}
}
Please help me resolve the issue.