1

I have created 3 classes.

  1. APex Class
  2. Callout Class
  3. 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.

0

The name of the outer (containing) class needs to be used too:

parent.tas.add(new etTemplateBody.templateAttributes1(FName, LName, HomeURL, Promocode));

See towards the bottom of the Extended Class Example documentation for more information.

  • Thanks Keith. After That I got another error "Line No 31: Variable does not exist: parent" error is shown. – preeth Mar 16 '16 at 5:40
  • String jsonPayload = JSON.serialize(parent); – preeth Mar 16 '16 at 6:00
  • @preeth The immediate problem is that the parent object is not in scope when you try to serialize it. But there is a parent object for every loan__Loan_Account__c; you could add those to an array (declared before the loan__Loan_Account__c loop to it is still in scope after the loop) and serialize the array. But that is a design decision for you. – Keith C Mar 16 '16 at 8:33
  • I want to execute the 3 classes. way this is correct. 1. Deliquientdays s = new Deliquientdays (); String sch = '0 0 * * * ?'; System.schedule('Deliquientdays', sch, s); 2. Deliquientdays s = new Deliquientdays (); database.executeBatch(s,200); If I am using the second one i got a error like that "Line: 10, Column: 1 Argument must be an object that implements Database.Batchable" – preeth Mar 17 '16 at 10:11
  • I am not using the batch class. – preeth Mar 17 '16 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.