• Abby Douglas 9
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I have a lookup relationship between Accounts and Leads (account__c) and I would like to create a before insert, before update (I think) trigger to transfer the Account Name to the Company name field. I just don't even know where to begin.  

Is this how you would do it? If so, could someone point me in the right direction or help me? 
Hi - I'm trying to create a trigger to update the lead count on the Account page.  I have a lookup relationship between Leads and Accounts (accounts__c) and a custom field on the Account (lead_count__c). I've created the below by tweaking a contact count trigger, but I'm running into the below errors on line 21 and 23.

I'm by no means a developer and any help and guidance would be greatly appreciated.  Thank you and Happy Holidays!
Line 23 - Lead_Count__c, (Select id, Name From Lead) from Account Where id in:parentIdsSet
                                     ^
ERROR at Row:1:Column:55
Didn't understand relationship 'Lead' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Line 21 - Variable does not exist: Leads

trigger leadSumTrigger on Lead (After insert, After delete, After update, After undelete) {
    Set<Id> parentIdsSet = new Set<Id>();
    List<Account> accountListToUpdate = new List<Account>();
    IF(Trigger.IsAfter){
        IF(Trigger.IsInsert || Trigger.IsUndelete|| Trigger.IsUpdate){
            FOR(Lead l : Trigger.new){
                if(l.Account__c!=null){  
                   parentIdsSet.add(l.Account__c);
                }
            }
        }
        IF(Trigger.IsDelete|| Trigger.IsUpdate){
            FOR(Lead l : Trigger.Old){
                if(l.Account__c!=null){  
                   parentIdsSet.add(l.Account__c);
                }
            }
        }
    }
    System.debug('#### parentIdsSet = '+parentIdsSet);
    List<Account> accountList = new List<Account>([Select id ,Name, Lead_Count__c, (Select id, Name From Lead) from Account Where id in:parentIdsSet]);
    FOR(Account acc : accountList){
        List<Lead> leadList = acc.Leads;
        acc.Lead_Count__c = leadList.size();
        accountListToUpdate.add(acc);
    }
    try{
        update accountListToUpdate;
    }catch(System.Exception e){
       
    }}

 
I have a lookup relationship between Accounts and Leads (account__c) and I would like to create a before insert, before update (I think) trigger to transfer the Account Name to the Company name field. I just don't even know where to begin.  

Is this how you would do it? If so, could someone point me in the right direction or help me? 
Hi - I'm trying to create a trigger to update the lead count on the Account page.  I have a lookup relationship between Leads and Accounts (accounts__c) and a custom field on the Account (lead_count__c). I've created the below by tweaking a contact count trigger, but I'm running into the below errors on line 21 and 23.

I'm by no means a developer and any help and guidance would be greatly appreciated.  Thank you and Happy Holidays!
Line 23 - Lead_Count__c, (Select id, Name From Lead) from Account Where id in:parentIdsSet
                                     ^
ERROR at Row:1:Column:55
Didn't understand relationship 'Lead' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Line 21 - Variable does not exist: Leads

trigger leadSumTrigger on Lead (After insert, After delete, After update, After undelete) {
    Set<Id> parentIdsSet = new Set<Id>();
    List<Account> accountListToUpdate = new List<Account>();
    IF(Trigger.IsAfter){
        IF(Trigger.IsInsert || Trigger.IsUndelete|| Trigger.IsUpdate){
            FOR(Lead l : Trigger.new){
                if(l.Account__c!=null){  
                   parentIdsSet.add(l.Account__c);
                }
            }
        }
        IF(Trigger.IsDelete|| Trigger.IsUpdate){
            FOR(Lead l : Trigger.Old){
                if(l.Account__c!=null){  
                   parentIdsSet.add(l.Account__c);
                }
            }
        }
    }
    System.debug('#### parentIdsSet = '+parentIdsSet);
    List<Account> accountList = new List<Account>([Select id ,Name, Lead_Count__c, (Select id, Name From Lead) from Account Where id in:parentIdsSet]);
    FOR(Account acc : accountList){
        List<Lead> leadList = acc.Leads;
        acc.Lead_Count__c = leadList.size();
        accountListToUpdate.add(acc);
    }
    try{
        update accountListToUpdate;
    }catch(System.Exception e){
       
    }}