You need to sign in to do that
Don't have an account?
padmasree.force1.3940871124123252E12
Trigger requirement
Hi all,
Here is the my requirement,i have two objects known as A and B,having lookup relationship In the A object i have 3 fields known as Xamt,Yamt,Zamt and in the Bobject i hv one currency field with amount and one picklist with x,y and z.when i choose x and enter amt value in the B object then that should be effected to XAmt in A object.this requirement should be done with trigger
Here is the my requirement,i have two objects known as A and B,having lookup relationship In the A object i have 3 fields known as Xamt,Yamt,Zamt and in the Bobject i hv one currency field with amount and one picklist with x,y and z.when i choose x and enter amt value in the B object then that should be effected to XAmt in A object.this requirement should be done with trigger
If X is choosen - you can copy the value entered in current field with amt to Xamt on object A and similarly for Yamt and Zamt
All Answers
If X is choosen - you can copy the value entered in current field with amt to Xamt on object A and similarly for Yamt and Zamt
B__c b=new B__c();
if(Trigger.isInsert){
b=Trigger.new[0];
if(b.status__c=='X'){
B__c b1=[select id,amount__c,status__c from b__c where name=:b.name];
}
if(Trigger.isUpdate){
A__C a=[select id,name,X_Amount__c from A__c where name=:b.name ];
a.X_Amount__c=b.Amount__c;
update a;
}
}
}
I have done like this but the data is not inserted can you help me in this code
padmasree.force1.3940871124123252E12..
Plz try this below Code if it helps..
trigger Assignamount on Child__c (After Insert,After Update,After Delete,After undelete) {
set<id> stid=new set<id>();
if((Trigger.Isinsert || Trigger.Isupdate || Trigger.Isundelete) && Trigger.IsAfter){
for(Child__c c :Trigger.new){
stid.add(c.Parent__c);
}
}
if((Trigger.Isdelete||Trigger.Isupdate) && Trigger.IsAfter){
for(Child__c c :Trigger.old){
stid.add(c.Parent__c);
}
}
list<Parent__c> parentlist=new list<Parent__c>();
for(Parent__c p:[select id, X_Amount__c,Y_Amount__c,Z_Amount__c,(select id, Amount__c,Type__c from Childs__r) from Parent__c where id in:stid]){
p.X_Amount__c=null;
p.Y_Amount__c=null;
p.Z_Amount__c=null;
for(Child__c cc:p.childs__r){
if(cc.Type__c=='X' && cc.Amount__c!=null){
if(p.X_Amount__c==null){
p.X_Amount__c=cc.Amount__c;
}else{
p.X_Amount__c+=cc.Amount__c;
}
}else if(cc.Type__c=='y' && cc.Amount__c!=null){
if(p.Y_Amount__c==null){
p.Y_Amount__c=cc.Amount__c;
}else{
p.Y_Amount__c+=cc.Amount__c;
}
}else if(cc.Type__c=='z' && cc.Amount__c!=null){
if(p.Z_Amount__c==null){
p.Z_Amount__c=cc.Amount__c;
}else{
p.Z_Amount__c+=cc.Amount__c;
}
}
}
parentlist.add(p);
}
if(parentlist.size()!=null){
update parentlist;
}
}
Thanks...
Pankaj Saini.