• Jane Nicolas
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 7
    Replies
Hi
This is Jane here I had a scenario where Feild 1 of A object needs to be updated with same value of  the Field 2 in Object B , whenever an update or insert of Field 2 occurs. I tried following Trigger But it doesn't seem to help. Can anyone suggest ? Thanks.

trigger OpportunityTrigger on Opportunity (after insert, after update)
{
    Set<Id> accountIds = new Set<Id>();
    for(Opportunity opp : Trigger.new)
    {
         accountIds.add(opp.AccountId);
    }

   Map<ID, Account> mapAccounts = new Map<ID, Account>([SELECT Id, Plan_Number__c FROM Account where Id IN :accountIds]);
List<Account> lstAccToUpdate = new List<Account>();
   For(Opportunity opp : Trigger.new)
   {
       Account acc = mapAccounts.get(opp.AccountId);
      acc.Plan_Number__c = opp.Plan_Number__c;
      lstAccToUpdate.add(acc);
   }
  update lstAccToUpdate;
Map<Id, Account> mapUpdatedAccounts = new Map<Id,Account>();
  For(Account acc : lstAccToUpdate)
  {
      mapUpdatedAccounts.put(acc.Id,acc);
  }
  
}
How can I make IsInsert Trigger work also for Updation of records .Trigger was:

trigger OpportunityTrigger on Opportunity (after insert, after update){

if(Trigger.isInsert){

    List<AccountManagement__c> am = new List <AccountManagement__c>();
   
    
    for(Opportunity opp : trigger.new){

        AccountManagement__c a = new AccountManagement__c
        
        
(Planholder__c = opp.Planholder_Name__c,
        Plan_Number__c = opp.Plan_Number__c);
         
           
                      
                 am.add(a);
                 
    }
    
    if(am != null && am.size() > 0){
insert am;}


}


}
hi all I was getting following error "System.TypeException: Invalid decimal: opp.Plan_Number__c: Trigger.OpportunityTrigger: line 10, column 1" for the below trrigger when tried creating a record in opportunity. my trigger was :

trigger OpportunityTrigger on Opportunity (after insert, after update){

if(Trigger.isInsert){

    List<AccountManagement__c> am = new List <AccountManagement__c>();
   
    
    for(Opportunity opp : trigger.new){

        AccountManagement__c a = new AccountManagement__c
        
        
(Planholder__c = opp.Planholder_Name__c,
        Plan_Number__c = decimal.valueof ('opp.Plan_Number__c') ,
        Name='');
         
           
                      
                 am.add(a);
                 
    }
    
    if(am != null && am.size() > 0){
insert am;}


}
}
Hi
This is Jane here I had a scenario where Feild 1 of A object needs to be updated with same value of  the Field 2 in Object B , whenever an update or insert of Field 2 occurs. I tried following Trigger But it doesn't seem to help. Can anyone suggest ? Thanks.

trigger OpportunityTrigger on Opportunity (after insert, after update)
{
    Set<Id> accountIds = new Set<Id>();
    for(Opportunity opp : Trigger.new)
    {
         accountIds.add(opp.AccountId);
    }

   Map<ID, Account> mapAccounts = new Map<ID, Account>([SELECT Id, Plan_Number__c FROM Account where Id IN :accountIds]);
List<Account> lstAccToUpdate = new List<Account>();
   For(Opportunity opp : Trigger.new)
   {
       Account acc = mapAccounts.get(opp.AccountId);
      acc.Plan_Number__c = opp.Plan_Number__c;
      lstAccToUpdate.add(acc);
   }
  update lstAccToUpdate;
Map<Id, Account> mapUpdatedAccounts = new Map<Id,Account>();
  For(Account acc : lstAccToUpdate)
  {
      mapUpdatedAccounts.put(acc.Id,acc);
  }
  
}
hi all I was getting following error "System.TypeException: Invalid decimal: opp.Plan_Number__c: Trigger.OpportunityTrigger: line 10, column 1" for the below trrigger when tried creating a record in opportunity. my trigger was :

trigger OpportunityTrigger on Opportunity (after insert, after update){

if(Trigger.isInsert){

    List<AccountManagement__c> am = new List <AccountManagement__c>();
   
    
    for(Opportunity opp : trigger.new){

        AccountManagement__c a = new AccountManagement__c
        
        
(Planholder__c = opp.Planholder_Name__c,
        Plan_Number__c = decimal.valueof ('opp.Plan_Number__c') ,
        Name='');
         
           
                      
                 am.add(a);
                 
    }
    
    if(am != null && am.size() > 0){
insert am;}


}
}