TransWikia.com

How do I call this method inside of inner class

Salesforce Asked by Lavasocks on October 4, 2021

Hello im really confused about how to call requestBody(Id quoteId) inside this code I created using inner classes:

public class PT_Interface{
    
public class Request_Model {
   
    
    public String ptquoteid {get;set;} 
    public String ptaccount {get;set;}
    public String sfobjreceive {get;set;} 
    
    
    @TestVisible
    public Request_Model(SBQQ__Quote__c myData) { 
        this.ptquoteid = '123';
        // this.ptquoteid = myData.SOMETHING 
        // this.ptaccount = myData.SOMETHING 
    }

    public String requestBody(Id quoteId) {
            SBQQ__Quote__c myQuote_Data = [
            Select ID, Name 
            FROM SBQQ__Quote__c
            WHERE Id = :quoteId Limit 1
        ];
        if (myQuote_Data == null) {
            System.debug(logginglevel.ERROR, 'The world is falling');
            return null;
        }
        Request_Model returnData = new Request_Model(myQuote_Data);
        return JSON.serialize(returnData);
    }

}
    
    
public class Response_Model {
    

    public String l2igroup {get;set;} 
    public String l2ipart {get;set;} 
    public String l2idescription {get;set;} 
    public Integer l2iquantity {get;set;} 
    public String l2igroupid {get;set;} 
    public String l2iproductid {get;set;} 
    
    public void Response_Model(){
    system.debug('l2igroup in interface '+l2igroup);
    l2iproductid = 'CHANGED';
    }
}
   
}

I’ve tried using this:

 PT_Interface.Request_Model ic = new PT_Interface.PT_Request_Model();
        ic.requestBody('a01234567');

But I get errors about it thinking Request_Model() doesn’t exist. Any help would be appreciated.

One Answer

Your outer class is PT_Interface, so you need to call your inner class in this format PT_Interface.PT_Request_Model. And you can't call your constructor without a parameter since you have defined your constructor to expect a parameter.

Sample code:

PT_Interface.PT_Request_Model ic = new PT_Interface.PT_Request_Model(anObject);
ic.requestBody('a01234567');

Answered by Hengky Ilawan on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP