You need to sign in to do that
Don't have an account?
hgeorge
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
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
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()];
hi george,
You have to update your SOQL query with below.
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
Thanks everyone,
But unfortunately none of the method suggeted is not working can you please help..
Thanks,
George
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
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
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