You need to sign in to do that
Don't have an account?
cribis
Creating a New Record in the Same Object
I am wortking on a conversion tool for a custom object (Customer Bulk Density). the thought process is that if a user create a bulk density record in Lbs/ft3, Salesforce will create a duplicate record in Kg/m3. Currently I am trying to write the trigger to create the new record, but am running into the following error:
Error: Compile Error: Method does not exist or incorrect signature: Customer_Bulk_Density__c.put(Id, SOBJECT:Customer_Bulk_Density__c) at line 15 column 7
Below is the code:
trigger BulkDensityConversion on Customer_Bulk_Density__c (after insert) { Set<Id> bIds = new Set<Id>(); for(Customer_Bulk_Density__c c:trigger.new){ bIds.add(c.id); } System.debug('****1 : B Id size '+ bIds.size()); List<Customer_Bulk_Density__c> c = [Select id, name, Customer_Product__c, Customer_Product_2__c, Customer_Product_3__c from Customer_Bulk_Density__c where id in:bIds]; System.debug('****2 : b size '+ bIds.size()); if (c.size() > 0) { List <Customer_Bulk_Density__c> design= new List <Customer_Bulk_Density__c>(); Map<id, Customer_Bulk_Density__c> capacity = new map<id, Customer_Bulk_Density__c>(); for(Customer_Bulk_Density__c m: c) { Customer_Bulk_Density__c.put(m.id, m); } //Loop through the records and create a Bulk Density Record Id n1; for(Customer_Bulk_Density__c y : trigger.new) { n1 = bulk.get(y.id).WhatId; Customer_Bulk_Density__c s = new Customer_Bulk_Density__c( Name = trigger.new[0].name, Customer_Product__c=trigger.new[0].Customer_Product__c, Customer_Product_2__c=trigger.new[0].Customer_Product_2__c, Customer_Product_3__c=trigger.new[0].Customer_Product_3__c ); insert s; } } }
How do I solve this error?
You're trying to call put() as a static method. Did you, perhaps, intend to put it in the map you'd just created, like:
capacity.put(m.id, m);
There are several things I don't understand about what you're trying to do. The first query (line 8) appears to be doing a query to get a list of objects identical to what's already in trigger.new. Seems like you could just as easily say:
List<Customer_Bulk_Density__c> c = trigger.new;
to avoid the query.
When you're looping through trigger.new and creating bulk density records, you refer to trigger.new[0], instead of having a loop counter, like:
for (integer i=0; i < trigger.new.size(); i++) {
...
Name=trigger.new[i].name
...
}
finally, you insert each new record individually. You'll really want to add them to a list, and have just one insert call after the for loop that just inserts the whole list.
Rich
All Answers
This line:
Should be
See if it works now.
Jeremy
You're trying to call put() as a static method. Did you, perhaps, intend to put it in the map you'd just created, like:
capacity.put(m.id, m);
There are several things I don't understand about what you're trying to do. The first query (line 8) appears to be doing a query to get a list of objects identical to what's already in trigger.new. Seems like you could just as easily say:
List<Customer_Bulk_Density__c> c = trigger.new;
to avoid the query.
When you're looping through trigger.new and creating bulk density records, you refer to trigger.new[0], instead of having a loop counter, like:
for (integer i=0; i < trigger.new.size(); i++) {
...
Name=trigger.new[i].name
...
}
finally, you insert each new record individually. You'll really want to add them to a list, and have just one insert call after the for loop that just inserts the whole list.
Rich
Both suggestions did the trick. Thank you for your help.