You need to sign in to do that
Don't have an account?
Mallik
Before Trigger on Contact to set a custom field to a value in the corresponding Account Object.
I want put a trigger on contact. When ever a contact is created and Account is tied to it then I want to set custom field Acct_Industry__c to the value of the industry in the Account Object.
I know it is basic scenario question but I am new to salesforce. Any help is appreciated.
I know it is basic scenario question but I am new to salesforce. Any help is appreciated.
trigger Contact_Trigger on Contact (before Insert, before Update, After Insert, After Update) {
If(Trigger.isBefore){
If(Trigger.isInsert){
For(Contact con:Trigger.New){
If (con.AccountId != Null){
Account Acct = [Select Industry from Account where Id = :con.AccountId LIMIT 1];
con.Acct_Industry__c = Acct.Industry;
}
}
}
}
yes its not good coading skill that use SOQL inside for loop
try this below code
I hop it helps you
Please mark it best answer if it helps you so it make proper solution for others
Thanks