You need to sign in to do that
Don't have an account?
SKollcaku
A trigger to copy the value of a custom picklist from Account to another custom picklist in Contact?
Hi,
I need to have a trigger to copy the value of a picklist from Account to its related Contacts (another custom picklist).
The requirement is only to be copied if in the Contact poage the picklist is empty.
I tried this trigger:
But it worksonly if I change the picklist in Contact and not viceversa.
Any suggestions?
Thanks,
Skender
I need to have a trigger to copy the value of a picklist from Account to its related Contacts (another custom picklist).
The requirement is only to be copied if in the Contact poage the picklist is empty.
I tried this trigger:
trigger UpdateContactRegione on Contact(before Insert, before Update) { for(Contact Cont: Trigger.new){ Account acct = [select id,Regione__c from Account where Id=:Cont.AccountId]; if(Cont.Regione__c == null) Cont.Regione__c= acct.Regione__c; } }
But it worksonly if I change the picklist in Contact and not viceversa.
Any suggestions?
Thanks,
Skender
You should use a batch class for these kind of scenarios, please find the following solution -
Batch Class:
Schedulable Class:
Schedule the above class by navigating to Setup > Develop > Apex Classes > Schedule Apex
(or)
Developer Console > anonymous block > past the following logic -
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
All Answers
Have one more field Regione_Checkbox__c(Default the value to True).It will work n the Contact poage the picklist is empty.
trigger UpdateContactRegione on Contact (before insert,before Update) {
for(Contact Cont: Trigger.new){
Account acct = [select id,Regione__c from Account where Id=:Cont.AccountId];
if(Cont.Regione__c == null && Cont.Regione_Checkbox__c==True)
{
Cont.Regione__c= acct.Regione__c;
}
}
}
Please Let me know if it is helpful or not.
Thanks& Regards
Dinesh
You should use a batch class for these kind of scenarios, please find the following solution -
Batch Class:
Schedulable Class:
Schedule the above class by navigating to Setup > Develop > Apex Classes > Schedule Apex
(or)
Developer Console > anonymous block > past the following logic -
------------
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
set<id> setid =new set<id>();
for(Contact Cont: Trigger.new){
if(cont.accoutid != null)
{
setid.add(cont.accoutid);
}
for(contact con : trigger.new)
Account acct = [select id,Regione__c from Account where Id in: setid];
if(con.Regione__c == null)
{
Con.Regione__c= acct.Regione__c;
con.accountid=acct.id;
}
}