You need to sign in to do that
Don't have an account?
create records on the basis of multiselect values
Apex trigger oppsplicreate caused an unexpected exception, contact your administrator: oppsplicreate: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, oppsplicreate: maximum trigger depth exceeded Opportunity_Splits trigger event AfterInsert
- Whenever an opportunity is created an opportunity split record should be created with the practice same as that of opportunity and percentage as 100. (If the practice is one)
- If there are two practices then whenever an opportunity is created two opportunity split records should be created with the practices same as that of opportunity and each with 50% share
Sum of the two should always be equal to 100%
trigger oppsplicreate on Opportunity_Splits__c(after delete, after insert, after update){
set<Id> OpportunityIds = new set<Id>();
List<Opportunity_Splits__c> opportunitySplitList = new List<Opportunity_Splits__c>();
if(trigger.isInsert || trigger.isUpdate)
{
for(Opportunity_Splits__c p : trigger.new)
{
OpportunityIds.add(p.Opportunity__c);
opportunitySplitList.add(p);
system.debug('-----opportunitySplitList--------'+opportunitySplitList);
}
}
List<Opportunity_Splits__c> lstCon = new List<Opportunity_Splits__c>();
Opportunity oppt= [Select Id, Practiceu__c FROM Opportunity WHERE id IN :OpportunityIds];
// Opportunity oppt=[SELECT Name from Opportunity where Practiceu__cIN :multselect.split(';')
system.debug('-----oppt--------'+oppt);
String str = oppt.Practiceu__c ;
system.debug('-----str --------'+str );
if(str !=null)
{
List<String> lstValues = str.split(';');
for(String pkValue: lstValues)
{
Opportunity_Splits__c con = new Opportunity_Splits__c(Opportunity__c = oppt.Id, Practice__c =pkValue);
lstCon.add(con);
}
insert lstCon;
}
}
tell if you need to add the percentage
Kindly mark as best answer if this solves your problem
Update this code in batch job, and then try.
Thanks,
Gaurav
Skype: gaurav2990
and the idea is if the practice has two values like (value1; value 2), two opportunities splits will be created ? if it has 3 values,, so 3 opps split will be created?