You need to sign in to do that
Don't have an account?
guna malli
How to test class for after update trigger
How to write test class for this trigger
Here S__c different object, and R__c is different object in between no relationship
but S__c have this fields like A__c,B__c,C__c. same like that R__c have same fields
when ever S__c "status" have aprroved i want update the R__c "status" field completed
trigger Sname on S__c (after update) {
for(S__c s : Trigger.new){
if(s.Status__c == 'Approved'){
R__c R = [select id,Status__c from R__c where (A__c =: s.A__c and B__c =: s.B__c and C__c =: s.C__c)];
R.Status__c ='Completed';
update R;
}
}
}
Here S__c different object, and R__c is different object in between no relationship
but S__c have this fields like A__c,B__c,C__c. same like that R__c have same fields
when ever S__c "status" have aprroved i want update the R__c "status" field completed
trigger Sname on S__c (after update) {
for(S__c s : Trigger.new){
if(s.Status__c == 'Approved'){
R__c R = [select id,Status__c from R__c where (A__c =: s.A__c and B__c =: s.B__c and C__c =: s.C__c)];
R.Status__c ='Completed';
update R;
}
}
}
All Answers
Thanks for your quick replay.this test class is working fine.thank you somuch LBK
i am new developer in sfdc please help me easy way to write test classes.
how to call subclasses,methods,and if else and for condition.please send some links or materials you have?
Thanks & best Regards
Guna
There are basic syntax / keywords like @isTest, @isTest(SeeAllData=true), startTest, stopTest, etc...
You need to learn all of them.
For code coverage improvment, I suggest reading your code, understand the logic flow and prepare test data accordingly.
For example, if you have a condition check like below. These lines of code says that you need at least three opportunity records created (in your test data) with three different opportunity stages to get all three conditions covered.
More the number of conditions, more the number of test records to be created.
Does this make sense?
Please check the below trigger.this trigger same like above trigger but added 1 line how to call that one please help me
when click on runtest shown error like this "Method doen't exist getcontact();"
Here S__c different object, and R__c is different object in between no relationship
but S__c have this fields like A__c,B__c,C__c. same like that R__c have same fields
when ever S__c "status" have aprroved i want update the R__c "status" field completed
trigger Sname on S__c (after update) {
for(S__c s : Trigger.new){
if(s.Status__c == 'Approved'){
R__c R = [select id,Status__c from R__c where (A__c =: s.A__c and B__c =: s.B__c and C__c =: s.C__c)];
R.Status__c ='Completed';
update R;
LogController.fromTrigger(sid); // this is new line (Here "Logcontroller" is onemore new apexclass,in that class have method like "fromtrigger"that method calling here .when click on runtest shown error like this "Method doen't exist getcontact();")
}
}
}
This has to be an exception from the fromTrigger method. I cannot comment on it, unless I take a look at the code. Also, you are passing an attribute called sid to the fromTrigger method (in the above line of code). Where are you getting it from?
Here S__c different object, and R__c is different object in between no relationship
but S__c have this fields like A__c,B__c,C__c. same like that R__c have same fields
when ever S__c "status" have aprroved i want update the R__c "status" field completed
trigger Sname on S__c (after update) {
for(S__c s : Trigger.new){
String message = '';
if(s.Status__c == 'Approved'){
R__c R = [select id,Status__c from R__c where (A__c =: s.A__c and B__c =: s.B__c and C__c =: s.C__c)];
R.Status__c ='Completed';
update R;
message =('site'+'S.Name'+'is Approved');
}else if(s.Status__c == 'Submitted') {
message =('site'+'S.Name'+'is Submitted');
}else if(s.Status__c == 'Reviewed'){
message =('site'+'S.Name'+'is Reviewed');
}else if(s.Status__c == 'Rejected'){
message ='site'+'S.Name'+'is Rejected');
}
String TMTO = ('1345678');
LES.LSS(message, TMTO);
}
}