You need to sign in to do that
Don't have an account?
ExploreForce
create insert trigger on Registration having lookup on parent object contacts
I want to create insert trigger on registration.
1. create lookup on contacts
2. Need to check whether email id already exists in contacts.
if emailid alreday exists in contacts, Don''t register
if emailid doesn't exist, then register the user with new mailid.
Can someone help on this?
trigger Registration on Registration__c (before insert) {
List<String>newemail = new List<String>();
List<Contact> parentObjList = new List<Contact>();
List<Id> listIds = new List<Id>();
for (Registration__c childObj : Trigger.new) {
listIds.add(childObj.Contact__c);
}
parentObjList = [SELECT id,email FROM Contact WHERE ID IN :listIds];
}
1. create lookup on contacts
2. Need to check whether email id already exists in contacts.
if emailid alreday exists in contacts, Don''t register
if emailid doesn't exist, then register the user with new mailid.
Can someone help on this?
trigger Registration on Registration__c (before insert) {
List<String>newemail = new List<String>();
List<Contact> parentObjList = new List<Contact>();
List<Id> listIds = new List<Id>();
for (Registration__c childObj : Trigger.new) {
listIds.add(childObj.Contact__c);
}
parentObjList = [SELECT id,email FROM Contact WHERE ID IN :listIds];
}
If someone registers for an event with an email address not found in the Contact table, a new Contact should be created.
consider the Contact email address to be unique and should therefore be considered a unique identifier for the Contact.
Thanks in advance
trigger Registration on Registration__c (before insert) {
List<String>newemail = new List<String>();
List<Contact> parentObjList = new List<Contact>();
List<Id> listIds = new List<Id>();
for (Registration__c childObj : Trigger.new) {
listIds.add(childObj.Contact__c);
}
parentObjList = [SELECT id,email FROM Contact WHERE ID IN :listIds];
}
map<string,id> contactmap=new map<string.id>();
for(contact cn:parentObjList){
contactmap.add(cn.email,cn.id);
}
for (Registration__c childObj 2: Trigger.new){
if(contactmap.containskey(childobj2.email){
apexpages.adderror('contact already exist with this email');
}
}
Hope this helps.