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
sfdcianpsfdcianp 

Trigger on contact

Hi all,

 

on contact object while saving a new contact i need to give the account lookup field.

after saving a record i have a junction object called accountcontact there a new record
needs to be created and the contact name and account name needs to be popullated there.

 

 

Thanks in advance

Deepak Kumar ShyoranDeepak Kumar Shyoran

Hi sfdcianp,

 

To create a new record for accountcontact object after creating a record of contact you need to write a trigger on contact after insert event to create a new record for accountcontact objects.

 

For more help on trigger visit http://wiki.developerforce.com/page/Apex_Code_Best_Practices

 

 

If this post helps you then hit kudus by clicking on star and accept my post as a solution to your question. 

souvik9086souvik9086

Try this

 

trigger PopulateJunctionObject on Contact(after insert){

List<AccountContact__c> accConTobeInserted = new List<AccountContact__c>();
for(Contact conObj : trigger.new){

AccountContact__c accCon = new AccountContact__c();
accCon.Account__c = conObj.AccountId;
accCon.Contact__c = conObj.Id;
accConTobeInserted.add(accCon);
}
if(accConTobeInserted.size() > 0){
insert accConTobeInserted;
}
}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks