• Nishigandha Jadhav
  • NEWBIE
  • 30 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 0
    Replies
Applied cross filters but upto 3 we can add ,needs to add more cross filters .
Helper Class:
public class test{
public static void addContactRole(List<Opportunity> opps) {
List<OpportunityContactRole> oppCR=new List<OpportunityContactRole>();
        for(Opportunity opp : opps ){
           
            if(opp.StageName != 'Prospecting' && opp.StageName != 'Qualification' ){
           
            
              oppCR= [Select Id, opportunityId FROM OpportunityContactRole WHERE opportunityId =:opp.Id];
               
                if(oppCR == null || oppCR.size() == 0){
                   
                    opp.addError(' Opportunity must have at least one Contact Role assigned for any stages beyond 1');
                }
            }
        }
    }

Trigger:
trigger updatecontactrolecount on Opportunity (before insert, before update)
{
test.addContactRole(Trigger.New);
 
}

Note: If opportunity stage is other than Prospecting and Qualifiation then opportunity must have at least one contact role.(working fine but getting to many soql query error for bulk update or insert)
 
trigger Contactid on Case (before  update) {         for(Case c:trigger.new){             if(c.Account_License_Type_del__c!=null){             c.ContactId='0035C00000I4gjl';                    }         } }


Note: Not covering inside if statement.

 
trigger usertrigger on User (before update) {
//Set<ID> username = new Set<ID>{'0050z000007XtMB'};
   
  
   
   
 //Map<ID,User> usernames = new Map<ID,User>([SELECT ID, Name FROM User WHERE Name IN :username]);
  Map<ID,User> usernames = new Map<ID,User>([SELECT ID, Name FROM User WHERE ID in ('0050z000007XtMB' ,'00560000004Mpmp') ]);//(Checking for user id)
    for(User o:trigger.new){
        if(Trigger.oldMap.get(o.id).email!=o.email && usernames.containsKey(o.id) ){
        o.email.addError('you cannot edit the email');
        }
        else if(Trigger.oldMap.get(o.id).username!=o.username && usernames.containsKey(o.id)){
            o.username.addError('you cannot change the username');
        }
        else if(Trigger.oldMap.get(o.id).isActive!=o.isActive && usernames.containsKey(o.id)){
            o.isActive.addError('You cannot deactivate the user');
           
        }
        else if(Trigger.oldMap.get(o.id).profileID !=o.profileID && usernames.containsKey(o.id) ){
            o.profileId.addError('you cannot edit the profile');}
    }
}
setBccAddresses(); method of dingle email messaging