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
ledap13ledap13 

create a Trigger

Hi Friends,

 

how can look like a trigger that fires in the Object Opportunity on the field Probability = 100%???

 

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
digamber.prasaddigamber.prasad

Hi,

 

I assume 100% probability is treated as 1, so based upon that you can use below code skeleton:-

 

trigger OpportunityTrigger on Opportunity(before insert, before update){
	for(Opportunity oppty : trigger.new){
		if(trigger.isInsert){
			if(oppty.Probability == 1){
				//your code here
			}
		}else if(trigger.isUpdate){
			if(oppty.Probability == 1 && oppty.Probability != trigger.oldMap.get(oppty.Id).Probability){
				//your code here
			}
		}
	}
}

 You can modifiy this code to meet your requirement. 

 

Let me know if you have any specific question.

 

 

All Answers

Abhi_TripathiAbhi_Tripathi

Hi,

 

here is an example

trigger TriggerAccount on Account (after insert, after update) {
    
        if(Trigger.isAfter){
            if(Trigger.isInsert || Trigger.isUpdate){
            
                //calling helper class
              TriggerHelper.accountTwitterRatingUpdate(Trigger.newMap, Trigger.oldMap);      
            }
        }
    
}

 Helper class

public with sharing class TriggerHelper {
  
  //method called by account Trigger
  public static void accountTwitterRatingUpdate(Map<Id, Account> mapAccount, Map<Id, Account> oldMapAccount) {
    
    //set of accountId 
    Set<Id> accId = new Set<Id>();
    
    //Iterating records   
       for(Account account : mapAccount.values()){  
             
         //YOUR LOGICS HERE        
         }
       }    
    }
}

 

digamber.prasaddigamber.prasad

Hi,

 

I assume 100% probability is treated as 1, so based upon that you can use below code skeleton:-

 

trigger OpportunityTrigger on Opportunity(before insert, before update){
	for(Opportunity oppty : trigger.new){
		if(trigger.isInsert){
			if(oppty.Probability == 1){
				//your code here
			}
		}else if(trigger.isUpdate){
			if(oppty.Probability == 1 && oppty.Probability != trigger.oldMap.get(oppty.Id).Probability){
				//your code here
			}
		}
	}
}

 You can modifiy this code to meet your requirement. 

 

Let me know if you have any specific question.

 

 

This was selected as the best answer
ledap13ledap13

Thanks !!!

ledap13ledap13

Can you please tell me the script ??

 

(oppty.Probability == 1 && oppty.Probability != trigger.oldMap.get(oppty.Id).Probability)
digamber.prasaddigamber.prasad

Happy that it helped you! If you feel that I was able to help you, could you please give me KUDO for this.

 

Regarding, above code snippet, it checks if probability is 100% and if didn't update. The check is there to make sure that if you edit record without updating probability field, same code snippet not run again and again without change in probability in case of update of record.

 

Let me know if you have any specific question about this.

 

Happy to help you!

ledap13ledap13

Thanks