I have the following class with a property called sorToUpdate. I want to access this property to see if a specific Id is in the property. Do I need a specific decorator to do so? I only ask that because I visited the following Link -https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_properties.htm and it seems like in order to make my properties accessible I have to put a get or set method or declare it public:
Here is my class
public with sharing class DynamicSObjectUpdater {
Map<SObjectType, Map<Id, sObject>> sorToUpdate = new Map<SObjectType, Map<Id, sObject >>();
public SObject getSObject(ID sObjectID)
{
SObjectType sot = sObjectID.getSobjectType();
if(!sorToUpdate.containsKey(sot))
{
sorToUpdate.put(sot, new Map<Id, SObject>());
}
SObject targetSObject = sorToUpdate.get(sot).get(sObjectID);
if(targetSObject == null)
{
targetSObject = sot.newSobject(sObjectID);
sorToUpdate.get(sot).put(sObjectID, targetSObject);
}
return targetSObject;
}
public SObject getUpdateSObject(ID sObjectID, Map<String, Object> values)
{
SObjectType sot = sObjectID.getSobjectType();
if(!sorToUpdate.containsKey(sot))
{
sorToUpdate.put(sot, new Map<Id, SObject>());
}
SObject targetSObject = sorToUpdate.get(sot).get(sObjectID);
if(targetSObject == null)
{
targetSObject = sot.newSobject(sObjectID);
sorToUpdate.get(sot).put(sObjectID, targetSObject);
}
for (String field : values.keySet())
{
targetSObject.put(field, values.get(field));
}
return targetSObject;
}
public void updateSObjects()
{
List<SObject> sObjectsToUpdate = new List<SObject>();
if(sorToUpdate.size() > 0)
{
for(SObjectType sorType: sorToUpdate.keySet())
{
sObjectsToUpdate.addAll( sorToUpdate.get(sorType).values() );
}
}
if(sObjectsToUpdate.size()>0) update sObjectsToUpdate;
}
}
I instantiate an object in code like this:
DynamicSObjectUpdater sObjectUpdater = new DynamicSObjectUpdater();
And I Want to grab the property sorToUpdate
sObjectUpdater.sorToUpdate
public
in front of that variableget
andset
methods to access your variable