• Angadi VC
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
Hi All,

Is there any way to send report results(records) to non-salesforce users i.e. to external email id
I want to schedule the report on daily basis.
Any help would be appreciated.
Hi,
I have a schedule class which inserts a chatter post on user birthyday.
There is test class for same which give 100% coverage in sandbox,but while deploying it gives code coverage error with 73% coverage.
Kindly help me with this,
Thanks in advance.
Schedule class:

global class AnniversayBirthydayChatter implements Schedulable{
 

global void execute(SchedulableContext sc) {

 List<user> lstbirthday=[Select id,name,UserRole.name,User_State__c from user where IS_birthday_today__c=true and isactive=true];// query on birthday of users
 
 List<user> lstanniversary=[Select id,name,UserRole.name,User_State__c from user where IS_Anniversary_today__c=true and isactive=true];//query of anniversary of users
     
     list<FeedItem> postlist1= new list<FeedItem>();
     list<FeedItem> postlist2= new list<FeedItem>();
     
       for(User u:lstbirthday){
        FeedItem post = new FeedItem(); // chatter instance creation
        
        post.ParentId = u.id;
        
         post.Body = 'Join together in wishing a very Happy Birthday to '+'-'+u.name +'-'+u.UserRole.name+'-'+u.User_State__c ;
         postlist1.add(post);
           
       }
       if(postlist1.size()>0 && postlist1!=null){
          insert postlist1;
       }
         for(User u:lstanniversary){
            FeedItem post = new FeedItem();// chatter instance creation
            
            post.ParentId = u.id;
            
             post.Body = 'Ashirvad Family wishes you both a very happy anniversary. Wish you both lot of happiness & good health'+'-'+'Mr & Mrs.'+'-'+u.name+'-' +u.UserRole.name+'-'+u.User_State__c ;
             postlist2.add(post);
           
       }
           if(postlist2.size()>0 && postlist2!=null){ //check for list size
              insert postlist2;
           }

}
}

Test class:
 @isTest
   public class Test_AnniversayBirthydayChatter  {
        @isTest static void Chattertestmethod(){
        Test.startTest();
 AnniversayBirthydayChatter abc=new AnniversayBirthydayChatter();
String sch = '0 00 8 * * ?'; //schedule interval time
        system.schedule('AnniversayBirthydayChatter',sch , abc); //system method to schedule apex class
         Test.stopTest();
        }
    }
Hi,
I have 2 triggers:
1.Contentdocument 2.Contentdocumentlink
which counts the no of attachments attached in lightning and roll it up to parent object.But i have an issue in test class coverage.
It shows:Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, FilesRollupCount: execution of AfterInsert caused by: System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single Id on C
please help me with this.Thanks in advance.
Below is  my test class:

@isTest

public class ContentDocTrigger_Test{
    private static Account dis1;
    
    static testmethod void method_1(){
        
        dis1 = Initial_Test_Data.createAccount('test Account1','Distributor');
        dis1.Contact_Number_Mobile__c ='7259582222'; 
        dis1.Party_Type__c = 'Distributor';
        dis1.Status__c = 'Existing';
        dis1.Ramco_ID__c = 'abc123';
        insert dis1;
        
        Promotion__c prm = new Promotion__c();            
        prm.Date__c=System.today();
        prm.Type__c='Dealers Meet';
        prm.Total_Expenses__c = 1000;
        prm.Total_no_of_attendees__c = 0;
        prm.State__c = 'Karnataka';
        prm.Location__c = 'BTM';
        prm.Distributor__c=dis1.id;
        insert prm;        
        system.assert(prm.id != null);
        
        ContentVersion cver = new ContentVersion();
        cver.ContentLocation = 'S';
        cver.VersionData = Blob.valueOf('Unit Test Attachment Body');
        cver.PathOnClient = 'Retailer.png';
        cver.Title = 'Retailer Image';
        insert cver;       
        
        
        ContentVersion testContent = [SELECT id, ContentDocumentId FROM ContentVersion where Id = :cver.Id];
        Promotion__c promo = [select id from Promotion__c where id=:prm.id];
        //create ContentDocumentLink  record 
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = 'a0a2F000002whylQAA';
        cdl.ContentDocumentId = testcontent.ContentDocumentId;
        cdl.shareType = 'V';
        insert cdl; 
        
        List<ContentDocument> cdoc = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument where id=:testcontent.ContentDocumentId];
        
        delete cdoc;
    }

}
Hello,

I have trigger on contentdocumentlink where number files added is rollep up on one of the field(Total_no_of_attachment__c) of custom object(promotion__c).But when updating the list,it throwing List index out of bounds: 1  exception.

below is the code:
trigger UploadFilesToPromo on ContentDocumentlink (after insert,after delete,after undelete) {
        List<ContentDocumentLink > data=trigger.isinsert?trigger.new:trigger.old;    
        set<id> promotionid = new set<id>();
        set<id> docId = new set<id>();
        System.debug('data***********'+data+'************');
        
        
        for(ContentDocumentLink att:data)
        {
            promotionid.add(att.LinkedEntityId );
            System.debug('parentID ************'+att.LinkedEntityId +'************');
            System.debug('id in set -promotionid ************'+promotionid);
        }
        
        List<promotion__c> oldpromotionWithAtt = new List<promotion__c>();
        oldpromotionWithAtt =[select id,total_no_of_attachment__c from promotion__c where Id IN:promotionid ];
        for(promotion__c promo : oldpromotionWithAtt) {
            docId.add(promo.Id);
        }
        system.debug('promotionlist.....................................'+oldpromotionWithAtt );
        system.debug('docID set id--------'+docId);
        List<AggregateResult> totalCount= [SELECT count(Id) total FROM ContentDocumentLink WHERE LinkedEntityId IN: docId];
        System.debug('totalcount of files----------------------'+totalCount+'************');
        Integer i=0;
        List<promotion__c> ls = new List<promotion__c>();
        try{
            for(ContentDocumentLink atr:data)
            {
                promotion__c pr=oldpromotionWithAtt.get(i); 
              
                try{
                        pr.Total_No_of_Attachment__c=Integer.valueOf(totalCount[i].get('total'));
                        system.debug('output...............'+pr.Total_No_of_Attachment__c);
                } catch(Exception ex)
                  {    
                        System.debug('exception new   ............'+ex);
                        pr.Total_no_of_attachment__c=0;
                        system.debug('output...............'+pr.Total_no_of_attachment__c);
                  } 
                     i++;
                    ls.add(pr);
                    system.debug('ls list from adding pr'+ls);
                
            }
            
            system.debug('final op============================'+ls);
            if(ls.size()>0 && !ls.IsEmpty()){
                system.debug('ls.size++++++++++++++++++'+ls.size());
                update ls;
            } 
        }
        catch(exception ex1)
        {
            System.debug('exception   ............'+ex1);
        }
        
   }


Thanks in advance.
Hi,

I have VF page ,where onclick of a button redirects to standard account page.The lookups inside standard account page works fine in classic and Lightning if logged through browser.But the same lookups doesn't doesn't fetch results in Salesforce mobile app.
Onclick of a button,it redirects to classic account page in Salesforce app.

Thanks in advance
Hi All,

Is there any way to send report results(records) to non-salesforce users i.e. to external email id
I want to schedule the report on daily basis.
Any help would be appreciated.
Hello,

I have trigger on contentdocumentlink where number files added is rollep up on one of the field(Total_no_of_attachment__c) of custom object(promotion__c).But when updating the list,it throwing List index out of bounds: 1  exception.

below is the code:
trigger UploadFilesToPromo on ContentDocumentlink (after insert,after delete,after undelete) {
        List<ContentDocumentLink > data=trigger.isinsert?trigger.new:trigger.old;    
        set<id> promotionid = new set<id>();
        set<id> docId = new set<id>();
        System.debug('data***********'+data+'************');
        
        
        for(ContentDocumentLink att:data)
        {
            promotionid.add(att.LinkedEntityId );
            System.debug('parentID ************'+att.LinkedEntityId +'************');
            System.debug('id in set -promotionid ************'+promotionid);
        }
        
        List<promotion__c> oldpromotionWithAtt = new List<promotion__c>();
        oldpromotionWithAtt =[select id,total_no_of_attachment__c from promotion__c where Id IN:promotionid ];
        for(promotion__c promo : oldpromotionWithAtt) {
            docId.add(promo.Id);
        }
        system.debug('promotionlist.....................................'+oldpromotionWithAtt );
        system.debug('docID set id--------'+docId);
        List<AggregateResult> totalCount= [SELECT count(Id) total FROM ContentDocumentLink WHERE LinkedEntityId IN: docId];
        System.debug('totalcount of files----------------------'+totalCount+'************');
        Integer i=0;
        List<promotion__c> ls = new List<promotion__c>();
        try{
            for(ContentDocumentLink atr:data)
            {
                promotion__c pr=oldpromotionWithAtt.get(i); 
              
                try{
                        pr.Total_No_of_Attachment__c=Integer.valueOf(totalCount[i].get('total'));
                        system.debug('output...............'+pr.Total_No_of_Attachment__c);
                } catch(Exception ex)
                  {    
                        System.debug('exception new   ............'+ex);
                        pr.Total_no_of_attachment__c=0;
                        system.debug('output...............'+pr.Total_no_of_attachment__c);
                  } 
                     i++;
                    ls.add(pr);
                    system.debug('ls list from adding pr'+ls);
                
            }
            
            system.debug('final op============================'+ls);
            if(ls.size()>0 && !ls.IsEmpty()){
                system.debug('ls.size++++++++++++++++++'+ls.size());
                update ls;
            } 
        }
        catch(exception ex1)
        {
            System.debug('exception   ............'+ex1);
        }
        
   }


Thanks in advance.