Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. public with sharing class CampaignDesignProfileTrigger {
  2. public void updateAccount(List<Campaign_Design_Profile__c> newProfiles){
  3. //This procedure will update the Account_Name_Ref__c with the
  4. //Account Id on the related Opportunity.
  5. Map<Id, Id> oppAccountIds = new Map<Id, Id>();
  6. List<Id> oppIds = new List<Id>();
  7.  
  8. //Retrieving the Opportunity Ids for the new records
  9. for(Campaign_Design_Profile__c p : newProfiles){
  10. oppIds.add(p.Related_Opportunity__c);
  11. }
  12.  
  13. //Populating the oppAccountIds map with the Opp Id/Acct Id for lookup later
  14. for(Opportunity o : [Select Id, AccountId From Opportunity Where Id in:oppIds]){
  15. oppAccountIds.put(o.Id, o.AccountId);
  16. }
  17.  
  18. for(Campaign_Design_Profile__c p : newProfiles){
  19. p.Account_Name_Ref__c = oppAccountIds.get(p.Related_Opportunity__c);
  20. }
  21. }
  22.  
  23. static testMethod void testCampaignDesignProfileTrigger(){
  24. test.startTest();
  25. //Retrieving Record Types
  26. List<RecordType> rec_type = [Select Id From RecordType
  27. Where IsActive=true And SobjectType = 'Campaign_Design_Profile__c' Limit 1];
  28. //Creating a test Account
  29. Account acct = new Account(Name='CampaignDesignProfileTest Account');
  30. insert acct;
  31.  
  32. //Creating a test Opportunity
  33. Opportunity opp = new Opportunity(Name='CampaignDesignProfileTest Opportunity', AccountId=acct.Id,
  34. StageName='Needs Analysis', CloseDate=system.today());
  35. insert opp;
  36.  
  37. //Creating a test Campaign Design Profile
  38. Campaign_Design_Profile__c cdp = new Campaign_Design_Profile__c(Name='CampaignDesignProfileTest cdp',
  39. Campaign_Type__c='Account Profiling', Related_Opportunity__c=opp.Id);
  40. cdp.Estimate_Type__c = 'N/A';
  41. cdp.Volume__c =14.00;
  42. cdp.of_Hours__c =15.00;
  43. insert cdp;
  44.  
  45. test.stopTest();
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement