You need to sign in to do that
Don't have an account?

Cloned OPP when met with criteria
Hi,
I have a requirement, when Opportunity stage met with "closed won", i want cloned Opp with the name different. I got this, however autonumber I am not getting.
For eg: I have a Opp name: Aux, when it met with the criteria, cloned Opp name should be "Aux Ren 1",again Aux met with the same criteria, cloned Opp name should be "AUX REN 2".
here is my code:
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%)') {
Trigger.new[0].check__c=true;
Opportunity opp = new Opportunity();
opp.Name = Trigger.new[0].Name +'Ren';
opp.StageName = 'Need Analysis (0%) ';
opp.RecordTypeId = '012V00000008as6';
opp.AccountId = Trigger.new[0].AccountId;
opp.CloseDate = System.Today().addmonths(6);
insert(opp);
}
Regards
}
Validator_cls.setAlreadyDone();
}
If you are going to follow the same naming format to all your opprtunity names, then you can use indexof to find the whether Ren is available and then split the opp name to get the current number.
hi, Thanx fr the reply..could you gve code snippet for that...
You can try
if(opp.Name.indexof('Ren') != -1){
Integer i = opp.Name.lastindexof('Ren');
String s = opp.Name.substring(i+1,opp.Name.length());
}
Apex trigger trg_CreateOpportunityNAwardOnClosedStage_BU caused an unexpected exception, contact your administrator: trg_CreateOpportunityNAwardOnClosedStage_BU: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.trg_CreateOpportunityNAwardOnClosedStage_BU: line 17, column 1
getting this error while saving the record..
Can you post the code you have written??
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();
if(Trigger.new[0].Name.indexof('Ren') != -1){
Integer i = Trigger.new[0].Name.lastindexof('Ren');
string s = Trigger.new[0].Name.substring(i+1,Trigger.new[0].Name.length());
opp.Name = 'Ren-'+Trigger.new[0].Name+i ;
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();
}
}