0

The situation is that I want to update a lead field that is map with contact field over a field in the account. I have tried a trigger in the account after insert and query the child on the contact but is not working. Any ideas? Thanks!

4
  • please provide us what you have tried so far so that we can help you further Feb 13, 2015 at 5:41
  • [code] trigger updatefield on Account (after insert) { Account acc = [SELECT id, name, (SELECT Contact.id, Contact.LeadSource from Account.Contacts) FROM Account ]; if(Contact.id != null){ if(Contact.LeadSource = 'XXXX') { acc.AccountSource = 'XXXX'; } } update acc; }
    – andcaj
    Feb 13, 2015 at 21:06
  • trigger updatefield on Account (after insert) { Account acc = [SELECT parentid, name, (SELECT Contact.id, Contact.LeadSource from Account.Contacts) FROM Account ] if(Contact.id != null){ if(Contact.LeadSource = '') { acc.AccountSource = 'XXXX'; }} update acc; }
    – andcaj
    Feb 13, 2015 at 21:16
  • I'm sorry i'm pretty new on how to set the code in a comment, and it looks that i can set correctly. I have tried to select the field from the contact and then update the field on the account. This makes sense? I have thought to do it in the opposite way, by triggering the contact but i don't know how to get the parent ID from the contact.
    – andcaj
    Feb 13, 2015 at 21:17

1 Answer 1

0

I assume that you need to update that on after insert in account object Here is how you get the newly insert object on account

Trigger simpleTrigger on Account (after insert) {
    for (Account a : Trigger.new) {
        //here trigger.new contains the newly inserted record only
    }
}

Here is some code that will help you code thorugh trigger

and what do I think is Account is parent object to leads after insert of account won't give us record in Leads. confirm on this so that I can help you further. correct me so that I can edit my answer you accordingly.

1
  • I need to trigger after insert Contact and Account, because the field i want to update in Account is mapping to a Contact field after a Lead conversion. So what i want to do is trigger after insert contact, and update parent account with the field from Contact, all this after Lead conversion.
    – andcaj
    Feb 16, 2015 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .