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
hgeorgehgeorge 

Trigger to update New Lead count

Hi There,

 


Can any one please tell me where Iam going wrong in this trigger?

 

 

trigger calculateNewLeads on Campaign (before update) {
    
    List<Lead> leads=[SELECT Id, lead_source_details__c FROM Lead WHERE lead_source_details__c IN :Trigger.new];
    
    for (Campaign c : Trigger.new) {
        c.trigger_new_field__c=leads.size();
    }
    
    
}

 

Followintg is the error message - Error: Compile Error: Invalid bind expression type of SOBJECT:Campaign for column of type String at line 3 column 100.

 

Request all to kindly help.

 

Thanks,

George

souvik9086souvik9086

Is this lead_source_details__c field is a look up field to Campaign?

You can do one thing

 

List<ID> ids = new List<Id>();

for(Campaign cam : Trigger.new){

ids.add(cam.id);

}

List<Lead> leads=[SELECT Id, lead_source_details__c FROM Lead WHERE lead_source_details__c IN :ids];

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Rahul_sgRahul_sg

use Trigger.new.keyset() in your query

 

List<Lead> leads=[SELECT Id, lead_source_details__c FROM Lead WHERE lead_source_details__c IN :Trigger.new.keyset()];
    

hitesh90hitesh90

hi george,

 

You have to update your SOQL query with below.

 

List<Lead> leads=[SELECT Id, lead_source_details__c FROM Lead WHERE lead_source_details__c IN :Trigger.newmap.keyset()];

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

hgeorgehgeorge

Thanks everyone,

 

But unfortunately none of the method suggeted is not working can you please help..

 

Thanks,

George

souvik9086souvik9086

The above post of mine didn't worked?

 

Can you please tell me Is this lead_source_details__c field is a look up field to Campaign?

 

Thanks

hgeorgehgeorge

yes it is a look feild... Iam able to save the trigger but, the whole trigger which was was supposed to update new leads for campaign is not working ...

 

Thanks,

George

Rishi kaliaRishi kalia

Hi George,

 

I tried following trigger and it worked absolutely fine for me . In last reply you mention this trigger is suppose to update new lead records but actually this trigger is updating "trigger_new_field__c" field in campaign object .

 

Code : 

 

trigger calculateNewLeads on Campaign (before update) {

List<Lead> leads=[SELECT Id, lead_source_details__c FROM Lead WHERE lead_source_details__c IN :Trigger.newmap.keyset()];

for (Campaign c : Trigger.new) {
c.trigger_new_field__c=string.valueof(leads.size());
}}

 

Please comfirm your requirement..

 

Regards

Rishi kalia