You need to sign in to do that
Don't have an account?

sending more than 10 emails
Hello All,
I 'd an issue regarding sending emails using singleemailmessage class. I am trying to send ONLY selected properties over mail.
If property is not available (Status:Sold) --> Then show error message.
Can anyone can help me!
Thank you.
public void sendRecomProp() {
if ( !lRecomProperties.IsEmpty() ) {
newTemplate = new EmailTemplate();
newTemplate = [SELECT Id,Name,IsActive,Subject,Body,HtmlValue,Folder.Name
FROM EmailTemplate
WHERE (Name LIKE '%RecomProperties%') LIMIT 1];
if ( newTemplate!=null ) {
String urlDestino = '';
String templateSubject = 'KC Properties - Recommended properties';
String templateBody = newTemplate.HtmlValue;
templateBody = templateBody.Replace('{!Contact.Name}',( actualContact.Name!=null ) ? actualContact.Name : 'User');
templateBody = templateBody +
'<br/>' + '<br/>' +
'<table style="width: 100%; border-spacing: 0px; border-color: red transparent;">';
String priceFinal = '';
for ( Property__c proppe :lPropiedades ) {
templateBody = templateBody +
'<tr>' +
'<td style="padding: 5px; width: 100px;">' +
'<img width="250" height="150" src="' + ( proppe.FirstReferenceImage__c!=null ? String.ValueOf(proppe.FirstReferenceImage__c) : Label.NoImage ) + '"/>' +
'</td>';
priceFinal = ( contactRole=='Renter' ) ?
( proppe.PriceToRentEUR__c!=null ? String.ValueOf(proppe.PriceToRentEUR__c) : 'Undefined') :
( proppe.PriceToSaleEUR__c!=null ? String.ValueOf(proppe.PriceToSaleEUR__c) : 'Undefined' );
templateBody = templateBody +
'<td style="padding: 5px;">' +
'<b>- Property ID: </b>' +
'<a href="' + ( proppe.WebReference__c!=null ? String.ValueOf(proppe.WebReference__c) : 'www.kcproperties.com' ) + '">' +
proppe.Name +
'</a>' + '<br/>' +
'<b>- Price: </b>' + priceFinal + '<br/>' +
'<b>- Area: </b>' + ( proppe.Area__c!=null ? String.ValueOf(proppe.Area__c) : 'Undefined' ) + '<br/>' +
'<b>- Address: </b>' + ( proppe.Address__c!=null ? String.ValueOf(proppe.Address__c) : 'Undefined' ) + '<br/>' +
'<b>- Details: </b>' + ( proppe.Beds__c!=null ? String.ValueOf(proppe.Beds__c) : 'Undefined' ) + '<br/>' +
'<b>- Baths: </b>' + ( proppe.Baths__c!=null ? String.ValueOf(proppe.Baths__c) : 'Undefined' ) + '<br/>' +
'<b>- Build area (m2): </b>' + ( proppe.BuildArea__c!=null ? String.ValueOf(proppe.BuildArea__c) : 'Undefined' ) + '<br/>' +
'</td>' +
'</tr>';
}
templateBody = templateBody +
'</table>' + '<br/>' +
'You can visit any property via the link on the Property ID value.' + '<br/>' + '<br/>' +
'Best regards.' + '<br/>' +
'KC Properties team';
String[] addressesList = new String[]{actualContact.Email};
OrgWideEmailAddress[] lOrgAddresses = new OrgWideEmailAddress[]{};
lOrgAddresses = [SELECT Id
FROM OrgWideEmailAddress
WHERE (Address LIKE '%kcpropertiesestateagent%') LIMIT 1];
Messaging.SingleEmailMessage emailToSend = new Messaging.SingleEmailMessage();
emailToSend.SetSubject(templateSubject);
emailToSend.SetOrgWideEmailAddressId( !lOrgAddresses.IsEmpty() ? lOrgAddresses[0].Id : null );
emailToSend.SetToAddresses(addressesList);
emailToSend.SetHtmlBody(templateBody);
try {
if ( !Test.IsRunningTest() && !lOrgAddresses.IsEmpty() ) {
Messaging.SendEmailResult[] resultToSend = Messaging.SendEmail(new Messaging.SingleEmailMessage[]{emailToSend});
smsMailingResult = 'The mailing has been completed successfully. '+
'<a href="/' + actualContact.Id + '" style="color: blue; font-size: 100% !important;">'+
'Click here to return to the contact detail'+
'</a>';
ApexPages.Addmessage(new ApexPages.Message(ApexPages.severity.CONFIRM,smsMailingResult));
}
} catch (Exception error) {
smsMailingResult = 'An error has occurred, please try again later or contact your administrator. '+
'<a href="/' + actualContact.Id + '" style="color:blue;font-size:100% !important;">'+
'Click here to return to the contact detail'+
'</a>';
ApexPages.Addmessage(new ApexPages.Message(ApexPages.severity.ERROR,smsMailingResult));
smsMailingResult = '';
AUX_Methods.log(Label.ErrorSendingEmail+' - Send Email - '+error.GetMessage());
}
}
}
}
I 'd an issue regarding sending emails using singleemailmessage class. I am trying to send ONLY selected properties over mail.
If property is not available (Status:Sold) --> Then show error message.
Can anyone can help me!
Thank you.
public void sendRecomProp() {
if ( !lRecomProperties.IsEmpty() ) {
newTemplate = new EmailTemplate();
newTemplate = [SELECT Id,Name,IsActive,Subject,Body,HtmlValue,Folder.Name
FROM EmailTemplate
WHERE (Name LIKE '%RecomProperties%') LIMIT 1];
if ( newTemplate!=null ) {
String urlDestino = '';
String templateSubject = 'KC Properties - Recommended properties';
String templateBody = newTemplate.HtmlValue;
templateBody = templateBody.Replace('{!Contact.Name}',( actualContact.Name!=null ) ? actualContact.Name : 'User');
templateBody = templateBody +
'<br/>' + '<br/>' +
'<table style="width: 100%; border-spacing: 0px; border-color: red transparent;">';
String priceFinal = '';
for ( Property__c proppe :lPropiedades ) {
templateBody = templateBody +
'<tr>' +
'<td style="padding: 5px; width: 100px;">' +
'<img width="250" height="150" src="' + ( proppe.FirstReferenceImage__c!=null ? String.ValueOf(proppe.FirstReferenceImage__c) : Label.NoImage ) + '"/>' +
'</td>';
priceFinal = ( contactRole=='Renter' ) ?
( proppe.PriceToRentEUR__c!=null ? String.ValueOf(proppe.PriceToRentEUR__c) : 'Undefined') :
( proppe.PriceToSaleEUR__c!=null ? String.ValueOf(proppe.PriceToSaleEUR__c) : 'Undefined' );
templateBody = templateBody +
'<td style="padding: 5px;">' +
'<b>- Property ID: </b>' +
'<a href="' + ( proppe.WebReference__c!=null ? String.ValueOf(proppe.WebReference__c) : 'www.kcproperties.com' ) + '">' +
proppe.Name +
'</a>' + '<br/>' +
'<b>- Price: </b>' + priceFinal + '<br/>' +
'<b>- Area: </b>' + ( proppe.Area__c!=null ? String.ValueOf(proppe.Area__c) : 'Undefined' ) + '<br/>' +
'<b>- Address: </b>' + ( proppe.Address__c!=null ? String.ValueOf(proppe.Address__c) : 'Undefined' ) + '<br/>' +
'<b>- Details: </b>' + ( proppe.Beds__c!=null ? String.ValueOf(proppe.Beds__c) : 'Undefined' ) + '<br/>' +
'<b>- Baths: </b>' + ( proppe.Baths__c!=null ? String.ValueOf(proppe.Baths__c) : 'Undefined' ) + '<br/>' +
'<b>- Build area (m2): </b>' + ( proppe.BuildArea__c!=null ? String.ValueOf(proppe.BuildArea__c) : 'Undefined' ) + '<br/>' +
'</td>' +
'</tr>';
}
templateBody = templateBody +
'</table>' + '<br/>' +
'You can visit any property via the link on the Property ID value.' + '<br/>' + '<br/>' +
'Best regards.' + '<br/>' +
'KC Properties team';
String[] addressesList = new String[]{actualContact.Email};
OrgWideEmailAddress[] lOrgAddresses = new OrgWideEmailAddress[]{};
lOrgAddresses = [SELECT Id
FROM OrgWideEmailAddress
WHERE (Address LIKE '%kcpropertiesestateagent%') LIMIT 1];
Messaging.SingleEmailMessage emailToSend = new Messaging.SingleEmailMessage();
emailToSend.SetSubject(templateSubject);
emailToSend.SetOrgWideEmailAddressId( !lOrgAddresses.IsEmpty() ? lOrgAddresses[0].Id : null );
emailToSend.SetToAddresses(addressesList);
emailToSend.SetHtmlBody(templateBody);
try {
if ( !Test.IsRunningTest() && !lOrgAddresses.IsEmpty() ) {
Messaging.SendEmailResult[] resultToSend = Messaging.SendEmail(new Messaging.SingleEmailMessage[]{emailToSend});
smsMailingResult = 'The mailing has been completed successfully. '+
'<a href="/' + actualContact.Id + '" style="color: blue; font-size: 100% !important;">'+
'Click here to return to the contact detail'+
'</a>';
ApexPages.Addmessage(new ApexPages.Message(ApexPages.severity.CONFIRM,smsMailingResult));
}
} catch (Exception error) {
smsMailingResult = 'An error has occurred, please try again later or contact your administrator. '+
'<a href="/' + actualContact.Id + '" style="color:blue;font-size:100% !important;">'+
'Click here to return to the contact detail'+
'</a>';
ApexPages.Addmessage(new ApexPages.Message(ApexPages.severity.ERROR,smsMailingResult));
smsMailingResult = '';
AUX_Methods.log(Label.ErrorSendingEmail+' - Send Email - '+error.GetMessage());
}
}
}
}
//now do your loop ....
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(emailsLeads);
String subject='GoToMeeting Invitation Details for '+subject;
String body='test'; mail.setHtmlBody(body);
mail.setSubject(subject); allMails.add(mail); ....
}
//Finished your loop? Now you have an array of mails to send.
//This uses 1 of your 10 calls to sendEmail that you are allowed
Messaging.sendEmail(allMails);