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
kaustubh chandratrekaustubh chandratre 

Write a trigger on Opportunity. If opportunity amount >= 100000 then update the field Priority__c as "High" else if amount < 100000 and amount > 50000 then update the field Priority__c as "Medium" else if amount <50000 then update the field Priority__c as

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Kaustubh,

Please find the below apex trigger logic for the scenerio. 
 
trigger OpportunityTrigger on Opportunity (before Update) {
    for (opportunity opp : Trigger.new){
        if(opp.Amount>= 100000){
            opp.Priority__c ='High';
        }
        else if (opp.Amount< 100000 && opp.Amount> 50000 ){
            opp.Priority__c='Medium';
        }
        else{
            opp.Priority__c='Low';
        }
    }

}


If this solution helps, Please mark it as best answer.

Thanks,
 
CharuDuttCharuDutt
Hii Kaustaubh
Try Below Trigger
trigger OpportunityTrigger on Opportunity (before Insert,before Update) {

	if(Trigger.isbefore){
	if(Trigger.isInsert){
		 for (opportunity opp : Trigger.new){
        if(opp.Amount >= 100000){
            opp.Priority__c = 'High';
        }
        else if (opp.Amount < 100000 && opp.Amount > 50000 ){
            opp.Priority__c = 'Medium';
        }
        else if(opp.Amount < 50000){
            opp.Priority__c = 'Low';
        }
    }
	}
	if(Trigger.isUpdate){
	 for (opportunity opp : Trigger.new){
        if(opp.Amount >= 100000 && trigger.oldMap.get(Opp.Id).Amount){
            opp.Priority__c = 'High';
        }
        else if (opp.Amount < 100000 && opp.Amount > 50000 && trigger.oldMap.get(Opp.Id).Amount){
            opp.Priority__c = 'Medium';
        }
        else if(opp.Amount < 50000 && trigger.oldMap.get(Opp.Id).Amount){
            opp.Priority__c = 'Low';
        }
    }
	}
	}  
}
Please Mark It As Best Answerr If It Helps
Thank You!
Suraj Tripathi 47Suraj Tripathi 47
Hii Kaustaubh,
Here is the attached code snippet for your issue
trigger OpportunityTrigger on Opportunity (before Update) {
if(Trigger.isbefore && Trigger.isupdate) {
OpportunityHandler.updateOpportunity(trigger.new);
}


public class OpportunityHandler{
public static void updateOpportunity(List<Opportunity> opplist)
{
try{list<opportunity> newoppList = new list<opportunity>();
	 for (opportunity opportunityobj : opplist){
	if(opportunityobj.Amount >= 100000){
		opportunityobj.Priority__c = 'High';
	}
	else if (opportunityobj.Amount < 100000 && opportunityobj.Amount > 50000 ){
		opportunityobj.Priority__c = 'Medium';
	}
	else if(opportunityobj.Amount < 50000){
		opportunityobj.Priority__c = 'Low';
	}
	newoppList.add(opportunityobj);
}
update newoppList;
}
catch (Exception ex) {
		System.debug('Exceptions : : ' + ex.getMessage());
		System.debug('Exceptions Line Number : : ' + ex.getLineNumber());
	}
	}

}

Thanks and regards,
Suraj Tripathi 
Please Mark It As Best Answer If It Solves your issue