You need to sign in to do that
Don't have an account?

Trigger - how make it NOT fire for one profile ID
Hi,
I have a trigger that ensures a delivery contact is added to the opportunity. I now want to make the trigger NOT fire when a Finance user edits the opportunity. So somehow I want to add NOT profileId = '00e20000000me3Q'. So that Finance users can go in and change stuff without having to add a delivery contact, but everyone else have to.
Where would I add this? Can you use NOT in apex code?
Here is my trigger:
trigger Opportunity_DeliveryContact_Required on Opportunity (before insert, before update) { //map to keep track of the contact_required = 1 Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>(); //Trigger.new is an array of opportunities //and adds any that have Contact_Required = 1 to the oppy_contact Map for (Integer i = 0; i < Trigger.new.size(); i++) { System.debug('*****Required? ' + Trigger.new[i].contact_required__c); if (Trigger.new[i].contact_required__c == 1) { oppy_contact.put(Trigger.new[i].id,Trigger.new[i]); } } //map to keep track of the opportunity contact roles map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>(); //select OpportunityContactRoles for the opportunities with contact role required List<OpportunityContactRole> roles = [select OpportunityId, Role from OpportunityContactRole where (OpportunityContactRole.Role ='Delivery Contact') and OpportunityContactRole.OpportunityId in :oppy_contact.keySet()]; for (OpportunityContactRole ocr : roles) { //puts the contact roles in the map with the Opportunity ID as the key oppycontactroles.put(ocr.OpportunityId,ocr); } // Loop through the opportunities and check if they exists in the contact roles map or contact role isn't required String OppRectypeId = [SELECT Id, Name FROM RecordType WHERE Sobjecttype = 'Opportunity' AND Name = 'License Opportunity'].Id; for (Opportunity oppy : system.trigger.new) { if(Oppy.RecordTypeId == OppRectypeId) { if (oppy.contact_required__c ==1 && !oppycontactroles.containsKey(oppy.id)) { oppy.addError('No Delivery Contact exists. Please go to the Contact Roles area and select a delivery contact before you can move on to stage "A6 - Closed Won".'); } } } }
David,I got your point as what you are trying to say here.
Jill,
Try this one,
All Answers
Couple things, I would not hard code the Id of the profile as this would be coupled to the org you're working in and won't work for future deployments.
That being said you can handle it by aggregating the list of "LastModifiedBy" id's into a set and querying the user table to get their profile Id. You would then exclude your opportunities if the user matches the criteria.
Something like this:
Jill,
Try below code :-
David,I got your point as what you are trying to say here.
Jill,
Try this one,