function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lakshya agrawallakshya agrawal 

trigger for question no.1.2?

Question 1:- Create Trigger to fulfil below Scenarios?
1.1:- If AFAO Type Opportunity is Closed Won, Create new AFAO Opportunity.

Answer:- 

Apex Class:

public class TriggerHandlerOpportunity {
  public static Boolean isFirstTime = true;     
    public static void createNewAFAO(List<Opportunity> oppList,map<id,Opportunity> oldMap){
        List<Opportunity> OpportunityList = new List<Opportunity>();
        for(Opportunity op:oppList){
            if(op.Opportunity_Type__c == 'AFAO' &&  (op.StageName == 'Closed Signed Up (Won)' &&  oldMap.get(op.id).StageName != op.StageName)){
                Opportunity newOpportunity = new Opportunity();
                newOpportunity.Name = op.name;
                newOpportunity.StageName = op.Stagename;
                newOpportunity.CloseDate = op.CloseDate;
                newOpportunity.AccountId = op.AccountId;
                newOpportunity.Opportunity_Type__c = op.Opportunity_Type__c;
                 OpportunityList.add(newOpportunity);
                    
            }
        }
        insert OpportunityList;
        
    } 
}

Trigger:

trigger TriggerOnOpportunity on Opportunity (after update) {
       if(trigger.isafter && trigger.isupdate){
         if(TriggerHandlerOpportunity.isFirstTime ){
        TriggerHandlerOpportunity.isFirstTime = false;
        TriggerHandlerOpportunity.createNewAFAO(trigger.new,trigger.oldmap);
                  }
            } 
    }

1.2  Move all the existing USM Records with the status “Pending” to another AFPO, and "Convo started”/ “Open" to newly created AFAO.

Hint:

 (a) USM Object -Picklist Field “CAC Status”- (Values - Open, Convo started, Closed Won, Closed Lost, Pending) 

(b) Opportunity Object - Piclklist Field "Opportunity Type"-(Values-AFAO,NAFS,AFPO)

(c) Opportunity and Usm have lookup relationship between them.

(d) Opportunity is parent and USM is child.

Can anyone help by writing trigger for it 

Please see question 1.1 first i.e done but 1.2 can be done with help of 1.1.

please help me.
 
lakshya agrawallakshya agrawal
is this the answer for this??

 Move all the existing USM Records with the status “Pending” to another AFPO, and "Convo started”/ “Open" to newly created AFAO.
lakshya agrawallakshya agrawal
can you expalin me this??
 
lakshya agrawallakshya agrawal
not working 
 
lakshya agrawallakshya agrawal
still not working
lakshya agrawallakshya agrawal
Question 1:- Create Trigger to fulfil below Scenarios?
1.1:- If AFAO Type Opportunity is Closed Won, Create new AFAO Opportunity.

Answer:- 

Apex Class:

public class TriggerHandlerOpportunity {
  public static Boolean isFirstTime = true;     
    public static void createNewAFAO(List<Opportunity> oppList,map<id,Opportunity> oldMap){
        List<Opportunity> OpportunityList = new List<Opportunity>();
        for(Opportunity op:oppList){
            if(op.Opportunity_Type__c == 'AFAO' &&  (op.StageName == 'Closed Signed Up (Won)' &&  oldMap.get(op.id).StageName != op.StageName)){
                Opportunity newOpportunity = new Opportunity();
                newOpportunity.Name = op.name;
                newOpportunity.StageName = op.Stagename;
                newOpportunity.CloseDate = op.CloseDate;
                newOpportunity.AccountId = op.AccountId;
                newOpportunity.Opportunity_Type__c = op.Opportunity_Type__c;
                 OpportunityList.add(newOpportunity);
                    
            }
        }
        insert OpportunityList;
        
    } 
}

Trigger:

trigger TriggerOnOpportunity on Opportunity (after update) {
       if(trigger.isafter && trigger.isupdate){
         if(TriggerHandlerOpportunity.isFirstTime ){
        TriggerHandlerOpportunity.isFirstTime = false;
        TriggerHandlerOpportunity.createNewAFAO(trigger.new,trigger.oldmap);
                  }
            } 
    }

1.2  Move all the existing USM Records with the status “Pending” to another AFPO, and "Convo started”/ “Open" to newly created AFAO.

Hint:

 (a) USM Object -Picklist Field “CAC Status”- (Values - Open, Convo started, Closed Won, Closed Lost, Pending) 

(b) Opportunity Object - Piclklist Field "Opportunity Type"-(Values-AFAO,NAFS,AFPO)

(c) Opportunity and Usm have lookup relationship between them.

(d) Opportunity is parent and USM is child.

Can anyone help by writing trigger for it 


it is done with the help of 1.1
lakshya agrawallakshya agrawal
1. Create Picklist Field “CAC Status” on USM Object (Values - Open, Convo started, Closed Won, Closed Lost, Pending) 


2. Create Trigger to fulfil below Scenarios

2.1 If AFAO Type Opportunity is Closed Won, Create new AFAO Opportunity.
2.2 Move all the existing USM Records with the status “Pending” to another AFPO, and "Convo started”/ “Open" to newly created AFAO. 
 
lakshya agrawallakshya agrawal
please reply someone