• MadeForIT
  • NEWBIE
  • 5 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 1
    Replies
======TEST CLASS FOR THIS PLEASE TODAY ITSELF=====

public class ExecuteProductfromJSON{

    public String productId;    //15075
    public String productName;  //Single Property Rental - 40 Year IO (60% LTV Max)
    public String productCode;  //SAR-40YF-IO-LTR-60
    public String investorName; //Truly Mortgage
    public String investorCode; //TM
    public boolean isPricingEnabled;
    public cls_productFields[] productFields;
    public cls_calculatedFields[] calculatedFields;
    public cls_status status;
    
    public class cls_productFields {
        public String fieldId;  //field@product-loan-program
        public cls_value value;
    }
    
    public class cls_value {
        public String type; //number
        public String value;    //7.375
        public string count;
        public string unit;
        public string variantId;
    }
    
    public class cls_calculatedFields {
        public String fieldId;  //calc@adjusted-interest-rate
        public cls_value value;
    }
    
    public class cls_status {
        public String type; //approved
        
        public cls_priceScenarios[] priceScenarios;
        public cls_priceAdjustments[] priceAdjustments;
        public cls_marginAdjustments[] marginAdjustments;
        public cls_rateAdjustments[] rateAdjustments;
        public cls_stipulations[] stipulations;
    }
    
    public class cls_priceScenarios {
        public cls_priceScenarioFields[] priceScenarioFields;
        public cls_calculatedFields[] calculatedFields;
        //public cls_status status;
    }
    
    public class cls_priceScenarioFields {
        public String fieldId;  //base-interest-rate
        public cls_value value;
    }
    
    public class cls_priceAdjustments {
        public String ruleId;   //31788
        public String amount;   //0
        public String description;  //DSCR - 2.409 / LTV - 60.000%
    }
    
    public class cls_marginAdjustments {
    
    }
    
    public class cls_rateAdjustments {
        public String ruleId;   //32118
        public String amount;   //6.875
        public String description;  //LLRA - Base Rate
    }
    
    public class cls_stipulations {
    
    }
    
    public static ExecuteProductfromJSON parse(String json){
        return (ExecuteProductfromJSON) System.JSON.deserialize(json, ExecuteProductfromJSON.class);
    }
}


 
TEST CLASS FOR THIS PLEASE====

public class AddRowAuraController 
{   
    @AuraEnabled
    public static void saveLoanApplicantList(List<LoanApplicant> conList, string loanapplicationId) 
    {        
        system.debug('loanapplicationId'+loanapplicationId);
        list<LoanApplicant> newconlist= new list<LoanApplicant>();
        map<string,LoanApplicant> applicantMap = new map<string,LoanApplicant>();
        map<string,LoanApplicant> SendEmailGuarantorMap = new map<string,LoanApplicant>();
       
        for(LoanApplicant La:conList){
            LoanApplicant Loan = new LoanApplicant(LoanApplicationId = loanapplicationId);
            Loan.Name = La.Name ;
            Loan.Last_Name__c = La.Last_Name__c;
            Loan.Email__c = La.Email__c;
            Loan.Title__c = La.Title__c;
            Loan.Ownershiprelativetoentity__c = La.Ownershiprelativetoentity__c;
            
            newconlist.add(Loan);
        }
        
        system.debug('newconlist'+newconlist);
        
        if(!newconlist.isEmpty()){
            
            for(LoanApplicant ap : newconlist){
                if(ap.Email__c != null){
                    applicantMap.put(ap.Email__c,ap);
                }
            }
            
            for(LoanApplicant la : [select id, ContactId , Email__c from LoanApplicant where Email__c in : applicantMap.keySet()]){
                applicantMap.get(la.Email__c).id = la.id;
            }
            
            for(LoanApplicant lp : applicantMap.values()){
                if(lp.id == null){
                    SendEmailGuarantorMap.put(lp.email__c,lp);
                }
            }
            
            if(!applicantMap.isEmpty()){
                upsert applicantMap.values();
            }
            
        }
        
    }
    
    
    public static void sendEmailToGuarantor(map<string,LoanApplicant> SendEmailGuarantorMap, map<string,LoanApplicant> applicantMap){
    
        for(String LAEmail : SendEmailGuarantorMap.keySet()){
        
            LoanApplicant lap = applicantMap.get(LAEmail);
            
            
            Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
            message.setSaveAsActivity(true);
            EmailTemplate emailTemplate = [Select Id,Subject,Description,  HtmlValue,DeveloperName,Body from EmailTemplate where name = 'GuarantorEmail'];
            
            message.setTemplateID(emailTemplate.Id);
            message.setWhatId(lap.Id); 
            
            message.toAddresses = new String[] { lap.email__c};
                    
            Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
                        
            Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
            
            if (results[0].success){
                System.debug('The email was sent successfully.');
            }else{
                System.debug('The email failed to send: ' + results[0].errors[0].message);
            }
        
        }
    }
    
    
    @AuraEnabled
    public static void removerecord(List<LoanApplicant> conList, string index){
        
        system.debug('conList: '+conList.size());
        delete [Select Id From LoanApplicant Where Id = :index];
        
        
    }
    
    @AuraEnabled
    public static list<LoanApplicant> getLoanApplicantList( string loanapplicationId) 
    {        
        system.debug('loanapplicationId: '+loanapplicationId);
        
        list<LoanApplicant> getconlist= [Select id, Name, First_Name__c , Last_Name__c , Email__c  , Ownershiprelativetoentity__c , Title__c From LoanApplicant where LoanApplicationId =:loanapplicationId AND Non_guarantors_key_principle__c = false And Primary_Guarantor__c = false];
        System.debug('List of applicants:'+getconlist);
        return getconlist;
        
    }
}
I think i will have to make dynamic SOQL query in an apex class 
and create input fields in lwc with a submit button. On click of the submit
button it will call a handler which will call the above class which is making 
a dynamic query to display records. Am i correct in my approach?? 
If yes then please guide me with the code as i am not able to write the required query. 
And if not then kindly guide me with the right approach.
Thank you in advance.
I have requirement of creating a LWC in which i have 8 fields from 2 different Objects. After user has entered the data, on click of 1 button, records should be saved in respective objects. 
Basically is there any way to save records of multiple objects with a single save button? 
I know how to create record in LWC using Apex, using Lightning/UI RecordApi and lightning-record-edit-form,  But all of these to save records in a single object with one button click.
please help me out.
Lead VarL1=new Lead();
VarL1.FirstName='Christina';
VarL1.LastName='Yang';
VarL1.company='Meditech';

Lead varL2 = new Lead();
varL2  =[select id,company from Lead MobilePhone ='9779379992'];
VarL2.company='Max';

list<Lead>VarLeadList=new list<Lead>();
VarLeadList.add(VarL1);
VarLeadList.add(VarL2);
update VarLeadList;
 
I have requirement of creating a LWC in which i have 8 fields from 2 different Objects. After user has entered the data, on click of 1 button, records should be saved in respective objects. 
Basically is there any way to save records of multiple objects with a single save button? 
I know how to create record in LWC using Apex, using Lightning/UI RecordApi and lightning-record-edit-form,  But all of these to save records in a single object with one button click.
please help me out.