Two things,New Edit:
After reviewing what we planned on doing with this JSON object:
Boxes:
[ { count: 5, Fragile: true };
{count: 10, Fragile: false};
I do not gethave gotten a clearer picture on what needs to be done.
With the return value for fragile correctly, it is always false even though someJSON object above we will then want to update existing box records have truein our organization.
When aWhich is why we need to query for existing box records that are not used that are either fragile vs non fragile.
So this json object comes overshows two box records, with at leasta count of 5 and a count of 10, one is fragile box it always duplicates the amountand one is not. For example if
SO we sendwill be updating 2 box information overrecords that have not been used yet.
So Box 1:
Count__c = 5; <=field that needs to be updated, grab the first count
(5) from json
Fragile__c = true<= we are not updating this, we need to find a un-used
box record that is fragile
Box 2:
Count__c = 10; <=field that needs to be updated, grab the second
count(10) from json
Fragile__c = false<= we are not updating this, we need to find a un-
used box record that is not fragile
Once that is updated, it sends 4we will then return back. a json object to our third party with this information about the box:
I think it is because of “numberOfBoxes”Width
Height
length
Fragile
Count
So to do so, it retrievesI have created a wrapper class for Boxes Needed:
public class BoxesNeeded{
public Decimal count {get;set;}
public Boolean fragile {get;set;}
public BoxesNeeded(Decimal count, Boolean fragile){
this.count = count;
this.fragile = fragile;
}
}
Then to send the 2 records but dupilicates because fragile comes over once as true andbox information once as falseupdated to our 3rd party, which is why the result returns 4, if that makes sense.boxWrapper will look like this:
global class boxWrapper{
Integer width {get;set;}
Integer height {get;set;}
Integer length {get;set;}
Boolean fragile {get;set;}
Integer count {get; set;}
public BoxWrapper(Integer width, integer height, integer length, boolean
fragile, integer count){
this.width= width;
this.height = height;
this.length = length;
this.fragile = fragile;
this.count = count;
}
}
How can I retrieve the correct numberhave added new data types to capture non-fragile vs fragile counts of box records depending onboxes needed:
Public Integer fragileCount {get; set;}
Public integer nonFragileCount {get;set;}
Then like mentioned below, my json object and returnFor Loop will count how many of each I need(changed var name to boxNeeded to differentiate from Object BoxesNeeded:
for(BoxesNeeded boxNeeded : packageWrapper.boxesNeeded){
if(boxNeeded.fragile == true){
fragileCount ++;
}
else if(boxNeeded.fragile == false){
nonFragileCount ++;
}
}
Then the two queries also mentioned below will bring back the box records I need to our third party?update:
Boxes List<Box__c> fragileBoxesToUse = [SELECT ID, width__c, height__c,
length__c FROM box__C WHERE Used__C = FALSE AND Fragile__c =true LIMIT :fragileCount FOR UPDATE];
List<Box__c> nonFragileBoxesToUse = [SELECT ID, width__c, height__c,
length__c FROM [box__C WHERE Used__C = FALSE AND Fragile__c = false LIMIT :nonFragileCount FOR UPDATE];
Now to loop through the two lists:
For(Box__c boxToUse : fragileBoxesToUse){
BoxToUse.Package__c = Pack.id;
BoxToUse.Date_Used__c = Date.today();
BoxToUse.Count__c = ??? I need to get the count: 5from the JSON
boxWrappers.add(new boxWrapper(boxToUse.width__c, Fragile:
true } boxToUse.height__c, boxToUse.length__c,,boxToUse.fragile__c,
boxToUse.count__c);
}
upsert FragileBoxesToUse;
For(Box__c boxToUse : nonfragileBoxesToUse){
BoxToUse.Package__c = Pack.id;
BoxToUse.Date_Used__c = Date.today();
BoxToUse.Count__c = ??? I need to get the count: 10from the JSON
boxWrapper(boxToUse.width__c, Fragile:boxToUse.height__c, false
boxToUse.length__c,,boxToUse.fragile__c, boxToUse.count__c);
}
upsert ]nonFragileBoxesToUse;
Basically with the json aboveTwo more things, to combine my two List<Box__c> queries would I need to write a dynamic soql query? Also after clarifying what "Count" is, how would I grab the correct "count" to update my box records? Count does not represent how many box records that need to be updated but it represents a field on the box record to indicate how many items will go in the box. (Count__c)
So in all, the goal from this Json is going to update two existing box records in my organizationand return the updated box records to our third party. It
So in this json example we will then return one true fragilebe updating two box records and one false fragilethen return two box with their dimensionsrecord's information.