I have a button in LWC component when i click the button LWC form will open when we filled and submit the form Email has to send but email is send sucessfully in debug logs but email is not receving. i checked all the junk folder also but not receiving
@AuraEnabled(cacheable=true)
public static string sendEmail(String AccountName,String AccountPhone,String AccountAddress,String AccountCity,String AccountState,String AccountZip,String ServiceDelivery,String ServiceNeeded,String AdditionalComments,String RequestedBy,String ServiceDate,String LocationofParts,String CurrentDate,String userName,string threadid,Id caseId){
String marketEmail=”;
Case caseData = [Select Id, Legacy_Account_Ship_To__c from Case where Id=: caseId LIMIT 1];
System.debug(‘legacy is ‘+caseData);
if(caseData != null && caseData.Legacy_Account_Ship_To__c != null){
list < Market_Configuration__mdt > marketConfigList = [SELECT Id, MasterLabel, DeveloperName,Fulfiller_Id__c,Service_Delivery_Distro__c FROM Market_Configuration__mdt where Fulfiller_Id__c=:caseData.Legacy_Account_Ship_To__c and MasterLabel !=’ASHCOMM’ and MasterLabel !=’Blank’];
if(!marketConfigList.isEmpty()){
marketEmail = marketConfigList[0].Service_Delivery_Distro__c;
System.debug(‘Service Delivery Distro: ‘ + marketConfigList[0].Service_Delivery_Distro__c);
}
}
List<String> recordIdList = ServiceDelivery.split(',');
List<ProductLineItem__c> productLineItems = [SELECT Item_SKU__c,Sales_Order_Number__c FROM ProductLineItem__c WHERE Id IN :recordIdList];
System.debug('the product line items are '+productLineItems);
System.debug('ServiceNeeded '+ ServiceNeeded );
System.debug('AdditionalComments '+ AdditionalComments);
System.debug('RequestedBy ' + RequestedBy);
System.debug('ServiceDate ' + ServiceDate );
System.debug('LocationofParts ' + LocationofParts);
System.debug('CurrentDate ' + CurrentDate);
System.debug('userName ' + userName);
String productLineItemsHTML = '';
for(ProductLineItem__c item : productLineItems) {
productLineItemsHTML += '<tr>' +
'<td style="text-align: center;">' + item.Item_SKU__c + '</td>' +
'<td style="text-align: center;">' + item.Sales_Order_Number__c + '</td>' +
'</tr>';
}
String messageBody =
‘Service Delivery’ +
” +
‘ .highlighted-heading { font-size: 24px; font-weight: bold; background-color: #ffbf00;text-align: center;}’ +
‘ .mytable, .mytable1 { width: 100%; }’ +
‘ .mytable th, .mytable td, .mytable1 th, .mytable1 td {padding: 5px; }’ +
‘ .thead { background-color: #f2f2f2; }’ +
‘ .checkbox-cell { display: flex; align-items: center; }’ +
‘ .small-checkbox { margin-right: 8px; }’ +
‘ .from { font-weight: bold; background-color: #ffbf00;}’ +
” +
” +
‘ ‘ +
‘ ‘ +
‘ Service Delivery’ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ From:’ +
‘ Brandon Warehouse’ +
‘ Customer’s Name:’ +
‘ ‘ + AccountNameWithCommas + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ 2998 Broadway Center Blvd’ +
‘ Address:’ +
‘ ‘ + AccountAddress + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Brandon, FL 33510’ +
‘ ‘ +
‘ ‘ + AccountCity + ‘, ‘ + AccountState + ‘ ‘ + AccountZip + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Phone Number:’ +
‘ ‘ + AccountPhone + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Item Number’ +
‘ Sale Order’ +
‘ ‘ +
productLineItemsHTML +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Service Needed’ +
‘ Additional Comments’ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ + ServiceNeeded + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ + AdditionalComments + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ Requested By:’ +
‘ ‘ + userName + ” +
‘ Date:’ +
‘ ‘ + currentDate + ” +
‘ ‘ +
‘ ‘ +
‘ Service Date:’ +
‘ ‘ + ServiceDate + ” +
‘ Location of parts:’ +
‘ ‘ + LocationofParts + ” +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
‘ ‘ +
” + threadid + ”+
” +
”;
if(marketEmail == ''){
return 'No market email found for the given case.';
}
/*Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] {marketEmail};
message.subject = 'Service Delivery Request';
message.HtmlBody = messageBody;
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);*/
OrgWideEmailAddress owea = new OrgWideEmailAddress();
try {
owea = [SELECT Id,DisplayName FROM OrgWideEmailAddress Where DisplayName = '**************'];
} catch(Exception e) {
}
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] {marketEmail};
message.subject = ' Service Delivery Request';
message.HtmlBody = messageBody;
message.setSaveAsActivity(true);
message.setWhatId(caseId);
if(owea != null){
System.debug('owea is not null');
message.setOrgWideEmailAddressId(owea.Id);
}
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
String messageOutput;
String emailAddress = message.toAddresses != null && message.toAddresses.size() > 0 ? message.toAddresses[0] : 'unknown';
System.debug(emailAddress);
for(Messaging.SendEmailResult res:results){
if(res.isSuccess()){
messageOutput = 'Email sent successfully';
System.debug('Email sent successfully '+emailAddress);
return messageOutput;
}else{
messageOutput = 'Email Sent Failed';
System.debug('Email Sent Failed');
return messageOutput + '. Market Email: ' + marketEmail;
}
}
return 'Unknown error';
}
Deena Vicky is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.