You need to sign in to do that
Don't have an account?
June Power
Need a test class please please!
I added a trigger on Note with this scenario which works in the sandbox. I also need a test class. Can anyone assist?
trigger UpdateOppLastNote on Note (after insert, after update) { List<Jr_Processing_Tasks__c> oppLstToUpdate=new List<Jr_Processing_Tasks__c>(); if(Trigger.isInsert){ for(Note nt : Trigger.new){ { Jr_Processing_Tasks__c opp=new Jr_Processing_Tasks__c(Id=nt.parentId,Latest_Note__c=nt.Body); oppLstToUpdate.add(opp); } } }if(Trigger.isUpdate){ for(Note nt : Trigger.new){ { if(nt.Body != Trigger.oldMap.get(nt.Id).Body){ Jr_Processing_Tasks__c opp=new Jr_Processing_Tasks__c(Id=nt.parentId,Latest_Note__c=nt.Body); oppLstToUpdate.add(opp); } } } } if(!oppLstToUpdate.isEmpty()){ try{ update oppLstToUpdate; }catch(DmlException de ){ System.debug(de); } } }
Please try the below test class:
@isTest
private class ConTest_Test
{
static testMethod void TestAccount()
{
Jr_Processing_Tasks__c Jr = new Jr_Processing_Tasks__c();
Jr.Name ='Test';
// add all the other required fields to create Jr_Processing_Tasks__c Record
insert Jr;
Note oNote = new Note();
oNote.Title = 'Test Note for Parent';
oNote.Body = 'this is test note';
oNote.parentId = Jr.Id;
Test.startTest();
insert oNote;
oNote.Body ='This is Test 2 ';
Update oNote;
Test.stopTest();
}
}
Can you please Let me know if it works or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, UpdateOppLastNote: execution of AfterInsert caused by: System.TypeException: Invalid id value for this SObject type: 001A000001TiVGwIAN Trigger.UpdateOppLastNote: line 8, column 1: []
Stack Trace: Class.UpdateOppLastNote_Test.TestAccount: line 14, column 1
Please create test class like following class:
Hope this helps you.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Field is not writeable: Jr_Processing_Tasks__c.Name
thanks
Thanks,
Raj
Error:
Class.UpdateOppLastNote_Test.testData: line 8, column 1
ugh... I appreciate any help you can give me.
@isTest
private class ConTest_Test
{
static testMethod void TestAccount()
{
Account a = new Account(Name = 'Test Account Joe ');
insert a;
Opportunity o = new Opportunity();
o.AccountId = a.Id;
o.Name = 'Test_Joe_123';
o.StageName = 'Prospecting';
o.CloseDate = date.today();
o.Type = 'New Business';
insert o;
Jr_Processing_Tasks__c Jr = new Jr_Processing_Tasks__c();
Jr.Status__c = 'Not Started';
Jr.Task__c = 'Payoff';
Jr.Loan__c = 'o.id'; // If its the lookup or Master detail first you have to insert thr test record for that parent Object.
insert Jr;
Note oNote = new Note();
oNote.Title = 'Test Note for Parent';
oNote.Body = 'this is test note';
oNote.parentId = Jr.Id;
Test.startTest();
insert oNote;
oNote.Body ='This is Test 2 ';
Update oNote;
Test.stopTest();
}
}
Can you please Let me know if it works or not!!!
If it helps don't forget to mark this as a best answer!!!
Thanks,
Raj