Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class CampaignDesignProfileTrigger {
- public void updateAccount(List<Campaign_Design_Profile__c> newProfiles){
- //This procedure will update the Account_Name_Ref__c with the
- //Account Id on the related Opportunity.
- Map<Id, Id> oppAccountIds = new Map<Id, Id>();
- List<Id> oppIds = new List<Id>();
- //Retrieving the Opportunity Ids for the new records
- for(Campaign_Design_Profile__c p : newProfiles){
- oppIds.add(p.Related_Opportunity__c);
- }
- //Populating the oppAccountIds map with the Opp Id/Acct Id for lookup later
- for(Opportunity o : [Select Id, AccountId From Opportunity Where Id in:oppIds]){
- oppAccountIds.put(o.Id, o.AccountId);
- }
- for(Campaign_Design_Profile__c p : newProfiles){
- p.Account_Name_Ref__c = oppAccountIds.get(p.Related_Opportunity__c);
- }
- }
- static testMethod void testCampaignDesignProfileTrigger(){
- test.startTest();
- //Retrieving Record Types
- List<RecordType> rec_type = [Select Id From RecordType
- Where IsActive=true And SobjectType = 'Campaign_Design_Profile__c' Limit 1];
- //Creating a test Account
- Account acct = new Account(Name='CampaignDesignProfileTest Account');
- insert acct;
- //Creating a test Opportunity
- Opportunity opp = new Opportunity(Name='CampaignDesignProfileTest Opportunity', AccountId=acct.Id,
- StageName='Needs Analysis', CloseDate=system.today());
- insert opp;
- //Creating a test Campaign Design Profile
- Campaign_Design_Profile__c cdp = new Campaign_Design_Profile__c(Name='CampaignDesignProfileTest cdp',
- Campaign_Type__c='Account Profiling', Related_Opportunity__c=opp.Id);
- cdp.Estimate_Type__c = 'N/A';
- cdp.Volume__c =14.00;
- cdp.of_Hours__c =15.00;
- insert cdp;
- test.stopTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement