Guest User

Untitled

a guest
Nov 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. trigger updatevalueonOpportunity on OpportunityLineItem (before insert) {
  2.  
  3. Set<id> prid = new Set<id>();
  4. Set<id> oppid = new Set<id>();
  5. for(OpportunityLineItem ol : Trigger.new){
  6. prid.add(ol.product2id);
  7. oppid.add(ol.OpportunityId);
  8. }
  9.  
  10. 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')];
  11. list<opportunity> Opps = [select id,PIMtype__c,HasOpportunityLineItem from opportunity where id IN:oppid];
  12.  
  13. if(Products.size()>0)
  14. {
  15. string prodPimtype = Products[0].PIM_Type__c;
  16. for(OpportunityLineItem ol1 : Trigger.new){
  17. for(product2 prods:Products){
  18. for(opportunity upOpp:Opps){
  19. if(upOpp.HasOpportunityLineItem == false)
  20. {
  21. if(prodPimtype == prods.PIM_Type__c && upOpp.id==ol1.Opportunityid){
  22. upOpp.PIMtype__c = prods.PIM_Type__c ;
  23. }else{
  24. ol1.addError('All OpportunityProducts are should be same PIM Type');
  25. }
  26. }else{
  27. if(upOpp.PIMtype__c==prods.PIM_Type__c){
  28. upOpp.PIMtype__c = prods.PIM_Type__c ;
  29. }else{
  30. ol1.addError('All OpportunityProducts are should be same PIM Type');
  31. }
  32. }
  33. }
  34. }
  35.  
  36. }
  37. update Opps;
  38. }
  39. }
  40.  
  41. Trigger updatevalueonOpportunity on OpportunityLineItem (before insert) {
  42.  
  43. Set<Id> PrdId = new set<Id>();
  44. Set<Id> OppId = new set<Id>();
  45. for(OpportunityLineItem OppLine : Trigger.new){
  46. PrdId.add(OppLine.product2id);
  47. OppId.add(OppLine.OpportunityId);
  48. }
  49.  
  50. 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')]);
  51. List<OpportunityLineItem> OppLinelst = [select id,product2id,Opportunityid from OpportunityLineItem where Opportunityid In:oppid];
  52. Map<Id,Opportunity> OppMap = new map<Id,Opportunity>([select id,HasOpportunityLineItem,PIMType__c from Opportunity where id In:oppid]);
  53. Map<Id,OpportunityLineItem> OppLineMap = new Map<Id,OpportunityLineItem>();
  54. List<Opportunity> UpdateOpportunity = new list<Opportunity>();
  55.  
  56. for(OpportunityLineItem OppItems : OppLinelst){
  57. OppLineMap.put(OppItems.Opportunityid,OppItems);
  58. }
  59.  
  60. if(CloudProductsmap.size()>0)
  61. {
  62. for(OpportunityLineItem Oppline1 : Trigger.new){
  63. if(OppMap.get(Oppline1.Opportunityid).HasOpportunityLineItem){
  64. if(OppMap.get(Oppline1.Opportunityid).PIMtype__c != null)
  65. String Pimtype = OppMap.get(Oppline1.Opportunityid).PIMtype__c;
  66. if(Pimtype!= CloudProductsmap.get(Oppline2.product2id).PIM_Type__c){
  67. Oppline1.addError('Product PIM type should be same as Existing product PIM type.');
  68. }
  69. }else{
  70.  
  71. string Pimtype1 = CloudProductsmap.get(Oppline1.product2id).PIM_Type__c;
  72. for(OpportunityLineItem Oppline2 : Trigger.new){
  73.  
  74. if(Pimtype1 == CloudProductsmap.get(Oppline2.product2id).PIM_Type__c){
  75. OppMap.get(Oppline2.Opportunityid).PIMType__c = Pimtype1;
  76.  
  77. Opp.PIMType__c = loudProductsmap.get(Oppline2.product2id).PIM_Type__c;
  78.  
  79. }else{
  80. Oppline1.addError('All OpportunityProducts first are should be same PIM Type');
  81. }
  82. }
  83. }
  84. }
  85.  
  86. update OppMap.values();
  87. }
  88. }
Add Comment
Please, Sign In to add comment