You need to sign in to do that
Don't have an account?
Dev2India
Help in Test class
trigger createSplitCommissionOnOpportunityX on Opportunity (after insert, after update) {
List<Split_Commissions__c> SCToInsert = new List<Split_Commissions__c> ();
for (Opportunity o : Trigger.new) {
if ( ((Trigger.isInsert) ||
(Trigger.isUpdate) && (Trigger.oldMap.get(o.id).StageName != 'Closed Won')) &&
(o.StageName == 'Closed Won') )
{
Split_Commissions__c SC = new Split_Commissions__c ();
sc.Opportunity_Name__c = o.id;
SCToInsert.add(sc);
}//end if
}//end for o
//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
insert SCToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
PLease help us to create the test class for the above code.
Thanks,
List<Split_Commissions__c> SCToInsert = new List<Split_Commissions__c> ();
for (Opportunity o : Trigger.new) {
if ( ((Trigger.isInsert) ||
(Trigger.isUpdate) && (Trigger.oldMap.get(o.id).StageName != 'Closed Won')) &&
(o.StageName == 'Closed Won') )
{
Split_Commissions__c SC = new Split_Commissions__c ();
sc.Opportunity_Name__c = o.id;
SCToInsert.add(sc);
}//end if
}//end for o
//once loop is done, you need to insert new records in SF
// dml operations might cause an error, so you need to catch it with try/catch block.
try {
insert SCToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
PLease help us to create the test class for the above code.
Thanks,
@isTest
public class createSplitCommissionOnOpportunityXTest{
public static testMethod void createSplitCommissionOnOpportunityXTest(){
Opportunity o=new Opportunity();
o.Name='Test Opportunity';
o.CloseDate=System.Today();
o.StageName='Closed Won';
insert o;
Split_Commissions__c s=new Split_Commissions__c();
s.Opportunity_Name__c=o.id;
insert s;
}
}
All Answers
In the trigger you should create a new opportunity and set the stage to Closed Won
Once created , give a name to the split commision(in the code) and query to see if it created.
This should test the working of the trigger - code sample available on the following link :
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm
I'd suggest you to start coding and you can post here f yu face any issues.
Invalid constructor syntax, name=value pairs can only be used for SObjects
Someone please help to wirte the test class for the same.
Thanks and appreciate for the help.......
Invalid constructor syntax, name=value pairs can only be used for SObjects
Someone please help to wirte the test class for the same.
Thanks and appreciate for the help.......
@isTest
public class createSplitCommissionOnOpportunityXTest{
public static testMethod void createSplitCommissionOnOpportunityXTest(){
Opportunity o=new Opportunity();
o.Name='Test Opportunity';
o.CloseDate=System.Today();
o.StageName='Closed Won';
insert o;
Split_Commissions__c s=new Split_Commissions__c();
s.Opportunity_Name__c=o.id;
insert s;
}
}
Thanks for the help.