You need to sign in to do that
Don't have an account?
prateek khanna 24
Need help in writing this trigger
Milestone and Opportunity Object is there , On Opportunity you have custom field called total Amount, if opportunity is inserted with 10000 as total amount, automatically 10 milesstone should be created.
if the amount is 15000, 15 milesstone should be created and so on.
if the amount is 15000, 15 milesstone should be created and so on.
Please go through the below code:
public class OpportunityMilestoneForum {
public static void createOpportunity(List<Opportunity> oppList)
{
try{
String totalAmount = String.valueOf(oppList[0].Total_Amount__c);
if(totalAmount != null && totalAmount.length() > 4) {
String oppNumber = totalAmount.substring(0,2);
List<MileStone__c> mileStoneList = new List<MileStone__c>();
for(Integer i =0; i<Integer.valueOf(oppNumber); i++)
mileStoneList.add(new MileStone__c(Name='mile stone demo record '+i));
insert mileStoneList;
}
}
catch(Exception ex) {
System.debug('Exception:::'+ex.getMessage()+' at line:: '+ex.getLineNumber());
}
}
}
Here is the trigger:
trigger OpportunityDemo on Opportunity ( after insert) {
if(Trigger.isAfter && Trigger.isInsert)
OpportunityMilestoneForum.createOpportunity(Trigger.New);
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com (http://www.sachinsf.com )
All Answers
Please go through the below code:
public class OpportunityMilestoneForum {
public static void createOpportunity(List<Opportunity> oppList)
{
try{
String totalAmount = String.valueOf(oppList[0].Total_Amount__c);
if(totalAmount != null && totalAmount.length() > 4) {
String oppNumber = totalAmount.substring(0,2);
List<MileStone__c> mileStoneList = new List<MileStone__c>();
for(Integer i =0; i<Integer.valueOf(oppNumber); i++)
mileStoneList.add(new MileStone__c(Name='mile stone demo record '+i));
insert mileStoneList;
}
}
catch(Exception ex) {
System.debug('Exception:::'+ex.getMessage()+' at line:: '+ex.getLineNumber());
}
}
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com (http://www.sachinsf.com )
Thanks for your response,How to call this class using trigger, When I am trying to do so, its showing some error.
Please go through the below code:
public class OpportunityMilestoneForum {
public static void createOpportunity(List<Opportunity> oppList)
{
try{
String totalAmount = String.valueOf(oppList[0].Total_Amount__c);
if(totalAmount != null && totalAmount.length() > 4) {
String oppNumber = totalAmount.substring(0,2);
List<MileStone__c> mileStoneList = new List<MileStone__c>();
for(Integer i =0; i<Integer.valueOf(oppNumber); i++)
mileStoneList.add(new MileStone__c(Name='mile stone demo record '+i));
insert mileStoneList;
}
}
catch(Exception ex) {
System.debug('Exception:::'+ex.getMessage()+' at line:: '+ex.getLineNumber());
}
}
}
Here is the trigger:
trigger OpportunityDemo on Opportunity ( after insert) {
if(Trigger.isAfter && Trigger.isInsert)
OpportunityMilestoneForum.createOpportunity(Trigger.New);
}
I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com (http://www.sachinsf.com )