121 lines
5.8 KiB
OpenEdge ABL
121 lines
5.8 KiB
OpenEdge ABL
public class RenewaloppClass{
|
|
public static void RenewalOppMethod(List<Opportunity>Opplist){
|
|
try{
|
|
List<Opportunity> RenewalOpportunities = new List<Opportunity>();
|
|
Id newrectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('New Business').getRecordTypeId();
|
|
Id RenewablerectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewable Business').getRecordTypeId();
|
|
System.debug('@@@@@ +new Business Id:' + newrectypeId);
|
|
System.debug('@@@@@ + Renewable Business Id:' + RenewablerectypeId);
|
|
List<Opportunity>opplist2=new List<Opportunity>(Opplist);
|
|
system.debug('@@@@@+ Getting Data'+opplist2);
|
|
List<Opportunity>opt=new List<Opportunity>();
|
|
for(Opportunity op : Opplist){
|
|
System.debug('@@@@@ Opplist in loop'+Opplist);
|
|
if (op.RecordTypeId == newrectypeId && op.StageName == 'Closed Won') {
|
|
Opportunity renewalOpp = new Opportunity();
|
|
System.debug('@@@@@@ inside the 1st loop' );
|
|
// Set the fields for the Renewal Opportunity
|
|
renewalOpp.RecordTypeId = RenewablerectypeId;
|
|
renewalOpp.Name = op.Name + ' - Renewal';
|
|
renewalOpp.CloseDate = System.today() + 30;
|
|
renewalOpp.StageName = 'Renewal Ready';
|
|
renewalOpp.Parent_Opportunity__c = op.Id;
|
|
renewalOpportunities.add(renewalOpp);
|
|
|
|
}
|
|
else if (op.RecordTypeId == RenewablerectypeId && op.StageName == 'Closed Won'){
|
|
Opportunity renewalOpp = new Opportunity();
|
|
System.debug('@@@@@@ inside the 2nd loop' );
|
|
// Set the fields for the Renewal Opportunity
|
|
renewalOpp.RecordTypeId = RenewablerectypeId;
|
|
renewalOpp.Name = op.Name + ' - Renewal';
|
|
renewalOpp.CloseDate = System.today() + 30;
|
|
renewalOpp.StageName = 'Renewal Ready';
|
|
renewalOpp.Parent_Opportunity__c = op.Id;
|
|
renewalOpportunities.add(renewalOpp);
|
|
|
|
}
|
|
else{
|
|
System.debug('@@@@ nothiggg');
|
|
}
|
|
}
|
|
|
|
insert RenewalOpportunities;
|
|
}
|
|
catch(Exception e){
|
|
System.debug('@@@@@ Error:' + e);
|
|
}
|
|
}
|
|
//For Update....
|
|
public static void RenewaloppMethod2(Map<Id,Opportunity> nMap,Map<Id,Opportunity> oMap){
|
|
try {
|
|
List<Opportunity> RenewalOpportunities = new List<Opportunity>();
|
|
Boolean exist=False;
|
|
Id newrectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('New Business').getRecordTypeId();
|
|
Id RenewablerectypeId = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewable Business').getRecordTypeId();
|
|
|
|
System.debug('@@@@@ +new Business Id:' + newrectypeId);
|
|
System.debug('@@@@@ + Renewable Business Id:' + RenewablerectypeId);
|
|
Set<Id> idd = new Set<Id>(); // Use set<Id> to store Id values
|
|
|
|
//getting id from nMap
|
|
for (Opportunity od1 : nMap.values()) {
|
|
idd.add(od1.Id); // Add the Id value to the list using the add() method
|
|
}
|
|
|
|
|
|
List<Opportunity> oppt = [SELECT Parent_Opportunity__c FROM Opportunity WHERE RecordTypeId=:RenewablerectypeId AND Parent_Opportunity__c IN :idd];
|
|
system.debug('@@@@@ Opppp id value'+oppt);
|
|
|
|
//getting those opportunities which has already child in related And stroring them into set of id
|
|
Set<Id> set1 = new Set<Id>();
|
|
for(Opportunity ol: [SELECT Parent_Opportunity__c FROM Opportunity WHERE RecordTypeId=:RenewablerectypeId AND Parent_Opportunity__c IN :idd]){
|
|
set1.add(ol.Parent_Opportunity__c);
|
|
}
|
|
|
|
//updating value of exist
|
|
for(Opportunity opl :nMap.values()){
|
|
system.debug('@@@@@ in loop');
|
|
if(set1.contains(opl.Id)){
|
|
exist=True;
|
|
system.debug('coantans???'+exist);
|
|
}
|
|
else{
|
|
exist=False;
|
|
system.debug('coantans???'+exist);
|
|
}
|
|
//checking the conditions
|
|
if(oMap.get(opl.Id).StageName!=nMap.get(opl.Id).StageName && nMap.get(opl.Id).StageName=='Closed Won' && exist==False){
|
|
|
|
if (opl.RecordTypeId == newrectypeId || opl.RecordTypeId == RenewablerectypeId ) {
|
|
Opportunity renewalOpp = new Opportunity();
|
|
|
|
system.debug('Making record');
|
|
|
|
// Set the fields for the Renewal Opportunity
|
|
renewalOpp.RecordTypeId = RenewablerectypeId;
|
|
renewalOpp.Name = opl.Name + ' - Renewal';
|
|
renewalOpp.CloseDate = System.today() + 30;
|
|
renewalOpp.StageName = 'Renewal Ready';
|
|
renewalOpp.Parent_Opportunity__c = opl.Id;
|
|
RenewalOpportunities.add(renewalOpp);
|
|
}
|
|
|
|
else{
|
|
System.debug('@@@@@@ no Criteria matched');
|
|
}
|
|
}
|
|
else{
|
|
System.debug('Record already attached');
|
|
}
|
|
|
|
|
|
insert RenewalOpportunities;
|
|
}
|
|
}
|
|
catch(Exception e){
|
|
System.debug('@@@@ Error:' + e);
|
|
}
|
|
}
|
|
|
|
} |