0

I need to retrieve the Account id and insert it to my method. Get the Basket__r.Account__r.id and place it to the Account id inside the for loop. How can i do that?

list<Configuration__c> conf = [select id, name, Basket__r.id, Basket__r.Account__r.id  from Configuration__c where Basket__r.id = : basketId];
    
    
    for (Configuration__c confList: conf){
    
    Attachment att = [select id, body from Attachment where name like parentId = :confList.id];
    system.debug(att);
    system.debug(att.Body);
    system.debug(att.Body.toString()); 
    list <Guarantee_Line__c> guara = new list <Guarantee_Line__c>();
    
    guara = GuaranteeCreator.createGuarantee(att.Body.toString(), confList, Account id);
    }
0

I fixed your variable names (confList is not a list, and conf is a list), but aside from that, you just need to reference the account record as <record>.Basket__r.Account__r.

list<Configuration__c> confList = [select id, name, Basket__c, Basket__r.Account__r.Id  from Configuration__c where Basket__c = :basketId];
for (Configuration__c conf: confList){
    Attachment att = [select id, body from Attachment where name like parentId = :conf.id];
    list <Guarantee_Line__c> guara = GuaranteeCreator.createGuarantee(att.Body.toString(), conf, conf.Basket__r.Account__r);
}

Note that Account__r represents the account record (e.g. all fields you query through the relationship). You may need to add additional fields to your query.

3
  • thank you for the fixes! However, i did this an i get an error of incorrect signature. Maybe it's my method's issue. My method: public static list <Guarantee_Line__c> createGuarantee(String jsonStr, Configuration__c pConf, Account acc){
    – Christos
    Nov 9 '20 at 15:11
  • @Christos It's expecting an entire account, not an ID. This is different than your original question. I'll edit.
    – sfdcfox
    Nov 9 '20 at 15:18
  • Thank you! Resolved it!
    – Christos
    Nov 9 '20 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.