Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger CreateNewAppRecordWhenContactCreated on Contact(after insert,after update) { public List<Hobbies__c> appList = new List<Hobbies__c>(); List<Hobbies__c> testList = new List<Hobbies__c>([select id,Name,Phone__c,contact_id__c from Hobbies__c]); public Hobbies__c hob; if(trigger.isafter && trigger.isInsert){ for(Contact con : Trigger.new){ Hobbies__c app = new Hobbies__c(); app.contact_id__c = con.id; app.Name = con.FirstName+' '+con.LastName; app.Phone__c = con.Phone; appList.add(app); } if(appList.size()>0 && appList != NULL){ insert appList; } } if(trigger.isafter && trigger.isupdate){ for(Contact con : Trigger.new){ for(Hobbies__c h : testList){ if(h.contact_id__c == con.id){ hob = [select id,Name,Phone__c,contact_id__c from Hobbies__c where contact_id__c=:con.id]; hob.Name = con.FirstName+' '+con.LastName; hob.Phone__c = con.Phone; appList.add(hob); } } } if(appList.size()>0 && appList != NULL){ update appList; } } }
Please clarify,we want to create a new record while a new record is creating in contact or while updating existed one
Hi,
Create another field called Contact lookup to Contact in the application object.
trigger-----------------------------on contact (after insert ,after update ){
List<Appliccation__c> appl = new List<Appliccation__c> ();
for(Contact con : trigger.new){
if(trigger.isinsert){
Appliccation__c ap = new Appliccation__c();
ap.name = con.name ;
ap.phone = con.phone ;
ap.Contact__c = con.id ;
appl.add(ap);
}
}
}
/// you can add update condition to update related application for an update.
Thanks,
Harish R.
trigger-----------------------------on contact (after insert ,after update ){
List<Appliccation__c> appl = new List<Appliccation__c> ();
List<id> vconids = new List<id>();
for(Contact con : trigger.new){
if(trigger.isinsert){
Appliccation__c ap = new Appliccation__c();
ap.name = con.name ;
ap.phone = con.phone ;
ap.Contact__c = con.id ;
appl.add(ap);
}
if(trigger.isupdate){
vconids.add(con.id);
}
}
List<Application__c> aps = [select id,contact__c , name , phone__c from Application__c where contact__c =: vconids];
for(Application__c ams: aps){
Contact conds = trigger.newmap.get(ams.contactid);
ams.phone = conds.phone;
ams.name = conds.name ;
}
update aps;
}
Thanks,
Harish R.
Error: Compile Error: Invalid type: Schema.application at line 35 column 27
if we haven't any relationship between those two,just create a field like "contact id" and use below code it should may be helps. Here i have used hobbies custom object and fileds, we will just make those changes.
Let me Known it hepls or we have any queries.