+ Start a Discussion
kiran k 12kiran k 12 

need help for trigger?

I have two objects opportunitycarset and discountgrid.in opportunitycarset object discount% and in discountgrid object model,year,totalfleetsize fields is there.the totalfleetsize is lookupto opportunity object.i want update the discount% field in opportunitycarset  based on model,year,totalfleetsize fields present in discountgrid.there is no relationship between these two objects.I am new to apex trigger .
trigger:
trigger Discountupdate on Opportunity_car_set__c(before insert, before update){

  List<ID> OppIds = New List<ID>();

  for(Opportunity_car_set__c o : Trigger.new){
    if(opportunity__r.totalfleetsize!= null){
      OppIds.add(o.Opportunity__c);
    }
  }

 
}

how to achieve this?
Abhishek BansalAbhishek Bansal
Hi Kiran,

Can you please explain your requirement in more detail.
Basically we need the answer of below questions in order to help you out :
  1. On what basis you want to update the Discount% field in OpportunityCarSet object (in both insert and update case). 
  2. How do we get to know that which record of the OpportunityCarSet record is to be updated when DiscountGrid is inserted or updated. Basically we want to know some kind of relationship between both the objects
  3. What should be the new value of discount% field. If it is calculated on the basis of the three fields that you mentioned above than please explain all the cases with proper example.
Please provide your comments on all of the above queries so that we can provide you help.

Thanks,
Abhishek Bansal.