+ Start a Discussion
Shubham Sinha 43Shubham Sinha 43 

how to convert one method to future method

I need to convert my method to future method . How to do that below is the code piece :-
global ID getDefaultEmailTemplateId() {
        
        String templateName = 'THA_Tmp_' + DateTime.now().getTime();
        System.debug('templateName=' + templateName);
        
        String emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_EN__c;
        if(UserInfo.getProfileId() == THA_Utils.getProfileIdByName('CCU Support') || UserInfo.getProfileId() == THA_Utils.getProfileIdByName('CCU Support Manager')) {
            if(caseLanguage == 'FR') {
                emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_CCU_Template__c;
            } else if(caseLanguage == 'NL') {
                emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_CCU_Template_NL__c;
            } else if(caseLanguage == 'DE') {
                emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_CCU_Template_DE__c;
            } else if(caseLanguage == 'EN') {
                emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_CCU_Template_EN__c;
            }
            
        } else if(caseSource == 'Izy') {
            if(caseLanguage == 'FR') {
                emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_Izy_FR__c;
            } else if(caseLanguage == 'NL') {
                emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_Izy_NL__c;
            } else {
                emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_Izy_EN__c;
            }
        } else {
            if(caseTTC == 'No') {
                if(caseLanguage == 'FR') {
                    emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_FR__c;
                } else if(caseLanguage == 'DE') {
                    emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_DE__c;
                } else if(caseLanguage == 'NL') {
                    emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_NL__c;
                }
            } else {
                if(caseLanguage == 'FR') {
                    emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_TTC_FR__c;
                } else if(caseLanguage == 'DE') {
                    emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_TTC_DE__c;
                } else if(caseLanguage == 'NL') {
                    emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_TTC_NL__c;
                } else if(caseLanguage == 'EN') {
                    emailTemplateId = THA_Thalys_Variables__c.getInstance().THA_Id_EmailTemplate_TTC_EN__c;
                }
            }
        }
        
        EmailTemplate source = [SELECT description, encoding, HtmlValue, subject, TemplateStyle, TemplateType, BrandTemplateId 
                                FROM EmailTemplate 
                                WHERE id = :emailTemplateId];
        
        EmailTemplate clone = source.clone();
        clone.developerName = templateName;
        clone.Name = templateName ; 
        
        clone.folderId=THA_Thalys_Variables__c.getInstance().THA_Id_TmpEmailTemplate_Folder__c;
        clone.IsActive=true;
        System.debug('STL : caseId: ' + caseId);
        if(new THA_TemplateGenerator_Cx(caseId).generateEmailTemplateText() != NULL ){
            clone.HtmlValue = clone.HtmlValue.replace('##dynamic_content##', new THA_TemplateGenerator_Cx(caseId).generateEmailTemplateText());
            //clone.HtmlValue += '</br><div>{!Case.THA_TECH_Ref_Email2Case__c}</div>';
            System.debug('SMARTLOADER TEMPLATE :' + clone.HtmlValue);
        } else {
            Case caseTmp = [SELECT THA_Case_Language__c, THA_Source__c 
                            FROM Case 
                            WHERE Id=:caseId];
        }
        
        Database.SaveResult res = Database.insert(clone);
        System.debug('EmailTemplate inserted in the getDefaultEmailTemplateId method : ' + res);
        
        //We delete the temporary email template as soon as it's used
        //futureDeleteTmpEmailTemplate(res.Id);
        
        return res.getId(); 
    }
and above method is passing as a perameter of another method,
like this .
sendEmailDefaults.setTemplateId(getDefaultEmailTemplateId())
how to convert this . Please help.