You need to sign in to do that
Don't have an account?
updating picklist fields using triggers...
-Create a trigger, if Red is selected delete the all related contacts, if Green is selected map the same value on related contacts, if Blue is selected clone all contacts to the parent account (Parent Account is a field on Account object) record.
thanks in advance...
this is what i have made...
trigger ColorCodeTrigger on Account (after insert,after update)
{
Set<Id> accIds = new Set<Id>();
for(Account con :trigger.new)
{
accIds.add(con.Id);
}
List<contact> conlist = new List<contact>([select id,AccountId from contact
where id in: accIds]);
for(Account con : trigger.new)
{
if(conlist.size() > 0 && conlist != null && con.color_codes__c == 'Red')
{
conlist.clear();
}
update conlist;
}
}
Hi may be this code useful for you
trigger ColorCodeTrigger on Account (after insert,after update)
{
Map<Id,String> accIds = new Map<Id,String>();
Map<id,Contact> conmap=new Map<id,Contact>();
List<contact> del=New List<Contact>();
for(Account acc :trigger.new)
{
accIds.put(acc.Id,color_codes__c);
}
List<contact> conlist = new List<contact>([select id,AccountId,color_codes__c from contact where id in: accIds.keyset()]);
for(integer i=0;i<conlist.size();i++){
conmap.put(conlist[i].AccountId,conlist[i]);
}
for(integer i=0;i<accIds.size();i++){
// For Deletion operation
if(accIds.get(accIds[i])=='Red'){
for(integer i=0;i<conlist.size();i++){
if(accIds.containsKey(conlist[i].AccountId)){
del.add(conmap.get(conlist[i].AccountId));
}
}
}
}
delete del;
}
}
The Above code is for Delete operation when we select Red color
Like this you can do for another two colors also....