• Vaishali Nagar
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi I am new to salesforce and trying to write a trigger to update field(live to site) in Lead based on some condition.

we have a custom field in Account Account_id__c(ex:25679) which is a number and also similar field(seller_id__c-which is also a number ex:25679) in lead which is also a number. When there is a new account with some account id matches with lead seller id then a field live to site(picklist with values Yes, No) in lead should update with Yes.

Here's is my trigger, please correct me.


trigger LTS_Update1 on Account (after update) {
    set<Id> acctIds = new set<Id>();
    map<Id, Account> mapAccount = new map<Id, Account>();
      List<Lead> listLead = new List<Lead>();
    
    for(Account acct : trigger.new) {
        acctIds.add(acct.Id);
        mapAccount.put(acct.Id, acct);
    }
    
    listLead = [SELECT Id, Live_to_site__c, Account__c FROM Lead WHERE Account__c IN : acctIds];    
    
    List<Account> acc=new List<Account>();
    for(Account acct: acc)
    {
    if(acc[0].Account_ID__c == listLead[0].seller_id__c) {
        for(Lead ld : listLead) {
            ld.Live_to_site__c = 'Yes';
          }  
        }
        update listLead;
    }
}