function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shalushalu 

create new object called application with 2 field namely application name and phone .if contact record is inserted new application record need to insert using trigger ..i need (after update ) trigger

shalushalu
can anyone send me code regarding this reqiurement
Brahmaiah GantaBrahmaiah Ganta
Hi ,
Please clarify,we want to create a new record while a new record is creating in contact or while updating existed one
Brahmaiah GantaBrahmaiah Ganta
Have any relationship between the two objects
Harish RamachandruniHarish Ramachandruni


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.


 
shalushalu
i need (after update)coding for this reqiurement 
Harish RamachandruniHarish Ramachandruni
HI,


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.


 
shalushalu

Error: Compile Error: Invalid type: Schema.application at line 35 column 27
Brahmaiah GantaBrahmaiah Ganta
Hi @swathy,
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.
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;
    }
     }
}
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.