• ksauce
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello!

This is a 2 part question.  I have a class that I created to move the Opportunity stage when a related case status moves.  Currently on the first part of the code works but not the rest of it.  I can get the first stage in the code to carry over but the rest of the stages do nothing.  Also, I would like to ignore this if the Opp stage is closed won.  

Here is the Trigger:
trigger updateOppStageNamefromCaseStatus on Case (after update)
{

    Case[] c = trigger.new;
     
     
     
     UpdateOppStageName.OpportunityRecord(c);


{
}
}


and here is the class I am using.

public with sharing class UpdateOppStageName
{  
    public static void OpportunityRecord(Case[] cases)
    {
        try
        {
        for (Case c: cases)
        {
            String sOppId = (String) c.Opportunity__c;
            List<Opportunity> listOpps = [SELECT Id, StageName FROM Opportunity WHERE Id = :sOppId limit 1];
           
            if(sOppId != '' && sOppId != null )
            {

                if (c.Status == 'Submitted')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Qualified'; }
                    if (listOpps.isEmpty() == false){ update listOpps; } 
                }
                               
                if (c.Status == 'Estimate in Progress')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Estimate in Progress'; }
                    if (listOpps.isEmpty() == false){ update listOpps; } 
                }
               
                if (c.Status == 'Information Needed from Client')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Pending Client Response/Review'; }
                    if (listOpps.isEmpty() == false) { update listOpps; }  
                }
               
                if (c.Status == 'Work in Progress')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Closed Won'; }
                    if (listOpps.isEmpty() == false) { update listOpps; }
                }   
              
                if (c.Status == 'Closed')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Closed Declined'; }
                    if (listOpps.isEmpty() == false){ update listOpps; } 
                
                }
                  
              
                if (c.Status == 'Estimate Pending Client Approval')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Estimate Pending Client Approval'; }
                    if (listOpps.isEmpty() == false){ update listOpps; } 
                
                }
               
               
                if (c.Status == 'Pending Client Acceptance')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Closed Won'; }
                    if (listOpps.isEmpty() == false){ update listOpps; } 
                
                }
                if (c.Status == 'Closed Declined')
                {                
                    for (Opportunity cOpp : listOpps) { cOpp.StageName = 'Closed Declined'; }
                    if (listOpps.isEmpty() == false){ update listOpps; } 
                
                }
                /*
                if(c.Status == 'Closed (Declined)')
                {     
                    for (Opportunity cOpp : listOpps) { cOpp.Status = 'Closed (Declined)'; }
                    if (listOpps.isEmpty() == false) { update listOpps; }  
                }  */
               
            } // if(sCaseId != '' && sCaseId != null)
               
        } // for (Opportunity o: case)
        } // try
        catch(DmlException e)
        {
            System.debug('The following DML exception has occurred: ' + e.getMessage());
        }
        catch(Exception e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
        finally
        {
        }
       
} // public static void CaseRecord(Opportunity[] case)
}


Can anyone help?  I dont know what I am doing wrong?!

  • December 24, 2013
  • Like
  • 0

Hai All,

 

When i was entered the data and saving to Lead,Through VisualForce Page..

It Raising Error...

 

AutomateLeadConversion: execution of AfterUpdate caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Converted objects can only be owned by users. If the lead is not owned by a user, you must specify a user for the Owner field.: [] Trigger.AutomateLeadConversion: line 12, column 1

 

My Trigger :

 

trigger AutomateLeadConversion on Lead (After Update) {
system.debug('Enter to convert Lead');
Lead myLead = trigger.new[0];

if( mylead.Incomplete_Application__c == false && myLead.isconverted==false && myLead.SSN_Not_Eligible__c == false && myLead.No_Govt_Proof_Form__c ==false && myLead.No_Program_List__c == false){
//myLead.LeadSource == 'fax'
system.debug('Enter to convert Lead condition');
database.LeadConvert lc = new database.LeadConvert();
lc.setLeadID(myLead.ID);
lc.convertedstatus = 'Closed - Converted';
lc.setDoNotCreateOpportunity(true);
Database.LeadConvertResult lcr = Database.convertLead(lc); ---->Line 12
System.assert(lcr.isSuccess());

}

}

 

 

 Please suggest me What to do for this....

Thanks,