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

Clone a record using textfield
I want to clone a record in same object uisng textfield......
For example:
if i have a Quantity__c field in object and fill the field with some numbers like 1,2,3 ....,and i press the save button, automatically it creates 3records or 2records in samke object as per the basis of quantity field uisng triggers(After insert).......
thanks
=========
Venkat Sforce
First off I would clone the object using a number field and not a text field for Quantity. In the example below lets assume the SObject you were wanting to clone was named Service__c.
And here is a basic unit test to verify to works:
Let me know if you have any questions.
All Answers
Why can't you have a parent object having Quantity field ? I don't think DML is allowed in Trigger.new
First off I would clone the object using a number field and not a text field for Quantity. In the example below lets assume the SObject you were wanting to clone was named Service__c.
And here is a basic unit test to verify to works:
Let me know if you have any questions.
trigger CloneonOpportunityQuantity on Account(before insert){integer i ;List<Account> ObjMainAcc = new List<Account>();
for(Account acc : Trigger.New)
{ for(i=0;i<acc.NumberOfEmployees;i++){
Account cloNewAcc = new Account();
cloNewAcc = acc.Clone();
ObjMainAcc.add(cloNewAcc); }
}
if(!ObjMainAcc.Isempty())
insert ObjMainAcc;
}
Set a class (to check the recursive)
public class checkRecussiveValue
{public static boolean chck = true;}
Please follow the above code which is dummy for your requirment.Hope this help you.
let me know whether you find the solution or not.
Regards,
Itsaws.
Thanks jbroquist..........
i got the result........i edit somethings in tht code and got the result....
trigger cloningrecords on Members__c (after insert)
{
if(Trigger.isInsert)
{
Members__c[] memb = new Members__c[]{};
for(Members__c member : Trigger.new)
{
for(Integer i=0; i<member.Quantity__c; i++)
{
for(Members__c oldmember:[Select Id,Name,Member_Intrest__c from Members__c where Id = :member.Id])
{
if(member.Quantity__c != null)
{
Members__c clonedMember = new Members__c();
clonedMember.Quantity__c = null;
clonedMember.Member_Intrest__c = member.Member_Intrest_Name;
clonedMember.Name = member.Name;
memb.add(clonedMember);
}
}
}
if(memb.size() > 0)
{
insert memb;
}
}
}
}