function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rajibnandirajibnandi 

how to Trigger an email when IDEA is promoted to 30 points

Can any one tell me how to Trigger an email when IDEA is promoted to 30 points?

vanessenvanessen

your problem is that you do not know how to send email in trigger or how to know when IDEA is promoted to 30 pts|???

rajibnandirajibnandi

thanks for your reply...i know how to send an email by trigger ....i want to know if my idea is promoted to 30 points ,i want to get a mail stating tat my idea has promoted to 30 points..can you plz help me with this?

Imran MohammedImran Mohammed

Can you tell which sobject is used to track the IDEA details?

rajibnandirajibnandi

i have used "votecount"....below is my code..am not sure it works fine

 

 

trigger promote on Idea (before insert,before update) {
list <Idea> vote1= new List<Idea>();
Map<Id,Decimal> accConMap= new Map<Id,Decimal>();
for (Idea pro:Trigger.new){
accConMap.put(pro.id, pro.votetotal);
}
system.debug(accConMap);
vote1= [select id, votetotal from idea where id in: accConMap.keyset()];
for(Integer i=0;i < vote1.size();i++){
if(vote1[i].votetotal >= 10){
system.debug(vote1[i]);
system.debug(vote1[i].votetotal);

Imran MohammedImran Mohammed

 

 

trigger promote on Idea (before insert,before update) {
list <Idea> vote1= new List<Idea>();
Map<Id,Decimal> accConMap= new Map<Id,Decimal>();

List<Messaging.SingleEmailMessage> mailList = new List<Messaging.SingleEmailMessage>();


for (Idea pro:Trigger.new){

 if(pro.votetotal >= 30)

 {

 //add your email code here

 

            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
            // Strings to hold the email addresses to which you are sending the email.
            String[] toAddresses = new String[] {Add Email of the User to whom email should be sent}; 
          
            mail.setToAddresses(toAddresses);
          
            mail.setSenderDisplayName(UserInfo.getName());//if required change
        
            mail.setSubject(''Add your subject here'');
        
            mail.setUseSignature(false);
            
            mail.setPlainTextBody(''Add content here'');
        
            mail.setHtmlBody('Add content here');
 mailList.add(mail);
 }

 


 accConMap.put(pro.id, pro.votetotal); //Check whether you still need this line
}
if(mailList.size() > 0)

{

Messaging.sendEmail(mailList);

}

 

Let me know if you were looking at something like this or if you have any questions.

rajibnandirajibnandi

i have tried testing with the above code which you have gave..but once my idea is promoted my idea to 30 points am not geting any mail...i have added the mail id too...

 

 

String[] toAddresses = new String[] {'.....@yahoo.com'}; 

rajibnandirajibnandi

i am getting the mail when new idea is posted but why am not geting the mail when the idea has promoted to 30 points?

Imran MohammedImran Mohammed

Instead of before update, use after update event in trigger and see.

rajibnandirajibnandi

i am geting the same error again...

Imran MohammedImran Mohammed

If you are getting any error message, can you post that along with the code and highlight the error line ?

rajibnandirajibnandi

i am not getting any error message but once i promote my idea to 30 points i am not geting any mail...my requirement is that once the idea is promoted to 30 points i should get a mail..

rajibnandirajibnandi

Here is the code which i have written before:

 

 

trigger promote on Idea (before insert,before update) {
list <Idea> vote1= new List<Idea>();
Map<Id,Decimal> accConMap= new Map<Id,Decimal>();
for (Idea pro:Trigger.new){
accConMap.put(pro.id, pro.votetotal);
}
system.debug(accConMap);
vote1= [select id, votetotal from idea where id in: accConMap.keyset()];
for(Integer i=0;i < vote1.size();i++){
if(vote1[i].votetotal >= 20){
system.debug(vote1[i]);
system.debug(vote1[i].votetotal);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'my mail id'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('my mail id');
mail.setSenderDisplayName('Idea Support');
mail.setSubject('message : ');
mail.setPlainTextBody('message');
mail.setHtmlBody('message');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}

Imran MohammedImran Mohammed

Is it printing the debug statements that are inside the if condition.

Is Votetotal of Decimal type?

what you do is update the if statement 

if(Votetotal >= Decimal.valueof(20))

 

rajibnandirajibnandi

no its not printing ....i guess i went wrong some where in the code...plz help me with this issue..

rajibnandirajibnandi

sobject type is "idea"

rajibnandirajibnandi

when i am posting any new idea i am getting the below log

 

 

20.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO
21:26:45.182|CODE_UNIT_STARTED|[EXTERNAL]|01q90000000U1zt|promote on Idea trigger event BeforeInsert for [new]
21:26:45.183|METHOD_ENTRY|[5]|MAP.put(ANY, ANY)
21:26:45.184|METHOD_EXIT|[5]|MAP.put(ANY, ANY)
21:26:45.184|METHOD_ENTRY|[7]|System.debug(ANY)
21:26:45.184|USER_DEBUG|[7]|DEBUG|{null=null}
21:26:45.184|METHOD_EXIT|[7]|System.debug(ANY)
21:26:45.184|SOQL_EXECUTE_BEGIN|[8]|Aggregations:0|select id, votetotal from idea where id in: accConMap.keyset()
21:26:45.185|METHOD_ENTRY|[8]|MAP.keySet()
21:26:45.185|METHOD_EXIT|[8]|MAP.keySet()
21:26:45.187|SOQL_EXECUTE_END|[8]|Rows:0
21:26:45.188|METHOD_ENTRY|[9]|LIST.size()
21:26:45.188|METHOD_EXIT|[9]|LIST.size()
21:26:45.188|CUMULATIVE_LIMIT_USAGE
21:26:45.188|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 0 out of 10000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 100
  Number of DML rows: 0 out of 10000
  Number of script statements: 7 out of 200000
  Maximum heap size: 0 out of 3000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10
  Number of find similar calls: 0 out of 10
  Number of System.runAs() invocations: 0 out of 20

21:26:45.188|CUMULATIVE_LIMIT_USAGE_END

21:26:45.188|CODE_UNIT_FINISHED|promote on Idea trigger event BeforeInsert for [new]
21:26:45.270|CUMULATIVE_LIMIT_USAGE
21:26:45.270|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 0 out of 10000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 100
  Number of DML rows: 0 out of 10000
  Number of script statements: 7 out of 200000
  Maximum heap size: 0 out of 3000000
  Number of callouts: 0 out of 10
  Number of Email Invocations: 0 out of 10
  Number of fields describes: 0 out of 100
  Number of record type describes: 0 out of 100
  Number of child relationships describes: 0 out of 100
  Number of picklist describes: 0 out of 100
  Number of future calls: 0 out of 10
  Number of find similar calls: 0 out of 10
  Number of System.runAs() invocations: 0 out of 20

21:26:45.270|CUMULATIVE_LIMIT_USAGE_END

Imran MohammedImran Mohammed

As per the debug logs Trigger.new does not hold any IDEA records.

Can you check whether it is atleast printing the values when the record is inserted initially?

rajibnandirajibnandi

Hi Imran,

As per my code i am able to track votetotal and idea id in debug log and i am getting mail if i edit or comment on idea which has 30points on it....but my question is cant i get mail once i promote the idea to 30 points?

vanessenvanessen

maybe you will have to use trigger.new and trigger.old,then check if the old value was not 30 pts and if the new value is 30 pts ,then send the mail.