You need to sign in to do that
Don't have an account?
rajesh kumar 50
Hi i am new to test classes can any one help me writing test class for the below trigger..
Here Is my Trigger:
trigger opportunityinsertupdate on Opportunity (before insert,before update) {
if(checkRecursive.runOnce()) {
Set<Id> accountIds = new Set<Id>();
for(Opportunity currentOpportunity: Trigger.New) {
accountIds.add(currentOpportunity.AccountId);
}
Map<Id, Account> accountMap = new Map<Id, Account>([Select Id, Super_Region__c from Account Where Id in:accountIds]);
boolean flag=True;
if(Trigger.isInsert){
for(Opportunity opp: trigger.New){
system.debug('opp.name.===='+opp.name);
if(opp.name != null){
if(opp.name.startsWith('FO-')){
opp.CampaignId = '701U0000000QsAA';
}
}
}
for(opportunity o : trigger.new) {
if(accountMap.get(o.AccountId) != null) {
if(((o.Record_Type_Name__c == 'NC Power')||(o.Record_Type_Name__c == 'NC Oil & Gas')||(o.Record_Type_Name__c == 'NC Nuclear')) &&(o.stagename == 'Closed Won') && (o.FS_Included__c == false) && accountMap.get(o.AccountId).Super_Region__c == 'Asia/India') {
o.Name = o.Name + ' - FS Opp';
o.RecordTypeId = '012U0000000UIoX';
o.stagename = 'Sales Lead';
o.amount = 1;
o.CurrencyIsoCode = 'USD';
o.Target_ShipDate__c = o.CloseDate.addmonths(3);
flag = false;
o.FS_Included__c = true;
}
}
}
}
if(trigger.isUpdate && flag) {
for(opportunity o1:trigger.new) {
if(accountMap.get(o1.AccountId) != null) {
if(((o1.Record_Type_Name__c == 'NC Power')||(o1.Record_Type_Name__c == 'NC Oil & Gas')||(o1.Record_Type_Name__c == 'NC Nuclear')) &&(o1.stagename == 'Closed Won') && (o1.FS_Included__c == false) && accountMap.get(o1.AccountId).Super_Region__c == 'Asia/India') {
Opportunity o2= new opportunity();
o2.name = o1.name+' - Fsopp';
o2.CloseDate = o1.CloseDate;
o2.RecordTypeId = '012U0000000UIoX';
o2.stagename = 'Sales Lead';
o2.amount = 1;
o2.CurrencyIsoCode = 'USD';
o2.Target_ShipDate__c = o1.CloseDate.addmonths(3);
o2.FS_Included__c = true;
insert o2;
}
}
}
}
}
}
please help me writing the test class for this trigger
thanks in advance..
trigger opportunityinsertupdate on Opportunity (before insert,before update) {
if(checkRecursive.runOnce()) {
Set<Id> accountIds = new Set<Id>();
for(Opportunity currentOpportunity: Trigger.New) {
accountIds.add(currentOpportunity.AccountId);
}
Map<Id, Account> accountMap = new Map<Id, Account>([Select Id, Super_Region__c from Account Where Id in:accountIds]);
boolean flag=True;
if(Trigger.isInsert){
for(Opportunity opp: trigger.New){
system.debug('opp.name.===='+opp.name);
if(opp.name != null){
if(opp.name.startsWith('FO-')){
opp.CampaignId = '701U0000000QsAA';
}
}
}
for(opportunity o : trigger.new) {
if(accountMap.get(o.AccountId) != null) {
if(((o.Record_Type_Name__c == 'NC Power')||(o.Record_Type_Name__c == 'NC Oil & Gas')||(o.Record_Type_Name__c == 'NC Nuclear')) &&(o.stagename == 'Closed Won') && (o.FS_Included__c == false) && accountMap.get(o.AccountId).Super_Region__c == 'Asia/India') {
o.Name = o.Name + ' - FS Opp';
o.RecordTypeId = '012U0000000UIoX';
o.stagename = 'Sales Lead';
o.amount = 1;
o.CurrencyIsoCode = 'USD';
o.Target_ShipDate__c = o.CloseDate.addmonths(3);
flag = false;
o.FS_Included__c = true;
}
}
}
}
if(trigger.isUpdate && flag) {
for(opportunity o1:trigger.new) {
if(accountMap.get(o1.AccountId) != null) {
if(((o1.Record_Type_Name__c == 'NC Power')||(o1.Record_Type_Name__c == 'NC Oil & Gas')||(o1.Record_Type_Name__c == 'NC Nuclear')) &&(o1.stagename == 'Closed Won') && (o1.FS_Included__c == false) && accountMap.get(o1.AccountId).Super_Region__c == 'Asia/India') {
Opportunity o2= new opportunity();
o2.name = o1.name+' - Fsopp';
o2.CloseDate = o1.CloseDate;
o2.RecordTypeId = '012U0000000UIoX';
o2.stagename = 'Sales Lead';
o2.amount = 1;
o2.CurrencyIsoCode = 'USD';
o2.Target_ShipDate__c = o1.CloseDate.addmonths(3);
o2.FS_Included__c = true;
insert o2;
}
}
}
}
}
}
please help me writing the test class for this trigger
thanks in advance..
public class Testopportunityinsertupdate{
static testmethod void testmethod1(){
acccount acc=new account();
acc.Name='testacc';
insert acc;
Opportunity objopp=new Opportunity();
objopp.name='FO-Test';
objopp.Account=acc.id;
objopp.Record_Type_Name__c='NC Power';
insert objopp;
opportunity opp=[select Record_Type_Name__c from opportunity where id=:objopp];
opp.Record_Type_Name__c='NC Oil & Gas';
update opp;
}
}