• sindhu suru
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
SOQL question : Here is what i am trying to do.

for (claim__c clm : shortlistedclaims){
Map<Date,Decimal> tad = new Map<Date,Decimal>();

AggregateResult[] groupedResults = [SELECT Begin_Date__c, SUM(Wages__c) FROM Wages__c where claim__c =: clm.id GROUP BY Begin_Date__c];

for (AggregateResult ar : groupedResults) {
tad.put((Date)ar.get('Begin_Date__c'),(Decimal)ar.get('expr0'));
}

ClaimtoMAP.put(clm.id,tad);
}

This works fine but leads to 'Too many SOQL statements' error since the query is inside the loop.

In general, Is it possible to populate Map<Id,Map<Date,Decimal>> in a single query? If not, any workaround to this problem?
When using setTemplateId with mass email, how to pass a record ID to the template to show all the merge fields. I have a mass email apex class and it does send the email but all the merge fields are blank. Please help.
SOQL question : Here is what i am trying to do.

for (claim__c clm : shortlistedclaims){
Map<Date,Decimal> tad = new Map<Date,Decimal>();

AggregateResult[] groupedResults = [SELECT Begin_Date__c, SUM(Wages__c) FROM Wages__c where claim__c =: clm.id GROUP BY Begin_Date__c];

for (AggregateResult ar : groupedResults) {
tad.put((Date)ar.get('Begin_Date__c'),(Decimal)ar.get('expr0'));
}

ClaimtoMAP.put(clm.id,tad);
}

This works fine but leads to 'Too many SOQL statements' error since the query is inside the loop.

In general, Is it possible to populate Map<Id,Map<Date,Decimal>> in a single query? If not, any workaround to this problem?

  Hello,everyone.I am new for the salesforce. Now i have a problem about sending email.

 

  I want to send outbound Emails to the clients if the status is update.However,i also create a personal HTML Email template.

 

  Now,the problem is,if i just send a text email that i write in the apex class,it runs well,i can receive the email.but if i use the email template,it always has a error .Please help me ,thank you very much!

 

 

 The code trigger:


trigger SendEmail on Opportunity (after update) {
String OldStatutPolice;
String NewStatutPolice;
Opportunity o=Trigger.New[0];
OldStatutPolice=trigger.old[0].Statut_Police__c;
NewStatutPolice=trigger.new[0].Statut_Police__c;


if((OldStatutPolice=='Proposition') && (NewStatutPolice=='Nouvelle Police (active)') )
{
NewPoliceSendEmail.SendEmail(o);
}
}

 

The code Apex Class:

 

public with sharing class NewPoliceSendEmail {


public static void SendEmail(Opportunity o)
{
      
 
if(o.Statut_Police__c=='Nouvelle Police (active)'){
    
    
    Opportunity OppAcc = [select Accountid from Opportunity where id = :o.id];
          
     Contact contact = [select Email from Contact where Accountid = :OppAcc.AccountId and Destinataire__c='Oui'];
    EmailTemplate et = [SELECT Id FROM EmailTemplate WHERE DeveloperName='Mail_Remerciement'];
 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 
                        mail.setTargetObjectId(contact.id);

                       mail.setBccSender(false);
                       mail.setSenderDisplayName('xxxxxx@xxxxxxl.com');
                       mail.setSubject('Merci');    
                       mail.setTemplateId(et.Id);
                       Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}

 

  The error is INVALID_FIELD_WHEN_USING_TEMPLATE, When a template is specified the plain text body, html body, subject and charset may not be specified : []:

  • June 13, 2012
  • Like
  • 0