You need to sign in to do that
Don't have an account?
Jim_morrison
Even if you use another coding logic as below, It does not work. since it crosses the SOQL (governers limit) for leads
I bet there is a solution, that I am unable to use here.
Working with null rows of query results
I am unable to code easily, the following logic.
--> Query the batch of Leads to find if the campaign member already exists for them
---> If it does not exist, Create One.
The issue i see is that: The SOQL select in a for loop, returns only selected rows. If we want to work on those "not matched" I cannot utilize that result.
Ex1: (does not work)
Code:
for(campaign c : [select id from campaign where id in : leadIdList]){ if c[i].id == null) // Do some action such as create a campaign member record. i++; }
Even if you use another coding logic as below, It does not work. since it crosses the SOQL (governers limit) for leads
Ex2: (does notwork)
Code:
for(Lead ld: Trigger.new){ if([select count() from Campaign where id in: leadidList] <= 0){ //Do some action such as create a campaign member record and store in a list } } //Then insert all newly created campaign member records at once. insert xxxx;
I bet there is a solution, that I am unable to use here.
Thanks in advance.
Try instead (some pseudocode for you here because I'm too lazy to write the real code):
Message Edited by werewolf on 04-23-2008 02:38 PM
Message Edited by TehNrd on 04-23-2008 03:08 PM
TehNrd,
Thanks for writing up the code. But it did not work.I think it is just similar to what I have originally written.
The issue is while creating campaign members.
Let's say 2 out of 4 leadIDs matched, The memberList is 2. Neither we have then the specifics as to as which ids did not match (nor we have captured the null values in that list). Therefore the MemberList values are incorrect. Consequently the logic to create a Campaign Member just as leadID is null value is inadequate.
ppat,
I tried your approach already, which seemed correct(using count() <= 0 and using List.get(i) ) . But the issue is ('select count()' goes in a for loop, and the No of SOQL statements exceed in a trigger which is not acceptable.
Werewolf,
The psedocode is right, thanks. But I think it will be a more complicated than that.First -> The campaign member creation requires campaign ID(required field). In our leads, if there were a lead with campaign ID that did not match with existing ones, then we need to assign a 'unknown' campaign ID. Therfore we need to find if that is matched using another soql query that again must using "non-matching" technique, identify and change campaignID Names on stored in Map etc etc.
But, I think it should work. I will update if it does not.
Thanks Everyone..
I guess I just assumed you knew what campaign you wanted to put it in. But that should be easy -- why not just make one and only one immutable "Unknown" campaign? Then you could just store the ID specifically, or you can do a simple singleton SOQL search. If you do end up writing SOQL for it, don't do that campaign SOQL query inside the lead loop -- do it outside the loop, before you get into the leads at all.
a) I did not see why it is taking 2 DML when actually I am running one(one statement).
Message Edited by TehNrd on 04-24-2008 01:48 PM
Its an after trigger. that generally comes from multiple sources --web form probably has only 1 at a time. A feed that sends batches..(that I am not sure of the limit)...and their claim of a DB refresh that might trigger all(>5000).....
So, I am just trying to overcome the limits as much as possible.
So for your testing you only need to insert/update 200 leads, not 500.
Message Edited by TehNrd on 04-24-2008 02:04 PM
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_update.htm
(search for the word "Maximum")
I'm sure it's documented also on the page for insert too.