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
foodrunnerfoodrunner 

Update records in the same object

I am working on a conversion tool that will change the lookup values depending on a drop down list of the different measurement systems.

 

The step I am on is writing a trigger to populate a lookup field connecting the two records with cooresponding value. The workflow is when a record is created, a trigger will calculate the cnverted measure and enter a new record with the converted value and a link to the original record. I am trying to insert the value in the lookup field on the original record.

 

 

I am recieving the following error message:

Error: Compile Error: Method does not exist or incorrect signature: updatedCustomer_Bulk_Density__c.add(SOBJECT:Customer_Bulk_Density__c) at line 9 column 10

 

 

Below is my code:

trigger BulkDensityLink on Customer_Bulk_Density__c (after insert, after update) {
    Map<Id, Customer_Bulk_Density__c> LookupPop = new Map<Id, Customer_Bulk_Density__c>();

   List <Customer_Bulk_Density__c> updatedbulkdensity =  new List<Customer_Bulk_Density__c>();

    for(Customer_Bulk_Density__c b : [select id, Converted_Record_ID__c from Customer_Bulk_Density__c
         where Converted_Record_ID__c in :LookupPop.keyset() Limit 1]) {
         b.Converted_Record_Id__c = b.id;
         updatedCustomer_Bulk_Density__c.add(b);
         }
    //update updatedCustomer_Bulk_Density__c;
}

 

How do I insert the desired value from one record to another record on the same object?

 

Thanks,

 

Chris

chezibchezib

Hi,

 

It seems like you are simply using the wrong variable name:

 

 

trigger BulkDensityLink on Customer_Bulk_Density__c (after insert, after update) {
    Map<Id, Customer_Bulk_Density__c> LookupPop = new Map<Id, Customer_Bulk_Density__c>();

   List <Customer_Bulk_Density__c> updatedbulkdensity =  new List<Customer_Bulk_Density__c>();

    for(Customer_Bulk_Density__c b : [select id, Converted_Record_ID__c from Customer_Bulk_Density__c
         where Converted_Record_ID__c in :LookupPop.keyset() Limit 1]) {
         b.Converted_Record_Id__c = b.id;

            updatedbulkdensity.add(b);
      //    NOT --> updatedCustomer_Bulk_Density__c

         }

    /* The same here  */
    //update updatedCustomer_Bulk_Density__c;
}

 Further more, when you are using the "limit 1" in SOQL there is no need to loop the result. 

 

Good Luck!

 

Jeremy_nJeremy_n

You are not referring to Trigger.new anywhere in your Trigger. LookupPop is initialized, but it has no data in it, so your loop shouldn't even run. Fill LookupPop with your trigger records, and this will work, at least for one record at a time.

 

Jeremy