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
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12 

how to write the Trigger to following Requirment?

Hi,

On  particular Owner have how many of record created by today on "Opportunity" object? That Record count will update to another object of "Service" , How to achive this updatetion Using trigger

NOTE: No relationship "Opportunity" to "Service", this case how to do this?
I have used following code but i'm struggle Kindly give any idea
Code:
============
Public class OpportunityTriggerHandler{

  public void OnbeforeInsert(list<Opportunity> listNewOpps){
  
   List<Opportunity> RecordCount=new List<Opportunity>();
   AggregateResult[] groupedResults;
  
   groupedResults = [SELECT Name FROM Opportunity WHERE id =:UserInfo.getUserId() group by name];
   system.Debug('============'+groupedResults);
  
  }
   public void OnbeforeUpdate(Map<Id,Opportunity> newOppMap,Map<Id,Opportunity> oldOppMap){
  List<Forecast_Agent__c> Orders = New list<Forecast_Agent__c>([Select Total_Sale__c from Forecast_Agent__c where Owner.Name ='Puthuvannam']);

    for(Forecast_Agent__c sale : Orders){}
    { 
      sale.count = Opportunity.Count;
    }
     Update Orders; 
  }
  
 }
 

Thanks.
SaiGSaiG

Assuming there is a lookup relationship between User and Service objects, the trigger on the opportunity can save the  record count on the User record. Create a formula field on the service object that pulls the count.

Hope this helps.

Thanks,
Sai