Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. trigger PullProjectNoOpportunity on SAP_Sales_Order__c (before update) {
  2.  
  3. Set<String> codes = new Set<String>();
  4. for (SAP_Sales_Order__c o : trigger.new) codes.add(o.SAP_Project_NO__c);
  5.  
  6. Map<String, Opportunity> pronumOpportunities = new Map<String, Opportunity>();
  7. for (Opportunity a : [
  8. SELECT Cilioproject__c FROM Opportunity
  9. WHERE Cilioproject__c IN :codes
  10. ]) pronumOpportunities.put(a.Cilioproject__c, a);
  11.  
  12. for (SAP_Sales_Order__c o : Trigger.new)
  13. {
  14. Opportunity pronumOpportunity = pronumOpportunities.get(o.SAP_Project_NO__c);
  15. Id parentId = (pronumOpportunity == null) ? null : pronumOpportunity.Id;
  16. o.project__c = parentId;
  17. }
  18. }
  19.  
  20. @isTest
  21. private class testPullProjectNoOpportunity {
  22. static testMethod void validateLookupPopulation() {
  23. SAP_Sales_Order__c SO = new SAP_Sales_Order__c(name='9999999');
  24. SO.SAP_Project_No__c = '30157';
  25. insert SO;
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement