Skip to main content
added 48 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

You cannot call cross-object get. Take a look at the FieldReference class. It's open source, so you can just copy it into your org. Then you could do:

for (String invoiceField : invoiceFields)
    system.debug(FieldReference.build(invoiceField).getFrom(opportunity);

What you want probably cannot be accomplished in a clean way without recursive logic. If you want to do so without a helper class, you could do something along the lines of:

public with sharing class CrossObject
{
    public static Object multiLevelGetget(ObjectSObject record, String field)
    {
        if (record == null) return null;
        if (!field.contains('.')) return ((SObject)record).get(field);
        record = ((SObject)record).getSObject(field.substringBefore('.'));
        field = field.substringAfter('.');
        return multiLevelGetget(record, field);
    }
}

You cannot call cross-object get. Take a look at the FieldReference class. It's open source, so you can just copy it into your org. Then you could do:

for (String invoiceField : invoiceFields)
    system.debug(FieldReference.build(invoiceField).getFrom(opportunity);

What you want probably cannot be accomplished in a clean way without recursive logic. If you want to do so without a helper class, you could do something along the lines of:

public static Object multiLevelGet(Object record, String field)
{
    if (record == null) return null;
    if (!field.contains('.')) return ((SObject)record).get(field);
    record = ((SObject)record).getSObject(field.substringBefore('.'));
    field = field.substringAfter('.');
    return multiLevelGet(record, field);
}

You cannot call cross-object get. Take a look at the FieldReference class. It's open source, so you can just copy it into your org. Then you could do:

for (String invoiceField : invoiceFields)
    system.debug(FieldReference.build(invoiceField).getFrom(opportunity);

What you want probably cannot be accomplished in a clean way without recursive logic. If you want to do so without a helper class, you could do something along the lines of:

public with sharing class CrossObject
{
    public static Object get(SObject record, String field)
    {
        if (record == null) return null;
        if (!field.contains('.')) return record.get(field);
        record = record.getSObject(field.substringBefore('.'));
        field = field.substringAfter('.');
        return get(record, field);
    }
}
added 542 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

You cannot call cross-object get. Take a look at the FieldReference class. It's open source, so you can just copy it into your org. Then you could do:

for (String invoiceField : invoiceFields)
    system.debug(FieldReference.build(invoiceField).getFrom(opportunity);

What you want probably cannot be accomplished in a clean way without recursive logic. If you want to do so without a helper class, you could do something along the lines of:

public static Object multiLevelGet(Object record, String field)
{
    if (record == null) return null;
    if (!field.contains('.')) return ((SObject)record).get(field);
    record = ((SObject)record).getSObject(field.substringBefore('.'));
    field = field.substringAfter('.');
    return multiLevelGet(record, field);
}

You cannot call cross-object get. Take a look at the FieldReference class. It's open source, so you can just copy it into your org. Then you could do:

for (String invoiceField : invoiceFields)
    system.debug(FieldReference.build(invoiceField).getFrom(opportunity);

You cannot call cross-object get. Take a look at the FieldReference class. It's open source, so you can just copy it into your org. Then you could do:

for (String invoiceField : invoiceFields)
    system.debug(FieldReference.build(invoiceField).getFrom(opportunity);

What you want probably cannot be accomplished in a clean way without recursive logic. If you want to do so without a helper class, you could do something along the lines of:

public static Object multiLevelGet(Object record, String field)
{
    if (record == null) return null;
    if (!field.contains('.')) return ((SObject)record).get(field);
    record = ((SObject)record).getSObject(field.substringBefore('.'));
    field = field.substringAfter('.');
    return multiLevelGet(record, field);
}
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

You cannot call cross-object get. Take a look at the FieldReference class. It's open source, so you can just copy it into your org. Then you could do:

for (String invoiceField : invoiceFields)
    system.debug(FieldReference.build(invoiceField).getFrom(opportunity);