+ Start a Discussion
taaataaa 

Cloned OPP when met with criteria

Hi, 

I have a trigger that create new OPP based on the criteria(in short it cloned that record with new name). I have product related list on Opp, what the requirement is, when record get cloned, the record in Product, should also get cloned and sit under the Related list of cloned Opp.

 

trigger trg_CreateOpportunityNAwardOnClosedStage_BU on Opportunity (before update) {

       if(!Validator_cls.hasAlreadyDone()){

      

if(Trigger.new[0].RecordTypeId == '012V00000008as6' && Trigger.new.size() == 1 && Trigger.old[0].StageName != Trigger.new[0].StageName && Trigger.new[0].StageName == 'Email Commitment/Closed Won (100%)') {

      

        Opportunity opp = new Opportunity();

        opp.Name = 'Renewed-'+Trigger.new[0].Name;

        opp.StageName = 'Need Analysis (0%) ';

        opp.RecordTypeId = '012V00000008as6';

        opp.AccountId = Trigger.new[0].AccountId;

        opp.CloseDate = System.Today().addmonths(6);

        insert opp;  

}

     Validator_cls.setAlreadyDone();

}

}

 

plz help..

amidstcloudamidstcloud

Hey taaa.

 

I think you need to create the product records too . . So when You are inserting the opp  You need to query all the existing  records of the product associating  Opportunity . then Needs to create the same records with the Cloned Opp Id.

 

Please elaborate the functionality of the  Validator_cls.setAlreadyDone(); function :)

 

Thanks

ankit 

taaataaa

hey Ankit,

 

Validator_cls.setAlreadyDone(); function is used to avoid  recursive trigger. I am working on the part you told, but how can I get cloned opp ID?

 

Thanks,

Riya