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
Sourav PSourav P 

How to add a NOT condition in a code snippet?

Hi ,
I have the below code snippet on Lead trigger.
I want to add an extra condition if the Lead Owner is Not equal to the queue "Partner Marketing" , How to do that ? i tried as  below but shows errors,

!newLead.OwnerID.equals ('Partner Marketing') Or tried as well
newLead.OwnerID != 00yhggddy4th2we
 
if (!oldLead.status.equals(newLead.status) || 
                (newLead.Company_Type__c != null && 
                 !newLead.Company_Type__c.equals(oldLead.Company_Type__c) && 
                 (newLead.Company_Type__c.startsWith('Partner')) )
               ) {
          // Add to list to update
            leadsToUpdate.add(new Lead(id = newLead.id));                    
        }

 
vishal-negandhivishal-negandhi

Hi Sourav, 

You need to do this
newLead.OwnerID != '00yhggddy4th2we' to make it work.

However, I'd recommended because we are hard-coding an Id which isn't a good practice. 

So better use the queue name for filtering
!newCase.Owner.Name.equals('Chat-IT') 

You might need to query the Owner.Name field if not available already but I hope you have an idea on how to do this now.

 

Best,

Vishal

Sourav PSourav P
Hi Vishal, Thanks
i tried as below , !newLead.Owner.Name.equals('Partner Marketing') But it didnt worked. Actually its a queue, and the object is Lead, so do we have specific name for the queue or so ?
Brian Weers 18Brian Weers 18
outside your loop, query for the id of the queue which you want to use.  It is in the object group.  Query would look like this:
select id,name,type from group where type = 'queue' and name = 'Partner Marketing'.  You can store that Id has a variable or in a variable which is a list of set of Ids and then use that with you != construction
AmitSoniAmitSoni
What Error are you getting?

As per the conversation so far, my understand is you are trying to compare the Lead Owner with a Queue name in Before/After Trigger. At this point of time Lead OwnerId field will not be assigned as per the sequence of the events execution as below, due to the assignment rule executes after Before/After trigger:

1. The original record is loaded from the database (or initialized for an insert statement)
2. The new record field values are loaded from the request and overwrite the old values
3. All before triggers execute (TRIGGERS)
4. System validation occurs, such as verifying that all required fields have a non-null value, and running any user-defined validation rules (VALIDATIONS)
5. The record is saved to the database, but not yet committed
6. All after triggers execute
7. Assignment rules execute
8. Auto-response rules execute
9. Workflow rules execute (WORKFLOW)
10. If there are workflow field updates, the record is updated again
11. If the record was updated with workflow field updates, before and after triggers fire one more time (and only one more time)
12. Escalation rules execute
13. All DML operations are committed to the database
14. Post-commit logic executes, such as sending email

Link for your reference:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm 

Hope this will be helpful!!