+ Start a Discussion
k practicek practice 

How to create a trigger on the case that will automatically make that opportunity when the case is escalated?

PratikPratik (Salesforce Developers) 
Hi,

Do you want to create an opportunity record when case is escalated? What all details you want to populate in opportunity? Please elaborate.

Thanks,
Pratik
k practicek practice
This is my requirement .I am new Triggers

When a case is saved and case.tier = “6 - Tech Lead”

First, see if there are any opportunities of record type “Professional Service Change Order” already associated with this case through the Originating Case field on an opportunity, if so, stop. We do not want to create another Change Order opportunity.

If no other “Professional Service Change Order” opportunities are associated with this case, then make a new opportunity using the following field settings:

Opportunity Record Type: Professional Service Change Order
Opportunity Name: {account name} - {case subject}
Close Date: {today + 30}
Amount: leave this blank
Stage = “Change Order Create”
Change Order Requested = today()
Opportunity Owner = case.account_name.owner (the account owner of the account associated with the case)
Opportunity.Originating_Case (new field, please create this), populate with the originating case

please help me........
Vijay NagarathinamVijay Nagarathinam
Try this code,
 
trigger autoCreatOpp on Case (after insert, after update) 
{
list<Opportunity> getOpp = new list<Opportunity>();
list<Opportunity> newOpp = new list<Opportunity>();

set<id> caseid = new set<id>();
for(Case newCase : Trigger.new)
{
if(newcase.status == 'Escalated')
caseid.add(newCase.id);
}

getOpp = [select id,recordtypeid,Orginating_Case__c  from Opportunity where recordtype.name='Professional_Service_Change_Order' and Orginating_Case__c =: caseid ];

for(Case c : [select id,status,casenumber,accountid,subject from case where id =: caseid ])
{
if(getOpp.size() == 0)
{
Opportunity opp = new Opportunity();
opp.name = c.accountid +'-'+ c.subject;
opp.accountid = c.accountid;
opp.recordtypeid='012j0000000WH2U';
opp.closedate = system.today()+30;
opp.stagename = 'Open';
opp.Orginating_Case__c = c.casenumber;
newOpp.add(opp);
}
}
insert newOpp;
}

 
k practicek practice
This code not working for me........