function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gita BorovskyGita Borovsky 

Trying to figure out last bit of Trigger

Hi,

I've got this Trigger on Leads:

trigger UpdateLeadOwner on Lead (before insert) {
    for (Lead leadInLoop : Trigger.new) {
    // Retrieve owner from Account record based on email domain name
    list <Account> acct = [Select OwnerId from Account WHERE Domain_1__c = :leadInLoop.Domain__c Limit 2];
        if (acct.size() == 1) {

    System.debug('account owner id is: ' + acct[0].OwnerId);
    leadInLoop.OwnerId=acct[0].OwnerId;
        }
    }
}

I need to update the trigger so that the Lead source field  "LeadSource" does not contain either of these picklist values, "Contact Us" or "Reprint" but I can't figure out where it should go.  Help, please?  Thanks!
Best Answer chosen by Gita Borovsky
justin_sfdcjustin_sfdc
Sorry my bad, the line should be:

if (leadInLoop.LeadSource != 'Contact Us' && leadInLoop.LeadSource != 'Reprint') {

Forgot to declare the field in which the value should not be equal to Contact Us or Reprint.


Hope that helped!

Thanks!

All Answers

justin_sfdcjustin_sfdc
Hi Gita,

Are you wanting to hide the picklist values from the field LeadSource. If so, you could use recordtypes to do so.

Please let me know what your actual requirement is so that I can better assist you.

Thanks!
Gita BorovskyGita Borovsky
I just don't want those two options in my picklist to be part of the trigger. The trigger looks at the Account owner for the corresponding lead and automatically changes the Lead owner to the rep who owns the Account. I want that to happen in all Lead Source instances except where the Lead source is either Contact Us or Reprint. Does that make sense? Thanks.
justin_sfdcjustin_sfdc
Hi Gita,

You just need to put the condition on when to fire the trigger. Try the code below:

trigger UpdateLeadOwner on Lead (before insert) {
    for (Lead leadInLoop : Trigger.new) {
        if (leadInLoop != 'Contact Us' && leadInLoop != 'Reprint') {
             // Retrieve owner from Account record based on email domain name
              list <Account> acct = [Select OwnerId from Account WHERE Domain_1__c = :leadInLoop.Domain__c Limit 2];
              if (acct.size() == 1) {
 
                    System.debug('account owner id is: ' + acct[0].OwnerId);
                    leadInLoop.OwnerId=acct[0].OwnerId;
               }
          }
    }
}


Thanks!
Gita BorovskyGita Borovsky
I'm getting the following error: Error: Compile Error: Comparison arguments must be compatible types: SOBJECT:Lead, String at line 3 column 13 . Thanks!
justin_sfdcjustin_sfdc
Sorry my bad, the line should be:

if (leadInLoop.LeadSource != 'Contact Us' && leadInLoop.LeadSource != 'Reprint') {

Forgot to declare the field in which the value should not be equal to Contact Us or Reprint.


Hope that helped!

Thanks!
This was selected as the best answer
Gita BorovskyGita Borovsky
That did it. Thanks so much!!!
justin_sfdcjustin_sfdc
Happy to help :)