You need to sign in to do that
Don't have an account?
Nani Sircilla
i need to test class for this trigger
Hi all,
i have a trigger and i need test class for this trigger. please check it once and give me appropriate solutions.
trigger OppMailTrigger on Opportunity (after insert) {
Opportunity i=[select ownerid, id,Owner.manager.email,Name from opportunity where id=:trigger.newMap.keySet()];
user s= [select name from User where id=:i.ownerid];
String userEmail = i.Owner.manager.email;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {userEmail};
mail.setToAddresses(toAddresses);
mail.setSubject('Automated email: Opportunity created');
//String body = 'Hello,'+' '+s.name+'\n\n'+' '+'On: '+''+system.now()+'\n'+'New Opportunity : '+' '+i.Name+' '+'is Created..'+'\n'+'Click Here..'+''+'https://www.google.co.in/?gfe_rd=cr&ei=cpZJVfviB6jv8wehxIGoDg#q=html+body+structure';
String body = '<html><body>Hello, '+ s.name+'<br>On: '+ system.now()+'<br><href>https://ankita26-dev-ed.my.salesforce.com/'+ i.id +'</href></body> </html>';
//mail.setPlainTextBody(body);
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
opportunity opp =[SELECT id FROM opportunity Where id in : Trigger.new];
opp.Active__c=true;
update opp;
}
Thank you.
Nani.
i have a trigger and i need test class for this trigger. please check it once and give me appropriate solutions.
trigger OppMailTrigger on Opportunity (after insert) {
Opportunity i=[select ownerid, id,Owner.manager.email,Name from opportunity where id=:trigger.newMap.keySet()];
user s= [select name from User where id=:i.ownerid];
String userEmail = i.Owner.manager.email;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {userEmail};
mail.setToAddresses(toAddresses);
mail.setSubject('Automated email: Opportunity created');
//String body = 'Hello,'+' '+s.name+'\n\n'+' '+'On: '+''+system.now()+'\n'+'New Opportunity : '+' '+i.Name+' '+'is Created..'+'\n'+'Click Here..'+''+'https://www.google.co.in/?gfe_rd=cr&ei=cpZJVfviB6jv8wehxIGoDg#q=html+body+structure';
String body = '<html><body>Hello, '+ s.name+'<br>On: '+ system.now()+'<br><href>https://ankita26-dev-ed.my.salesforce.com/'+ i.id +'</href></body> </html>';
//mail.setPlainTextBody(body);
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEMailMessage[]{mail});
opportunity opp =[SELECT id FROM opportunity Where id in : Trigger.new];
opp.Active__c=true;
update opp;
}
Thank you.
Nani.
You can simply insert a opportunity with all required fields in your test class
test class:
Opportunity objOppt = new Opportunity(Name = 'test');
insert objOppt;
Please perovide all required fields for opportunity and it will work for you..
Thanks
Sandeep
Please try above code to cover the code...But your code is not bulkified as a best practise we should not use soql inside loop...but as per your business need if there will not be bulk insert then it will work...but in bulkinsert thei will fail as it will exceed the limit..
Thanks,
Sandeep