You need to sign in to do that
Don't have an account?
Koustubh Kulkarni
Create multiple records of same other fields but different one field?
Hello,
I am new to salesforce. I have one junction object called allocation__c which is junction between contact and project__c. Allocation has various fields. after selecting time period(1 week,2 week,1 month,2 months etc.) i want to generate multiple records with same field values but each record for only one week.i.e. if i select 1 month then there should be four records with other parameters remaining same but just change in start and end date. how can we do that??
I am new to salesforce. I have one junction object called allocation__c which is junction between contact and project__c. Allocation has various fields. after selecting time period(1 week,2 week,1 month,2 months etc.) i want to generate multiple records with same field values but each record for only one week.i.e. if i select 1 month then there should be four records with other parameters remaining same but just change in start and end date. how can we do that??
Please use the below code for implementing your requirement, make changes according to your buisness rules :
Let me know if I can help you more.
Thanks,
Vishal
All Answers
You can write down your code in allocation__c trigger.
Please let me know if I can help you in writing that trigger.
Thanks,
Vishal
Please use the below code for implementing your requirement, make changes according to your buisness rules :
Let me know if I can help you more.
Thanks,
Vishal
Alloction is child of Project object or technically say Allocation object has Lookup of Project.
Please mark answer as best answer so it will help others in community.
Thanks,
Vishal
You can write code like this :
customLookupField__r.Name
Thansk,
Vishal
Can you share your code so I can check and let you know.
Thanks,
Vishal
{
//Modify below code with your requirement
public static List<Allocationsperweek__c> createAllocations(Integer vWeeksCount,Allocation__c vProject)
{
Integer startD = 0;
Integer endD = startD + 4;
List<Allocationsperweek__c> lstAllocation = new List<Allocationsperweek__c>();
for( Integer i = 0; i < vWeeksCount; i++ )
{
Allocationsperweek__c allo = new Allocationsperweek__c( Start_Date__c = Date.today().addDays( startD ), End_Date__c = Date.today().addDays( endD ),Allocation__c = vProject.Id,Allocated_Percentage__c=vProject.Allocated_Percentage__c,Employee_name__c=vProject.Employee_name__r.Name,Project_Name__c=vProject.Project_Name__r.Name,Reported_By__c=vProject.Reported_By__r.Name);
lstAllocation.add(allo);
startD += 7;
EndD += 7;
}
return lstAllocation;
}
//Modify below code with your requirement
public static Integer getNumberOfWeeks(String vTimePeriod)
{
if(vTimePeriod == '1 Week')
return 1;
else if(vTimePeriod == '2 Week')
return 2;
else if(vTimePeriod == '3 Week')
return 3;
else if(vTimePeriod == '1 Month')
return 4;
else if(vTimePeriod == '2 Month')
return 8;
else if(vTimePeriod == '3 Month')
return 12;
return 0;
}
}
Please do query on the related objects to get the value, in trigger we can't get the related fields value directly, we need to do query first and then can access it.
Thanks,
Vishal