• VictorBL
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

 I wrote the following trigger, but I need to convert it to an after update one! 

It just adds the item prices of the work Order. (Price Items are afected by a parameter in the work order)

 

trigger WOROrder on Orden_de_Servicio__C (before update) {

 

List<Orden_de_Servicio__C> toUpdate=new List<Orden_de_Servicio__C>();
for(Orden_de_Servicio__C myOrder : trigger.new){ 

 

 myOrder.Total_Orden__C = 0; 


// Populate the list of items based on trigger typeList

 

<AIT_Item__C> itemList = [SELECT j.Precio_Item__C, j.Orden_de_Servicio__C FROM AIT_Item__C j WHERE j.Orden_de_Servicio__r.id IN : Trigger.new FOR UPDATE];


// Process the list of items

 

for(AIT_Item__C itemToProcess : itemList){           

myOrder.Total_Orden__C += itemToProcess.Precio_Item__C;  }                         

 

toUpdate.add(myOrder);}  

 

Thanks in advance!!!!!!!!!!!!                     

 

 I wrote the following trigger, but I need to convert it to an after update one! 

It just adds the item prices of the work Order. (Price Items are afected by a parameter in the work order)

 

trigger WOROrder on Orden_de_Servicio__C (before update) {

 

List<Orden_de_Servicio__C> toUpdate=new List<Orden_de_Servicio__C>();
for(Orden_de_Servicio__C myOrder : trigger.new){ 

 

 myOrder.Total_Orden__C = 0; 


// Populate the list of items based on trigger typeList

 

<AIT_Item__C> itemList = [SELECT j.Precio_Item__C, j.Orden_de_Servicio__C FROM AIT_Item__C j WHERE j.Orden_de_Servicio__r.id IN : Trigger.new FOR UPDATE];


// Process the list of items

 

for(AIT_Item__C itemToProcess : itemList){           

myOrder.Total_Orden__C += itemToProcess.Precio_Item__C;  }                         

 

toUpdate.add(myOrder);}  

 

Thanks in advance!!!!!!!!!!!!                     

 

Hey guys,

 

Contacts are a child of a Lead, so a Lead can have multiple contacts (Contacts >> Lead). Once the user converts the lead, I want to associate all of the child Contacts with the converted Account. I have a trigger as follows:

trigger leadAfter on Lead (after update) {

    //create a list of Contacts to update with Converted Account ID
    List< Contact > contacts = new list< Contact >();
   
  for ( Lead l : Trigger.new )
  {
    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) {
        System.debug('******Entering LeadAfter******');

        //Create a list of contacts that matches the Converted LeadId
        Contact c = [SELECT id, Lead__c, Name, AccountId FROM Contact c WHERE c.Lead__c = :l.Id AND c.AccountId = null];
       
        c.AccountId = l.ConvertedAccountId;
        contacts.add(c);
    }
        update contacts;
}
}

 

This trigger doesn't work and throws the following error: List has more than 1 row for assignment to SObject Trigger.leadAfter: line 12, column 21.

 

How can I update all of the child Contacts in a bulk manner?

 

Your input is appreciated.

 

  • July 22, 2011
  • Like
  • 0