You need to sign in to do that
Don't have an account?
sundhar.mks1.3962649227519546E12
How to create new opportunity? when a Case is Closed.
Hi,
Case object have picklist field of Stage = Closed "Stage is a picklist field"
Case object have picklist field of Stage = Closed "Stage is a picklist field"
Below is the code.
Best Regrads,
Mithun.
All Answers
Below is the code.
Best Regrads,
Mithun.
It's working Perfect.Many Thanks..!
How to write the test class for this? Kindly help me
Here is test class Mark this as Best Answer, if it solves your proble.
Best Regards,
Mithun.
============================
Public class CasetriggerHandler{
Public void OnAfterInsert(map<id,Case> CaseNewMap,map<id,Case> CaseOldMap){
CreateNewOpp(CaseNewMap.values());
}
Public void OnAfterUpdate(map<id,Case> CaseNewMap,map<id,Case> CaseOldMap){
CreateNewOpp(CaseNewMap.values());
}
Public void CreateNewOpp(List<Case> NewCaseList){
List<Opportunity> oppList= New List<Opportunity>();
For(Case Cs: NewCaseList){
System.Debug('==========='+NewCaseList);
IF(Cs.nbfg__Status__c=='Closed'){
Opportunity opp=new Opportunity();
System.Debug('======Op======'+Opp);
opp.accountid = cs.accountid;
opp.name = 'New Opportunity -' + cs.casenumber;
opp.stageName = 'Prospecting';
opp.nbfg__Case__c=cs.casenumber;
opp.closedate = system.today();
opplist.add(opp);
}
}
if(oppList.size() > 0){
insert opplist;
}
}
}
Share your trigger code and error details.
Best Regards,
Mithun.
Code
===============
@isTest(SeeAllData=true)
public class CasetriggerHandlerTest
{
public static void CreateNewOpptest(){
account acc = new account(name = 'test acc for case');
insert acc;
case cs = new case (accountid = acc.id, status = 'closed', origin = 'Phone');
insert cs;
}
}
Error:
Compile Error: Invalid constructor syntax, name=value pairs can only be used for SObjects at line 5 column 20
I asked for your trigger code.
Best Regards,
Mithun.
Trigger
==============
trigger Casetrigger on Case (After insert, After update){
CasetriggerHandler handler = new CasetriggerHandler();
if(trigger.isAfter && trigger.IsInsert){
handler.OnAfterInsert(trigger.newmap, Trigger.OldMap);
}
if(trigger.isAfter && trigger.IsUpdate){
handler.OnAfterUpdate(trigger.newmap, Trigger.OldMap);
}
}
I need to write the test class for following class
Apex Class
====================
Public class CasetriggerHandler{
Public void OnAfterInsert(map<id,Case> CaseNewMap,map<id,Case> CaseOldMap){
CreateNewOpp(CaseNewMap.values());
}
Public void OnAfterUpdate(map<id,Case> CaseNewMap,map<id,Case> CaseOldMap){
CreateNewOpp(CaseNewMap.values());
}
Public void CreateNewOpp(List<Case> NewCaseList){
List<Opportunity> oppList= New List<Opportunity>();
For(Case Cs: NewCaseList){
System.Debug('==========='+NewCaseList);
IF(Cs.nbfg__Status__c=='Closed'){
Opportunity opp=new Opportunity();
System.Debug('======Op======'+Opp);
opp.accountid = cs.accountid;
opp.name = 'New Opportunity -' + cs.casenumber;
opp.stageName = 'Prospecting';
// opp.nbfg__Case__c=cs.casenumber;
opp.closedate = system.today();
opplist.add(opp);
}
}
if(oppList.size() > 0){
insert opplist;
}
}
}
I have tested your trigger, trigger helper class and test class (all 3) in my dev org, everything is working fine.
If want you can copy and try them in your dev org.
I think there may be some other triggers are firing on Case or Account or Opprtunity etc.. in your current org. Please check the error message properly that where it is pointing out and try to fix that trigger or class.
Best Regards,
Mithun.
How to Send all the product information to the primary contact of the opportunity,Kindly give any idea?
Thanks
I have Completed test class,
@isTest(SeeAllData=true)
public class CasetriggerHandlerTest
{
@isTest public static void CreateNewOpptest(){
//Inserting New Case record Creation
Case newcase = new Case();
newcase.nbfg__Status__c = 'New';
newcase.Status = 'Working';
insert newcase;
// Updating the Case record
List<Case> NewListCase = new List<Case>();
Case Caselist = [Select id,nbfg__Status__c,casenumber from Case Where id=:newcase.id Limit 1];
Caselist.nbfg__Status__c = 'Closed';
NewListCase.add(Caselist);
Update NewListCase;
//Inserting New Opportunity Record
Opportunity NewOpp = new Opportunity();
NewOpp.name = 'New Opportunity -' + Caselist .casenumber;
NewOpp.stageName = 'Prospecting';
NewOpp.closedate = system.today();
insert NewOpp;
}
}
Thanks.