You need to sign in to do that
Don't have an account?
Sfdc@Smitha
urgent requirement on trigger pls help me
Hi
can anybody help me?
I have the following requirement. Please write a trigger for it
I have two objects Leave_Application__c and Leave__c
Leave__c has Master Detail relationship with Leave_Application__c
There is a picklist field in Leave_Application__c object named Status__c
Now whenever a Status__c field is updated to the value "Approved" a record should be created in Leave__c object . Newly created record will have one field that is Leave_Application_No__c and that should be set to the trigger ID.
this should work fine. let me know if you need it tweaked for any fields
trigger insertNewLeave on Leave_Application__c (after insert,after update)
{
List<Leave__c> leaveList = new List<Leave__c>();
for(Leave_Application__c la : Trigger.new)
if(la.Status__c == 'Approved')
{
Leave__c l= new Leave__c();
l.Leave_Application__c = la.Id;
leaveList.add(l);
}
insert leaveList;
}
All Answers
this should work fine. let me know if you need it tweaked for any fields
trigger insertNewLeave on Leave_Application__c (after insert,after update)
{
List<Leave__c> leaveList = new List<Leave__c>();
for(Leave_Application__c la : Trigger.new)
if(la.Status__c == 'Approved')
{
Leave__c l= new Leave__c();
l.Leave_Application__c = la.Id;
leaveList.add(l);
}
insert leaveList;
}
Minor change so that only one Leave__c record gets created:
Thanku for reply but here what iam having doubt is the two objects having master detailed relationship so in code we represent the two objets like __c .But for child object we mention like__r here is there any problm of with out mention th__r pls breifly explain?
shouldn't matter if it's lookup or md. the triggers above work