Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger updatevalueonOpportunity on OpportunityLineItem (before insert) {
- Set<id> prid = new Set<id>();
- Set<id> oppid = new Set<id>();
- for(OpportunityLineItem ol : Trigger.new){
- prid.add(ol.product2id);
- oppid.add(ol.OpportunityId);
- }
- list<product2> Products = [select id,PIM_Type__c from product2 where id IN:prid and (PIM_Type__c='Cloud Flexibility Mode'or PIM_Type__c='Cloud Serenity Mode')];
- list<opportunity> Opps = [select id,PIMtype__c,HasOpportunityLineItem from opportunity where id IN:oppid];
- if(Products.size()>0)
- {
- string prodPimtype = Products[0].PIM_Type__c;
- for(OpportunityLineItem ol1 : Trigger.new){
- for(product2 prods:Products){
- for(opportunity upOpp:Opps){
- if(upOpp.HasOpportunityLineItem == false)
- {
- if(prodPimtype == prods.PIM_Type__c && upOpp.id==ol1.Opportunityid){
- upOpp.PIMtype__c = prods.PIM_Type__c ;
- }else{
- ol1.addError('All OpportunityProducts are should be same PIM Type');
- }
- }else{
- if(upOpp.PIMtype__c==prods.PIM_Type__c){
- upOpp.PIMtype__c = prods.PIM_Type__c ;
- }else{
- ol1.addError('All OpportunityProducts are should be same PIM Type');
- }
- }
- }
- }
- }
- update Opps;
- }
- }
- Trigger updatevalueonOpportunity on OpportunityLineItem (before insert) {
- Set<Id> PrdId = new set<Id>();
- Set<Id> OppId = new set<Id>();
- for(OpportunityLineItem OppLine : Trigger.new){
- PrdId.add(OppLine.product2id);
- OppId.add(OppLine.OpportunityId);
- }
- Map<Id,Product2> CloudProductsmap = new map<Id,Product2>([Select id,PIM_Type__c from product2 where Id In:PrdId and (PIM_Type__c='Cloud Flexibility Mode' or PIM_Type__c='Cloud Serenity Mode')]);
- List<OpportunityLineItem> OppLinelst = [select id,product2id,Opportunityid from OpportunityLineItem where Opportunityid In:oppid];
- Map<Id,Opportunity> OppMap = new map<Id,Opportunity>([select id,HasOpportunityLineItem,PIMType__c from Opportunity where id In:oppid]);
- Map<Id,OpportunityLineItem> OppLineMap = new Map<Id,OpportunityLineItem>();
- List<Opportunity> UpdateOpportunity = new list<Opportunity>();
- for(OpportunityLineItem OppItems : OppLinelst){
- OppLineMap.put(OppItems.Opportunityid,OppItems);
- }
- if(CloudProductsmap.size()>0)
- {
- for(OpportunityLineItem Oppline1 : Trigger.new){
- if(OppMap.get(Oppline1.Opportunityid).HasOpportunityLineItem){
- if(OppMap.get(Oppline1.Opportunityid).PIMtype__c != null)
- String Pimtype = OppMap.get(Oppline1.Opportunityid).PIMtype__c;
- if(Pimtype!= CloudProductsmap.get(Oppline2.product2id).PIM_Type__c){
- Oppline1.addError('Product PIM type should be same as Existing product PIM type.');
- }
- }else{
- string Pimtype1 = CloudProductsmap.get(Oppline1.product2id).PIM_Type__c;
- for(OpportunityLineItem Oppline2 : Trigger.new){
- if(Pimtype1 == CloudProductsmap.get(Oppline2.product2id).PIM_Type__c){
- OppMap.get(Oppline2.Opportunityid).PIMType__c = Pimtype1;
- Opp.PIMType__c = loudProductsmap.get(Oppline2.product2id).PIM_Type__c;
- }else{
- Oppline1.addError('All OpportunityProducts first are should be same PIM Type');
- }
- }
- }
- }
- update OppMap.values();
- }
- }
Add Comment
Please, Sign In to add comment