You need to sign in to do that
Don't have an account?
Prashant Gulve
On creation of Contact New Record website field should get auto populate, but it's not reflecting for account parent website.
Hi Team Need your Help on this trigger detail info provide please help..
On this trigger while creatig new contact record when i select Child Sham record on 'Account Name' field then Parent website getting auto populate on contact website but when i Select Parent Account Ram in contact 'Account Name' filed then it's showing Contact Website field blank. so it should reflect parent website in both scenario. Below is details
[when ever new contact record will created parent account website filed should get update on contact. even if child selected]
Created a trigger on Contact object (before update) to auto populate Website__c field on creation of New Contact record. on update of Account Parent -Account-Website field and Child Account Website field.
1- I have created Website Field in both account and conatct object data type URL
2- Account Parent Record created. e.g- Ram and website filed updated www.Ram@pareant.com
3- Account Child record created. e.g- Sham and Parent account name is Ram selected website updated www.sham@child.com
4- On New Contact creation always Pareant Account Website should get display on contact object. e.g- www.Ram@pareant.com even if we select Sham on contact object Account name field still www.Ram@pareant.com should get display on Contact object website filed.
Trigger:-
trigger WebsiteAutopopuoonContactTrigger on Contact (before insert) {
WebsiteAutopopuoonContact.createWebsite(trigger.new);
}
Handler:-
public class WebsiteAutopopuoonContact {
public static void createWebsite(List<Contact> contList) {
Set<Id> accSet = new Set<Id>();
for(Contact Con : contList) {
accSet.add(Con.AccountId);
System.debug('accSet===='+accSet);
}
List<Account> accList = [Select Id
, Name
, Website
, Account.Parent.Website
from Account where Id IN:accSet];
map<Id, String> idvswebsite = new map<Id, String>();
for(Account acc : accList){
idvswebsite.put(acc.id, acc.Parent.Website);
}
System.debug('accList==='+accList);
Map<Id,Contact> conNameKeys = new Map<Id,Contact>();
for(Contact Con : contList) {
conNameKeys.put(Con.AccountId, Con);
Con.Website__c = idvswebsite.get(Con.AccountId);
System.debug('conNameKeys==='+conNameKeys);
}
}
}
On this trigger while creatig new contact record when i select Child Sham record on 'Account Name' field then Parent website getting auto populate on contact website but when i Select Parent Account Ram in contact 'Account Name' filed then it's showing Contact Website field blank. so it should reflect parent website in both scenario. Below is details
[when ever new contact record will created parent account website filed should get update on contact. even if child selected]
Created a trigger on Contact object (before update) to auto populate Website__c field on creation of New Contact record. on update of Account Parent -Account-Website field and Child Account Website field.
1- I have created Website Field in both account and conatct object data type URL
2- Account Parent Record created. e.g- Ram and website filed updated www.Ram@pareant.com
3- Account Child record created. e.g- Sham and Parent account name is Ram selected website updated www.sham@child.com
4- On New Contact creation always Pareant Account Website should get display on contact object. e.g- www.Ram@pareant.com even if we select Sham on contact object Account name field still www.Ram@pareant.com should get display on Contact object website filed.
Trigger:-
trigger WebsiteAutopopuoonContactTrigger on Contact (before insert) {
WebsiteAutopopuoonContact.createWebsite(trigger.new);
}
Handler:-
public class WebsiteAutopopuoonContact {
public static void createWebsite(List<Contact> contList) {
Set<Id> accSet = new Set<Id>();
for(Contact Con : contList) {
accSet.add(Con.AccountId);
System.debug('accSet===='+accSet);
}
List<Account> accList = [Select Id
, Name
, Website
, Account.Parent.Website
from Account where Id IN:accSet];
map<Id, String> idvswebsite = new map<Id, String>();
for(Account acc : accList){
idvswebsite.put(acc.id, acc.Parent.Website);
}
System.debug('accList==='+accList);
Map<Id,Contact> conNameKeys = new Map<Id,Contact>();
for(Contact Con : contList) {
conNameKeys.put(Con.AccountId, Con);
Con.Website__c = idvswebsite.get(Con.AccountId);
System.debug('conNameKeys==='+conNameKeys);
}
}
}
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
All Answers
Thanks,
Maharajan.C
try with below code.
If this helps, Please mark it as best answer.
Thanks!!
Thank you for help, but code is not working for parent account Website, it's working for child only. so mine code is also working for child account record only. the our purpose is to Account Parent website should get auto populate on Contact website field on creation of new contact record and selecting "Account Name" is Pareant e.g Ram so it should display www.ram@parent.com only in any scnario. using this code if i select parent Account Name Ram then Contact website showing blank, it should reflect www.ram@pareant.com.
I have tested from my end, It working as per your requirement.
1.I have created parent account with website = www.ram@parent.com
2.I have created child account with webisite =www.sham@child.com and linked this account to parent account.
3. I have created/updated a contact for child account and the website name autopopulated from parent account and value is www.ram@parent.com.
Please follow these steps, it should work.
Thanks!!
so the code i have created it's working for Child Account name but not for Parent so for that i am stuck can you please help me out of that.
Try with below code.
If this helps, Please mark it as best answer.
Thanks!!
Thank you so much for your Help Code is working for Both Parent and Child record.
Thanks once and marked as Best Answer..