• Paul87
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi all,
i'm trying to build this solution (if it has sense).
Scenario: generate a default Mail for quote on Case Feed using web service SOAP and Classic Email Template.
I already have the web service and a classic email template, but i don't know how handle the soap response to generate the mail with data obtained.

Callout Method to external service
public void callQuoteService(Datetime dateFrom, Datetime dateTo, String npaxString, String tipoRisorsa, String extraString, String idLingua, String campingCode){

		String body = generateRequestBody(dateFrom, dateTo, npaxString, tipoRisorsa, extraString, idLingua);

		//Note: it is not possible to use the standard WSDL2APEX generator because the WSDL from SGS contains s:any blocks,
		//whìch are not supported
		HttpRequest soapRequest = this.createSoapRequest(campingCode,body);
 		Http http = new Http();
		HTTPResponse res = http.send(soapRequest);

		if (res.getStatusCode()==200){
			Trattamento result = TrattamentoXmlParser.parser(res.getBody());
			System.debug(result);
		}
}
 
global class JK_AutomaticCaseMail implements QuickAction.QuickActionDefaultsHandler {
    
    Case currentCase = new Case();

    // Constructor
    public JK_AutomaticCaseMail() {
        SERVICE_GenerateQuote requestData = new SERVICE_GenerateQuote();
        
        currentCase = [SELECT CaseNumber, data_di_partenza__c, data_di_arrivo__c, Tipologia_Richiesta__c, Campeggio__r.IdSGS__c FROM Case WHERE Id=:sendEmailDefault.getContextId()];
        Date dateFrom      = currentCase.data_di_partenza__c;
        Date dateTo        = currentCase.data_di_arrivo__c;
        // npax
        String tipoRisorsa = currentCase.Tipologia_Richiesta__c;
        // extraString
        // idLingua
        String campingCode = current.Case.Campeggio__r.IdSGS__c;


        requestData.callQuoteService(dateFrom, dateTo, npaxString, tipoRisorsa, extraString, idLingua, campingCode);

        /** i don't know how to handle the response after callQuoteService. **/
    }

    // Init mail template 
    global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
        QuickAction.SendEmailQuickActionDefaults sendEmailDefault = (QuickAction.SendEmailQuickActionDefaults)defaults.get(0);

        EmailTemplate em = [Select Id,HtmlValue from EmailTemplate where name ='JK_Template_MailToCustomer'];

        if (sendEmailDefaults != null && currentCase.CaseNumber != null) {

            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();
            emailMessage.BccAddress = c.ContactEmail;


            if (sendEmailDefault.getInReplyToId() == null) {
                Integer emailCount = [SELECT count() FROM EmailMessage 
                                      WHERE ParentId=:sendEmailDefaults.getContextId()];
                if (emailCount!= null && emailCount > 0) {
                    sendEmailDefault.setTemplateId(
                        getTemplateIdHelper('Automatic_Response'));
                } else {
                    sendEmailDefault.setTemplateId(
                        getTemplateIdHelper('New_Case_Created'));
                }
                sendEmailDefault.setInsertTemplateBody(false);
                sendEmailDefault.setIgnoreTemplateSubject(false);
            } else {
                sendEmailDefault.setTemplateId(
                    getTemplateIdHelper('Default_reply_template'));
                sendEmailDefault.setInsertTemplateBody(false);
                sendEmailDefault.setIgnoreTemplateSubject(true);
            }
        }
    }  
}

Bye,
Paolo.​​​​​​​
  • December 19, 2019
  • Like
  • 0
Hi,

I'm stucked on Service Cloud Specialist step 6. It shows the error message:

Challenge Not yet complete... here's what's wrong: 
We can't find the Recipient field in the email template. Ensure the Cloudy Weather Email Template addresses the Recipient of the email.
Close errors

However, my email template called Cloudy weather (Text format) has the following body:

Hey {!Contact.FirstName}, Sorry to hear that your panels aren't generating the power you hoped for. Based on our research, it appears the low power produced is related to the cloudy weather in your area recently. In the worst conditions, Ursa Major panels produce ~25% of maximum power. If you have additional questions, please give us a call and reference case {!Case.CaseNumber}. Thanks! {!User.Name}, Ursa Major Solar

Any ideas?

Regards