You need to sign in to do that
Don't have an account?

Simple Trigger, Not working with my Code.
Hi all,
My Scenario, i inserted some contacts with Dataloader in to Contacts Obj while inserting i left Account Name field empty in Contacts Obj. Now i want to update that field(Account Name field in Contact Obj).
Ex: For Contacts, starts with 'Al%' Account Name will be "Infosys".
For Contacts, starts with 'Na%' Account Name will be "IBM".
For Contacts, starts with 'Ma%' Account Name will be "TCS".
for this i wrote a trigger as below it didn't showing error but not updating Account Name field in Contact.
Trigger:
trigger AddAccName on Contact (before insert, before update) {
list<contact> lst = new list<contact>([select id,name from contact where name like 'al%']);
for(contact c: trigger.new)
{
c.account.name = 'Infosys';
lst.add(c);
}
insert lst;
}
My Scenario, i inserted some contacts with Dataloader in to Contacts Obj while inserting i left Account Name field empty in Contacts Obj. Now i want to update that field(Account Name field in Contact Obj).
Ex: For Contacts, starts with 'Al%' Account Name will be "Infosys".
For Contacts, starts with 'Na%' Account Name will be "IBM".
For Contacts, starts with 'Ma%' Account Name will be "TCS".
for this i wrote a trigger as below it didn't showing error but not updating Account Name field in Contact.
Trigger:
trigger AddAccName on Contact (before insert, before update) {
list<contact> lst = new list<contact>([select id,name from contact where name like 'al%']);
for(contact c: trigger.new)
{
c.account.name = 'Infosys';
lst.add(c);
}
insert lst;
}
Just match the values and check again. Even if this doesn't work, let me know.
Let me clear some more on this scenario,
1. I loaded data from data loader in to contact Obj (Say: 50)
2. while loading i left Account field empty in contac Object.
3. Now i want to update that Account field in Contact Obj, which contact names starts with 'Al%' update the account 'Infosys'
for above how could write the trigger.?