Domanda

Ho SOQL qui sotto e ottengo il risultato che contiene l'identificativo del sObject. La mia ipotesi è stata la query restituirà i campi di SObject pure. Per esempio la mia domanda cercare di ottenere "startDay__c" (la data), che è come campo di ShigotoShousai sobject. Ma Risultato ricerca è proprio ID dell'istanza sObject.

( genitori : ShigotoShousai bambina : ShigotoAssign)

sObject[] result = [
  SELECT
  ShigotoShousai__r.id, 
  ShigotoShousai__r.startDay__c
  FROM ShigotoAssign__c
];

system.debug (risultato) uscita

shigotoAssign_ c: {Id = a06500000067aNjAAI, ShigotoShousai _c = a055000000DlHnOAAV}, shigotoAssign_ c: {Id = a06500000067aNoAAI, ShigotoShousai _c = a055000000DlHnTAAV})

Ho ID di ShigotoShousai__c sObject invece del suo "startDay__c" proprietà. Ho pensato di uscita sarebbe qualcosa di simile:

shigotoAssign__c:{ShigotoShousai__c=a055000000DlHnOAAV, startDay__c=2010-10-10}, 
shigotoAssign__c:{ShigotoShousai__c=a055000000DlHnTAAV, startDay__c=2010-10-13})

Ma risultato della query solo a me è tornato ID di ShigotoShousai__c sobject: (

Ora so avere un valore ID di ShigotoShousai__c e vogliono accedere al suo campo in modo ho fatto in seguito.

ShigotoShousai__c foo = (ShigotoShousai__c)result[0].get('ShigotoShousai__c');
//now I assume I can access to some fields like below
system.debug(foo.workDate);

E questo mi dà errore:

System.TypeException: Invalid conversion from runtime 
type Id to SOBJECT:shigotoShousai__c

Poi ho pensato che ID non può essere usato per riferirsi a SObject (vale a dire ShigotoShousai__c).

Ma non ho il suo id .. Come posso accedere, diciamo startDay__c? C'è un modo per utilizzare questo ID?

È stato utile?

Soluzione

Il problema è che si sta assegnando il risultato della query SOQL al generico Sobject [], che non ha alcun campo concreti della propria, ad eccezione di Id. Finché non si sta cercando di fare qualcosa di fantasia con SOQL dinamica, provare qualcosa di simile:

ShigotoAssign__c[] result = [
  SELECT
  ShigotoShousai__r.id, 
  ShigotoShousai__r.startDay__c
  FROM ShigotoAssign__c
];

for(ShigotoAssign__c s : result) {
  System.debug(s.ShigotoShousai__r.startDay__c);
}

Altri suggerimenti

Inoltre voglio solo condividere la mia informazioni in quanto è legato alla domanda. Speriamo che qualcuno trova questa utile.

Di seguito interrogazione comporta genitore, figlio, nipote e ho usato apice per raggiungere ciascuno dei valori. Ora posso visualizzare quelli valore a pagina Visualforce:)

    //WORK
    public String workName { get; set; }
    public String workContent { get; set; }
    public String workCategory { get; set; }
    public String workSponsor { get; set; }
    //WORK DETAIL
    public String workDetailStartDay { get; set; }
    public String workDetailStartHour { get; set; }
    public String workDetailStartMin { get; set; }
    public String workDetailEndDay { get; set; }
    public String workDetailEndHour { get; set; }
    public String workDetailEndMin { get; set; }
    public String workDetailCategory { get; set; }
    public String workDetailDivision { get; set; }
    //WORK ASSIGN

ShigotoAssign__c[] result = [
            SELECT
            ShigotoShousai__r.Shigoto__r.name,
            ShigotoShousai__r.Shigoto__r.workContent__c,
            ShigotoShousai__r.Shigoto__r.category__c,
            ShigotoShousai__r.Shigoto__r.sponsor__c,
            ShigotoShousai__r.id, ShigotoShousai__r.startDay__c, ShigotoShousai__r.startHour__c,
            ShigotoShousai__r.startMin__c,
            ShigotoShousai__r.endDay__c, ShigotoShousai__r.endHour__c, ShigotoShousai__r.endMin__c,
            ShigotoShousai__r.workCategory__c, ShigotoShousai__r.workDivision__c,
            ShigotoShousai__r.address__c,
            id, contactStat__c
            FROM ShigotoAssign__c
            WHERE id = :workAssigned.id
        ];

    //get WORK info to show on email template page
    workName = result[0].ShigotoShousai__r.Shigoto__r.name;
    workContent = result[0].ShigotoShousai__r.Shigoto__r.workContent__c;
    workSponsor = result[0].ShigotoShousai__r.Shigoto__r.sponsor__c;
    //get WORK DETAIL info to show on email template page
    workDetailStartDay = String.valueOf(result[0].ShigotoShousai__r.startDay__c);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top