function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi
I have two objects A and B
B has MasterDetail relationship with A
how can I write a trigger to insert a record In object B on update of field in a record of object A
Hi Sapan
Try this....
trigger updateDocDetails on Leave_Application__c (after update)
{
if(trigger.new.size() > 1) return;
for (Leave_Application__c leaveapp:Trigger.new){
if(trigger.new[0].Status__c =='Approved')
Leave__c lv = new Leave__c();
lv.Name = 'xyz';
lv.Leave_Application_No__c = trigger.new[0].Id;
insert lv;
}
DId this post solve your problem If so please mark It solved so that others get benified.....
Thanks
asish
Hi Sapana
It would be more usiful If you could have told more about your requirement...
I am just giving trigger format... try this
trigger updateA on A(after update){Map<Id, A> mapA = new Map<Id, A>();for (A objA: Trigger.new){mapA .put(objA.AId__c,objA);}if(mapA .size() > 0){
B newobj = new B ();
--------------
------
Did this solve your problem.. If so please mark it solved
hi asish,
I suppose explaining my requirement would clear the picture
I have two objects Leave_Application__c and Leave__c
Leave__c has MasterDetail 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
Thanks asish
Hi Sapan
Try this....
trigger updateDocDetails on Leave_Application__c (after update)
{
if(trigger.new.size() > 1) return;
for (Leave_Application__c leaveapp:Trigger.new){
if(trigger.new[0].Status__c =='Approved')
{
Leave__c lv = new Leave__c();
lv.Name = 'xyz';
lv.Leave_Application_No__c = trigger.new[0].Id;
insert lv;
}
}
}
DId this post solve your problem If so please mark It solved so that others get benified.....
Thanks
asish
All Answers
Hi Sapana
It would be more usiful If you could have told more about your requirement...
I am just giving trigger format... try this
trigger updateA on A(after update)
{
Map<Id, A> mapA = new Map<Id, A>();
for (A objA: Trigger.new)
{
mapA .put(objA.AId__c,objA);
}
if(mapA .size() > 0)
{
B newobj = new B ();
--------------
------
}
}
Did this solve your problem.. If so please mark it solved
Thanks
asish
hi asish,
I suppose explaining my requirement would clear the picture
I have two objects Leave_Application__c and Leave__c
Leave__c has MasterDetail 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
Hi Sapan
Try this....
trigger updateDocDetails on Leave_Application__c (after update)
{
if(trigger.new.size() > 1) return;
for (Leave_Application__c leaveapp:Trigger.new){
if(trigger.new[0].Status__c =='Approved')
{
Leave__c lv = new Leave__c();
lv.Name = 'xyz';
lv.Leave_Application_No__c = trigger.new[0].Id;
insert lv;
}
}
}
DId this post solve your problem If so please mark It solved so that others get benified.....
Thanks
asish
Thanks asish