You need to sign in to do that
Don't have an account?
Vladimir Bessonov
how to cast one list into another?
I am getting APEX CPU issue as I have to process a lot of records
I found one example from Salesforce on how to use Maps instead of slow list iteration.
My question is how I can apply the same principle if I need to assign values of Map to another object.
so I need to assign somehow the values of Map to the list. A simple cast doesn't work in this case.
I have 1 field in the object that the original one doesn't have.
Double Total = part.Number_of_units__c * part.Quantity__c;
Please advise.
I found one example from Salesforce on how to use Maps instead of slow list iteration.
My question is how I can apply the same principle if I need to assign values of Map to another object.
for (NonSerializedPart__c part : NonSerPartsConfig) { Double Total = part.Number_of_units__c * part.Quantity__c; project_Non_Serialized_Part__c NewPart = New project_Non_Serialized_Part__c(Name = part.Name, Project__c =ProjectID, Material_Number__c = part.Material_Number__c, Supplier__c = part.Supplier__c, Supplier_Part_Number__c = part.Supplier_Part_Number__c, Total_Quantity__c = Total ,Unit_of_measurement__c = part.Unit_of_measurement__c, Number_of_units__c = part.Number_of_units__c, unit_Quantity__c = part.Quantity__c); NonSerParts.add(NewPart); } insert NonSerParts;
so I need to assign somehow the values of Map to the list. A simple cast doesn't work in this case.
Map<id, NonSerializedPart__c> NSPM = new Map <id, NonSerializedPart__c>([Select ID, Name, Number_of_units__c, Quantity__c, Unit_of_measurement__c, Material_Number__c, Supplier_Part_Number__c, Supplier__c from NonSerializedPart__c where Project__c =: 'a3ae0000003ZTBmAAO']); NonSerParts = (project_Non_Serialized_Part__c) NSPM.values();
I have 1 field in the object that the original one doesn't have.
Double Total = part.Number_of_units__c * part.Quantity__c;
Please advise.
Check this code:-
And maybe you are getting the error in the project__c field(line no. 6). Is projectId a variable or a field?
In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.