You need to sign in to do that
Don't have an account?
Shawn Nguyen
Auto-populate related contact with new Opportunity
We have a field on the Account calls Relationship_Manager__c that looks up to a contact record. We want whenever an opportunity is created, the same lookup relationship is created on the Opportunity record field calls Relationship_Manager__c. I know WF can't accomplish and that only a trigger would do. Can anyone help with the trigger and test code?
Thanks in advance!
Thanks in advance!
Trigger:
Test:
If this resolves your purpose, please mark this topic as solved.
@isTest
public with sharing class TestRelationshipManager {
static testMethod void testOpportunities(){
//insert records
Contact c1 = new Contact(lastname = 'test', Nickname__c='test');
insert c1;
Account a1 = new Account(name = 'test1', Account_Type__c='non-Member', Industry='Banking', Relationship_Manager__c = c1.id);
insert a1;
Opportunity o1 = new Opportunity(name = 'test2');
o1.stageName = 'Target';
o1.closeDate = System.today()+10;
o1.AccountID = a1.id;
insert o1;
//check whether field is updated correctly
System.assertEquals(o1.relationship_manager__c,c1.id);
}
}
Error Message: System.AssertException: Assertion Failed: Expected: null, Actual: 003R000000oeLzzIAE