You need to sign in to do that
Don't have an account?
John Stamers
Apex Trigger: Create a new record when an existing record is updated to meet certain criteria
Hi all, I want to preface this by saying I have absolutley zero knowledge of coding and how to write an apex trigger. However, I do know the result i'm trying to achieve so I'm hoping my description will be enough for someone to provide some help.
My situation is the following: I have 2 custom objects Volunteer and Subject. What I want to happen is that when a certain field (Volunteer_Status__c), a picklist value, is updated to the selection "Screening Completed" a new record is created under the Subject object that replicates the information stored under the volunteer record.
If someone could provide some instruction it would be much appreciated!
My situation is the following: I have 2 custom objects Volunteer and Subject. What I want to happen is that when a certain field (Volunteer_Status__c), a picklist value, is updated to the selection "Screening Completed" a new record is created under the Subject object that replicates the information stored under the volunteer record.
If someone could provide some instruction it would be much appreciated!
Trigger copyVolunteertoSubject on Volunteer__c(after insert, after update)
{
List<Subject__c> sub=new List<Subject__c>();
for(Volunteer__c v : Trigger.new)
{
if(v.Volunteer_Status__c == 'Screening Completed')
{
Subject__c s=new Subject__c();
s.Name=v.Name;
//add other fields of subject here and add volunteer values in that.
sub.add(s);
}
if(sub.size()>0)
insert sub;
}
}
All Answers
Trigger copyVolunteertoSubject on Volunteer__c(after insert, after update)
{
List<Subject__c> sub=new List<Subject__c>();
for(Volunteer__c v : Trigger.new)
{
if(v.Volunteer_Status__c == 'Screening Completed')
{
Subject__c s=new Subject__c();
s.Name=v.Name;
//add other fields of subject here and add volunteer values in that.
sub.add(s);
}
if(sub.size()>0)
insert sub;
}
}
How would htis trigger change if i wanted the Subject object that has been created to also be created as a child record of another object called Trial? Trial currently has a lookup relationship with the Volunteer object.
Could you advise?
I need that trigger to run every day for checking all records that have date__c = today() and then create for this records the Subject records. How can this be done?
Thanks in advance!
I do not need the company field as required. I followed your comments but the visibility could not be changed. please help
i have similar kind of requirement like John Stamers, I have one custom object(Application__c) and standard object (Contact), when picklist (Candidate_interest__c) Fully Interested, new record is created under the contact object that replicates the information stored under the Application record.
i have errors, and dont know how to debug it, Please Help
Below is my trigger
trigger apptocontact on Application__c (after insert, after update) {
List<Contact> con=new List<Contact>();
for(Application__c v : Trigger.new)
{
if(v.Candidate_interest__c == 'Fully Interested')
{
Contact s=new Contact();
s.Name=v.Last_Name__c;
//add other fields of subject here and add volunteer values in that.
con.add(s);
}
if(con.size()>0)
insert con;
}
}