+ Start a Discussion
bharath kumar 52bharath kumar 52 

Trigger to add account and contact info to a custom object "after insert"

Hi All,

I have a situation where i need to insert 2 fields from account and the few fields from contact(related to account) to a custom object . Is it possible using triggers?
 
SFDC9999SFDC9999
1. When does this need to happen ? Upon Contact creation or Account creation or when one of these update ?
2. Is the new object to related to account or contact ?

This can be defenitely done through trigger. 

 
bharath kumar 52bharath kumar 52
@SFDC9999 1.)It needs to happen when contact is created.
2.)It deosn't have a relationship with either of them but i think i need to create lookup on account only theni can access it i guess.
SFDC9999SFDC9999
Here is something to start , i have a object Relationship which has a lookup to Contact . Every time a contact is created then a relationship record is created with contact details . You can get more fields added here if you need . 

rigger createRelationship on Contact (after insert) 
{   
   
    
        List<Relationship__c> Relationship = new List<Relationship__c>();
        for (Contact con : trigger.new) 
        {
            Relationship__c rl = new Relationship__c();
            rl.Contact__c = Con.Id;
            rl.Employee__c = Con.Logged_in_User__c;
            rl.Functional_Area__c = Con.Functional_Area__c;
            rl.Contact_Key_Skills__c = Con.KeySkills__c;
            
            Relationship.add(rl);
        }
        insert Relationship;
    
}

 
sandeep reddy 37sandeep reddy 37
 i thought your asking about if u save the contact after need to save account with 2 fields from contact 
global trigger foraccount on contact(after insert){
list<contact con=[select lastname,phone from contact where name=:trigger.new];
LIst<account> acc=new list<account>();
account a=new account();
a.name=con.lastname;
a.phone=con.phone;
}
just do this any issue tell me i hope this is use ful to u