function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rafael.Martins.SantosRafael.Martins.Santos 

I cannot get a list of attachments using SOQL in APEX when the Salesforce is in Lighting Experience mode

Hi,
I have a code that verify if have at least 1 attachment in a opportunity.
The code was working normally but when I change to Lighting expecience mode, the SOQL of the Attahment don't work no more.
Do you know what is the problem? and How I can fix this if there is a way.

Here is my code:

Trigger Valida_Anexo on Opportunity (before insert, before update) {
    
    if(trigger.isInsert){
        for (Opportunity op : trigger.new) {
            if(op.StageName == 'Proposta Comercial' || op.StageName == 'Aposta'){
               op.addError(' Você precisa anexar o documento \"Proposta Comercial\" para seguir para etapa \"' +op.StageName + '\"');
            }

            if(op.StageName == 'Fechado e ganho'){
               op.addError(' Você precisa anexar o documento \"Proposta Comercial\" para fechar esta esta oportunidade');
            }
        } 
    }
    
    if(trigger.isUpdate){
        for (Opportunity op : trigger.new) {
        Integer c = 0;
        System.debug('Foi atualizado, contador: '+c);
            // THE LIST RETURN EMPTY
            LIST<Attachment> attachments = [SELECT Id, Name, ParentId FROM Attachment WHERE ParentId = : op.Id];
            System.debug('Lista de anexos: '+attachments);
          //THE CODE DON'T EXECUTE THIS FOR
          for(Attachment att : attachments){
              System.debug('Nome: '+ att.Name+', Contagem de anexos: ' + c);
              c++;
          }
            if(op.StageName == 'Proposta Comercial' && c == 0 || op.StageName == 'Aposta' && c == 0){
                System.debug('Estrou primeiro if, contador: '+c);
               op.addError(' Você precisa anexar o documento \"Proposta Comercial\" para seguir para etapa \"' +op.StageName + '\"');
            }

            if(op.StageName == 'Fechado e ganho' && c < 1){
                System.debug('Estrou segundo if, contador: '+c);
               op.addError(' Você precisa anexar o documento \"Proposta Comercial\" para fechar esta esta oportunidade');
            }
           }
    }
}

Best Regards
Rafael
Hemant_SoniHemant_Soni
Hi Rafael.Martins.Santos,

I have a question
are you creating attachment from feed layout.

Thanks
Hemant
Rafael.Martins.SantosRafael.Martins.Santos
Hi Hernant,
Yes, I enter in the Opportunity layout and drag and drop the file there, and I tried upload too, and by this way not work.
Hemant_SoniHemant_Soni
Hi Rafael.Martins.Santos

This because you are creating feed post not a Attachment.So if you want to get attachment then you have to write a trigger who make feed post to Attachment and you get Attachments in lighting as well.
If you need help in this trigger you can contact me on my email id "soni.sonihemant.hemant@gmail.com" and i will do all necessary changes for this functionalty without any cost but you need to clear your exect requirment.

Thanks
Hemant

 
Rafael.Martins.SantosRafael.Martins.Santos
Hi Hermant,
Thanks for your help.
But in the opportunity page don't have a way to upload in the format "Attach" without I have to create a trigger?
If it's not possible, All I have to do is recognize the file as Attachment.
 
Hemant_SoniHemant_Soni
Hi In opportunity object, From page layout you can enable notes and add attachment related list and from there you can upload file as a attachment. Thanks Hemant
Hemant_SoniHemant_Soni
Hi Rafael.Martins.Santos,
If you are available at skype or gtalk then i will help you in this on video call.
Thanks
Hemant
Rafael.Martins.SantosRafael.Martins.Santos
Hi Hernant,
I changed to classic mode again, and I note that the file that I attach, have the type "File" and when I delete him and upload again the file in classic mode, the file contain the type "Attach". So when I add a file by drag and drop or uploading the file on opportunity page, the file has a type of "File", for this reason my code doesn't recognize the attachment.
If you have a document that explain how is it work to share with me I thank you.
Because if for some way I can change the type of the file to "Attach" my code will work.

Abount the skype I have, but I not talk well in english, I'm horroble on this yet kkkkkkk, but if you still wanted I give you my nickname to add me.
So thanks again for your help. 
Hemant_SoniHemant_Soni
Hi Rafael.Martins.Santos,
I understand your problem.which language do you understand very well.You can talk me in that language.you can serach me on skype this is my skype id "sonihemant26". and i will give you a batter solution for this problem.

Thanks
Hemant
Rafael.Martins.SantosRafael.Martins.Santos
Hi hernant,
I'm from Brazil, I speak portuguese.