You need to sign in to do that
Don't have an account?
Michael Webb 5
Need urgent help writing a test class
trigger PropOwned on Contact (after update) {
for (Contact c : Trigger.new){
McLabs2__Ownership__c ownNew= new McLabs2__Ownership__c();
Contact oldContact = Trigger.oldMap.get(c.id);
if (c.One_Prop_Owned__c != oldContact.One_Prop_Owned__c && c.One_Prop_Owned__c != null){
ownNew.McLabs2__Contact__c = c.id;
ownNew.McLabs2__Property__c = c.One_Prop_Owned__c;
insert ownNew;
}
}
}
This is the trigger, I need to move it into production. I was able to write a test class that created a new ownership, but then I realized that was not correct. I have tried a million different things and none have worked. This was my original, that obviously didn't work I realize it is because I need to create a contact record and then update it, just don't know how.
Thank you very much in advance.
@isTest
public class TestOwnership {
static testMethod void createOwnership() {
McLabs2__Ownership__c ownNew= new McLabs2__Ownership__c();
ownNew.McLabs2__Contact__c = 'Michael Webb';
ownNew.McLabs2__Property__c = '131 West 33rd Street';
insert ownNew;
}
}
Thanks again!
for (Contact c : Trigger.new){
McLabs2__Ownership__c ownNew= new McLabs2__Ownership__c();
Contact oldContact = Trigger.oldMap.get(c.id);
if (c.One_Prop_Owned__c != oldContact.One_Prop_Owned__c && c.One_Prop_Owned__c != null){
ownNew.McLabs2__Contact__c = c.id;
ownNew.McLabs2__Property__c = c.One_Prop_Owned__c;
insert ownNew;
}
}
}
This is the trigger, I need to move it into production. I was able to write a test class that created a new ownership, but then I realized that was not correct. I have tried a million different things and none have worked. This was my original, that obviously didn't work I realize it is because I need to create a contact record and then update it, just don't know how.
Thank you very much in advance.
@isTest
public class TestOwnership {
static testMethod void createOwnership() {
McLabs2__Ownership__c ownNew= new McLabs2__Ownership__c();
ownNew.McLabs2__Contact__c = 'Michael Webb';
ownNew.McLabs2__Property__c = '131 West 33rd Street';
insert ownNew;
}
}
Thanks again!
You triggering point is contact update.Please try below code for test class and update it if needed:
All Answers
You triggering point is contact update.Please try below code for test class and update it if needed:
System.StringException: Invalid id: 131 West 33rd Street