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
snehil kumarsnehil kumar 

When an Opportunity Status is being changed to prospect, make sure there is a value in the start date and end date.

Hi All,

When an Opportunity Status is being changed to prospect, make sure there is a value in the start date and end date.

CharuDuttCharuDutt
Hii Snehil
Try Below Trigger
trigger opptrigger in opportunity(before update){
	for(opportunity opp: trigger.new){
	if(opp.StageName == 'Prospect' && trigger.oldmap.get(opp.Id).StageName && opp.startDate == null && opp.endDate == null){
	opp.adderror('fill startDate And EndDate');
		}
	}
}
Please Mark It As Best Answer If It Helps
Thank You!
Maharajan CMaharajan C
If all start and end date fields are in Opportunity Object then no need of trigger Simply you can use the validation rule.

Create the below validation rule in opportunity object . Change the api names in below formula as per your org.
 
AND(
	ISCHANGED( StageName ),
	ISPICKVAL( StageName , "Prospect"),
	OR(
		ISBlank(Start_Date__c), 
		ISBlank(End_Date__c), 
	)
)

Thanks,
Maharajan.C
Suraj Tripathi 47Suraj Tripathi 47
Hi snehil kumar,
Try Below Trigger for Your solution:
trigger oppUpdate on Opportunity (before update) {
HandlerOpportunity.updateOpp(trigger.new);
}



////Handler class for Trigger--
public class HandlerOpportunity {
    public static void updateOpp(List<Opportunity>oppList){      
        for(Opportunity opp :oppList){
            if(opp.StageName=='Prospecting'&&opp.Startdate__c==null&&opp.Enddate__c==null){
                opp.addError('enter startdate and enddate');
            }
        }
    }
}

Please mark it as  best answer so that other people can take reference from it.
Thank You