+ Start a Discussion
sessusessu 

trigger

Hi Sales force I have created two custom objects, a and b i want to create a trigger so that if i update records of a, automatically b will also get updated. please help me this code i have written but update is not happening, please help, have created a look up named.... MemberName(Name__c) in member2 to member trigger updt on Member__c (before update) { Map mem= new Map(); for (integer i=0; imemm=new List(); for(Member2__c x : [select id, FirstName__c from Member2__c where Name__c in : mem.keyset()]) { Member__c member = mem.get(x.Name__c); x.FirstName__c = member.FirstName__c; memm.add(x); } update memm; }
apex_keenapex_keen
Chamil has answered to your question before also. Please tell if this is not solving your problem http://boards.developerforce.com/t5/Apex-Code-Development/copy-field-values-of-one-object-to-another-object/m-p/314843#M55677
nbknbk

Here you go with simple trigger

Contact has been created when Account inserted.

trigger trgInsertContact on Account (after insert)
 {
      Account[] acc = Trigger.new; 
      Contact c = new Contact();
      c.Accountid = acc[0].Id;
      c.Email = 'test@test.com';
      c.LastName = acc[0].Name;
      insert c;     
 }

Shashikant SharmaShashikant Sharma

You can see this to learn writting triggers from very basic to advance and best practices

 

http://forceschool.blogspot.com/search/label/Apex%20Triggers

 

It also covers the case that you want.