You need to sign in to do that
Don't have an account?
brijender singh rathore 16
TEST CLASS FOR ROLLUP
latest__c is rollup summary field = max(opportunity).This trigger is mapping latest opportunity amount into account field (acc.opty_amount__c).
trigger latest on Account (after update) {
if(checkRecursive.runOnce())
{ set<id> acctid =new set<id>();
list<account> accnt=new list<account>();
for(account acc:trigger.new)
{ acctid.add(acc.id); }
for(account acc : [select id,name,opty_amount__c,latest__c(select id,amount,CreatedDate from opportunities) from account where id in:acctid]) { list <opportunity> oppo = acc.opportunities;
for(opportunity op:oppo)
{ if(acc.latest__c == op.CreatedDate)
{ acc.opty_amount__c=op.amount;
}
}
accnt.add(acc);
}
update accnt;
}
THIS TEST CLASS IS GIVING 80% COVERAGE PLZ HELP ME TO CONVERT IT TO 100%.
@isTest
private class UpdateAccount_Test
{ public static testMethod void TestUpdateAccount()
{ Account acc = new Account();
acc.Name = 'Test';
insert acc;
opportunity oppo = new opportunity();
oppo.accountid =acc.id;
oppo.amount = 50000.00;
update acc;
}
}
trigger latest on Account (after update) {
if(checkRecursive.runOnce())
{ set<id> acctid =new set<id>();
list<account> accnt=new list<account>();
for(account acc:trigger.new)
{ acctid.add(acc.id); }
for(account acc : [select id,name,opty_amount__c,latest__c(select id,amount,CreatedDate from opportunities) from account where id in:acctid]) { list <opportunity> oppo = acc.opportunities;
for(opportunity op:oppo)
{ if(acc.latest__c == op.CreatedDate)
{ acc.opty_amount__c=op.amount;
}
}
accnt.add(acc);
}
update accnt;
}
THIS TEST CLASS IS GIVING 80% COVERAGE PLZ HELP ME TO CONVERT IT TO 100%.
@isTest
private class UpdateAccount_Test
{ public static testMethod void TestUpdateAccount()
{ Account acc = new Account();
acc.Name = 'Test';
insert acc;
opportunity oppo = new opportunity();
oppo.accountid =acc.id;
oppo.amount = 50000.00;
update acc;
}
}
Please check once following code. Hope this helps you!
Thanks
Varaprasad
For Support: varaprasad4sfdc@gmail.com
Error: Compile Error: Field is not writeable: Account.latest__c at line 13 column 13
* note you need to do SOQL to get the latest__c field.
THIS ONE IS GIVING 100% COVERAGE
***I THINK DOING SOQL IN TEST CLASS IS CONSIDERED A BAD PRACTICE. (PLZ CORRECT ME IF I AM WRONG) *****
@isTest
private class UpdateAccount_Test{
public static testMethod void TestUpdateAccount() {
Account acc = new Account();
acc.Name = 'Test';
insert acc;
opportunity oppo = new opportunity();
oppo.name = 'bsr';
oppo.amount = 50000.00;
oppo.StageName = 'Closed Won';
oppo.CloseDate = system.today();
oppo.accountid =acc.id;
insert oppo;
update acc;
}
}