function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
padmasree.force1.3940871124123252E12padmasree.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
Best Answer chosen by padmasree.force1.3940871124123252E12
Sonam_SFDCSonam_SFDC
You can write a after insert, after update trigger on object B and have the IF condition run on the field with picklist values X, Y and Z.
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

Sonam_SFDCSonam_SFDC
You can write a after insert, after update trigger on object B and have the IF condition run on the field with picklist values X, Y and Z.
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


This was selected as the best answer
realtimetasks1.3941822547955107E12realtimetasks1.3941822547955107E12
trigger amountUpdate on B__c(after insert,after update) {
    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
Tech InfoTech Info
Hi .....
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.