• Elsa Cordonnier
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 4
    Replies
Hello, 
I try to write a trigger which count the number of Custom Object (Naterbox Call) linked to a Lead. 

I dont have any error in the code, but I don't have results neither. 
Can someone help me ?

Best
Elsa

trigger NatterboxUpdateLead on Natterbox_Call_Reporting_Object__c (after delete, after insert, after undelete, after update) {

Set<ID> LeadIds = new Set<ID>();

//We only care about tasks linked to Leads.

String leadPrefix = Lead.SObjectType.getDescribe().getKeyPrefix();

//Add any Lead ids coming from the new data

if(trigger.new!=null){
    for (Natterbox Call Reporting Object, t : Trigger.new) {
     if (t.WhoId!= null && string.valueof(t.WhoId).startsWith(leadPrefix) ) {

if(!LeadIds.contains(t.WhoId)){
//adding unique lead ids since there can be many tasks with single lead
LeadIds.add(t.WhoId);
}
}
      }
}
 
//Also add any Lead ids coming from the old data (deletes, moving an activity from one Lead to another)

if(trigger.old!=null){
    for (Natterbox Call Reporting Object t2 : Trigger.old) {
     if (t2.WhoId!= null && string.valueof(t2.WhoId).startsWith(leadPrefix) )
         {
if(!LeadIds.contains(t2.WhoId)){
//adding unique lead ids since there can be many tasks with single lead
LeadIds.add(t2.WhoId);
}
}
      }
}

     if (LeadIds.size() > 0){



List<Lead> leadsWithNatterbox Call Reporting Objects = [select id,Natterbox_activity_Count__c,(select id from Natterbox Call Reporting Objects) from Lead where Id IN : Leadids];

List<Lead> leadsUpdatable = new List<Lead>();

for(Lead L : leadsWithNatterbox Call Reporting Objects){

L.Activity_Count__c = L.Natterbox Call Reporting Objects.size();
leadsUpdatable.add(L);

}

if(leadsUpdatable.size()>0){

update leadsUpdatable;
//update all the leads with activity count

}

    }
}
Hello everyone, 

I'm looking to create a trigger on a Lead level to count how many custom object are associated to this Lead. The lead and the custom object(Box) are associate through a lookup filed in the Box object.
I create a custom filed call Count__c to collect the result. 

I get inspiration from a trigger which count the number of tasks assiciate to a Lead but this doesn't work. 
Can you provide me advise ? 

Thank you 
Best
Elsa


 
Hello hello,

I want to know if it's possible to create a trigger which will do the following step:
- Every time that a new lead is created, the trigger need to analyse the entire system to see iff there is already the same lead present in the data base according to two data keys (email address and phone number).
- If a same lead is found, the neew lead has to take Lead Status = "Doublette", then I will set up an automatic email alert to warn our provider that the lead is already existing

Any help is welcomed :)
Thanks a lot for your support

Best
Elsa
 
Hello, 
I need help and advise to build a smal trigger on a Custom Object to push some information on the Opportunity, the mentionned object don't have any Master relationship with the Opportunity. 

My Object is called: Consumer_Order__c
I need to push the information only if the order_type__c (Picklist) is "Compensation Credit"

My aim, is to push in the Opportunity 2 information when the Object is created.
- First the Net_Price__c (Currency)
- Second the Compensation_credit_reasons__c (Picklist)

The two fields I have to update in the Opportunity are: 
- Consumer_Compensation_credit__c (Currency)
- Consumer_Compensation_credit_reasons__c (Text)

Can you help me building this simple Trigger ? 
Thank you in advance
Hello, 
I try to write a trigger which count the number of Custom Object (Naterbox Call) linked to a Lead. 

I dont have any error in the code, but I don't have results neither. 
Can someone help me ?

Best
Elsa

trigger NatterboxUpdateLead on Natterbox_Call_Reporting_Object__c (after delete, after insert, after undelete, after update) {

Set<ID> LeadIds = new Set<ID>();

//We only care about tasks linked to Leads.

String leadPrefix = Lead.SObjectType.getDescribe().getKeyPrefix();

//Add any Lead ids coming from the new data

if(trigger.new!=null){
    for (Natterbox Call Reporting Object, t : Trigger.new) {
     if (t.WhoId!= null && string.valueof(t.WhoId).startsWith(leadPrefix) ) {

if(!LeadIds.contains(t.WhoId)){
//adding unique lead ids since there can be many tasks with single lead
LeadIds.add(t.WhoId);
}
}
      }
}
 
//Also add any Lead ids coming from the old data (deletes, moving an activity from one Lead to another)

if(trigger.old!=null){
    for (Natterbox Call Reporting Object t2 : Trigger.old) {
     if (t2.WhoId!= null && string.valueof(t2.WhoId).startsWith(leadPrefix) )
         {
if(!LeadIds.contains(t2.WhoId)){
//adding unique lead ids since there can be many tasks with single lead
LeadIds.add(t2.WhoId);
}
}
      }
}

     if (LeadIds.size() > 0){



List<Lead> leadsWithNatterbox Call Reporting Objects = [select id,Natterbox_activity_Count__c,(select id from Natterbox Call Reporting Objects) from Lead where Id IN : Leadids];

List<Lead> leadsUpdatable = new List<Lead>();

for(Lead L : leadsWithNatterbox Call Reporting Objects){

L.Activity_Count__c = L.Natterbox Call Reporting Objects.size();
leadsUpdatable.add(L);

}

if(leadsUpdatable.size()>0){

update leadsUpdatable;
//update all the leads with activity count

}

    }
}
Hello everyone, 

I'm looking to create a trigger on a Lead level to count how many custom object are associated to this Lead. The lead and the custom object(Box) are associate through a lookup filed in the Box object.
I create a custom filed call Count__c to collect the result. 

I get inspiration from a trigger which count the number of tasks assiciate to a Lead but this doesn't work. 
Can you provide me advise ? 

Thank you 
Best
Elsa