You need to sign in to do that
Don't have an account?

Trigger to match value against custom object.
Hi, I desperatly need some help creating my first trigger and i'm a bit lost.
I'm trying to create a trigger on a custom object called wp_leads__c which looks up a field called code_entered__c against another custom object called wp_cid__c on a field called coupon__c.
If wp_leads__c. code_entered__c = wp_cid__c.coupon__c I want to update a tickbox field called matched_code__c in the wp_leads__c object with a tick.
Please help!
Couple of questions before i can suggest something:
1) What is the realtionship between wp_leads__c object and wp_cid__c (Is there any direct relationship??)
2) If there is no direct relationship, on what condition do you wanna check whether the code entered on WP LEAD is matching against WP CID obejct??
Your answer will help guiding you in right direction.
Thanks,
Balaji
Thanks so much for getting back to me.
Theres no master-child relationship or lookup relationship between the two objects. What I want to do is tick a box called matched_code__c in the wp_leads__c if:
wp_leads__c. code_entered__c = wp_cid__c.coupon__c
Your help is very much appreciated!
Ben
@Ben.,
If there is no direct relation between those two objects,
wp_leads__c and wp_cid__c are two different objects, to compare the code_entered__c field on wp_leads__c record, we need to query wp_cid__c records. So now my questions are:
> what are the condtions those need to be considered to query the wp_cid__c records?
> If there are no conditions, are you trying to check whether the code_entered__c from wp_leads__c record exists in wp_cid__c object or not? If so what should happen if you find multiple records in wp_cid__c object with the code you entered?
Im asking these questions not you confuse you :) but to know what the exact requirment is., hope you understand that!
Cheers.,
Thanks,
Balaji
trigger demo on wp_leads__c(before insert, before update)
{
set<ID> wpCID = new set<ID>();
for(wp_leads__c wp:trigger.new)
{
wpCID.add(wp.wp_cid__cID);
}
List<wp_cid__c> wpcids=[select id, name ,coupon__c from wp_cid__c where id In :wpCID];
for(wp_leads__c wp:trigger.new)
{
if(wp. code_entered__c == wpcids[0].coupon__c)
{
wp.matched_code__c=true;
}
}
}
Hope it helps.,
Thanks,
balaji
check this out!