Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Here, Test__c is a custom object.
trigger CreateCustomObjRec on Opportunity (after insert, after update) {
List <Test__c> testRec = new List <Test__c> ();
for (Opportunity o : Trigger.new) {
if (o.StageName == 'Closed Won'){
Test__c s = new Test__c ();
s.Name = o.Name;
// Map other fields if you want
testRec.add(s);
}
}
try {
INSERT testRec;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Here, Test__c is a custom object.
trigger CreateCustomObjRec on Opportunity (after insert, after update) {
List <Test__c> testRec = new List <Test__c> ();
for (Opportunity o : Trigger.new) {
if (o.StageName == 'Closed Won'){
Test__c s = new Test__c ();
s.Name = o.Name;
// Map other fields if you want
testRec.add(s);
}
}
try {
INSERT testRec;
} catch (system.Dmlexception e) {
system.debug (e);
}
}
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Here, Test__c is a custom object.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Here, Test__c is a custom object.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks and Regards,
Khan Anas
It is working fine in my org. Please share your code.
Regards,
Khan Anas
List<Candidate__c> candlist=new list<Candidate__c>();
for(opportunity opp:trigger.new){
if(opp.stagename=='closed won'){
Candidate__c t=new Candidate__c();
t.Name = opp.Name;
candlist.add(t);
}
}
insert candlist;
}
It is working fine. The record is creating in a custom object. You just need to select "All" from your custom object List View.
I hope it helps you.
Kindly mark this as solved if the information was helpful.
Thanks and Regards,
Khan Anas
Thank you i got it.
Below Sample Code can fulfill your requirements, Hope this will work for you.
Please mark this as best answer if this solves your problem.
Thank you
Ajay Dubedi