• Sfdc Couple
  • NEWBIE
  • 55 Points
  • Member since 2019

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 9
    Replies

Hello,
the code sent two time post chatter for the sames WhoId.
If condition found two Task
The code sent post chatter in first for the first WhoId, in second for the first and the second WhoId.
What can I do please ?
Thanks

Code: 
public ConnectApi.FeedElement CreatePostChatterRDV(){
        ConnectApi.FeedElement AlertPostChatter;
        
        
        List<Task> TaskAlert = new List<Task>();
        List<Task> listTask = [select OwnerId, WhoId, ActivityDate, Created_from_Visit_planner__c from task];
        for(Task ta: listTask){
            if(ta.ActivityDate == Date.today() && ta.Created_from_Visit_planner__c == true){
                //system.debug(ta);
                TaskAlert.add(ta);
                System.debug(TaskAlert);
                for(Task tb: TaskAlert){
                    List<User> utilisateur = [select Name from user where id = :tb.OwnerId];
                    for(User us: utilisateur){
                        
                        ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
                        ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
                        ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
                        ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
                        messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
                        
                        mentionSegmentInput.id = tb.OwnerId;
                        messageBodyInput.messageSegments.add(mentionSegmentInput);
                        
                        textSegmentInput.text = ' ' + MessagePostChatter(us.Name);
                        messageBodyInput.messageSegments.add(textSegmentInput);
                        
                        feedItemInput.body = messageBodyInput;
                        feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
                        feedItemInput.subjectId = ta.WhoId;
                        
                        AlertPostChatter = ConnectApi.ChatterFeeds.postFeedElement(null, feedItemInput);
                    }
                }
                
            }
        }
        return AlertPostChatter;
    }

 

Please find my trigger  in code sample and suggest me how to write a test class for helper class.

Trigger :

trigger ContentDocument on ContentDocument (after insert) 
{
 if(Trigger.isAfter && Trigger.isInsert)
   {
   
  //1. SELECT THE OPPORTUNITY TEAM
  SET<ID> SetOfContentDocumentIDs = new SET<ID>();
  for(ContentDocument cdoc: Trigger.New)
  {
    SetOfContentDocumentIDs.add(cdoc.Id);
  } 
 
  //2. Sharing Files With Opportunity Team
  ContentDocumentHelper.shareOpportunityPrivateFileWithOppTeam(SetOfContentDocumentIDs);
  }
  
}

Helper Class:

public class ContentDocumentHelper{

 @future
 public static void shareOpportunityPrivateFileWithOppTeam(SET<ID> SetOfContentDocumentIDs)
 {
    
    System.Debug('AM: SetOfContentDocumentIDs :' + SetOfContentDocumentIDs);
    List<ContentDocumentLink> ListOfContentDocumentLink = new List<ContentDocumentLink>();
    
    integer i = 0;
    while(i <=80 && ListOfContentDocumentLink.size()<=1 )
    {
      ListOfContentDocumentLink = [ SELECT LinkedEntityId,ContentDocumentId 
                                    FROM ContentDocumentLink 
                                    WHERE ContentDocumentId IN : SetOfContentDocumentIDs];
      i++;
    }
                                                             
  //2.Get OpportunityTeamMember  
  SET<ID> SetOfOpportunityIDs = new SET<ID>();
  for(ContentDocumentLink cdl : ListOfContentDocumentLink )
  {
    SetOfOpportunityIDs.add(cdl.LinkedEntityId);
  } 
  
  System.Debug('AM: SetOfOpportunityIDs : ' + SetOfOpportunityIDs );
  
   
  List<OpportunityTeamMember> ListofOpportunityTeamMember =  [SELECT UserId,OpportunityId 
                                                              FROM OpportunityTeamMember 
                                                              WHERE OpportunityId IN : SetOfOpportunityIDs];
  
  
  System.Debug('AM: ListofOpportunityTeamMember :' + ListofOpportunityTeamMember );
  
  MAP<ID,SET<ID>> MapOfOppIDSetUsersID = new MAP<ID,SET<ID>>();
  
  for(OpportunityTeamMember oppteam :ListofOpportunityTeamMember )
  {
    if(MapOfOppIDSetUsersID.get(oppteam.OpportunityId) == null)
    {
      SET<ID> SetofUserID = new SET<ID>();
      SetofUserID.add(oppteam.UserId);
      MapOfOppIDSetUsersID.put(oppteam.OpportunityId,SetofUserID);
    }
    else
    {
      SET<ID> SetofUserID = MapOfOppIDSetUsersID.get(oppteam.OpportunityId);
      SetofUserID.add(oppteam.UserId);
      MapOfOppIDSetUsersID.put(oppteam.OpportunityId,SetofUserID);
      
    }
  }
  
  System.Debug('AM: MapOfOppIDSetUsersID: ' + MapOfOppIDSetUsersID);
 
  //3.Process the documents and share with users
  List<ContentDocumentLink > ListofUserShare = new List<ContentDocumentLink >();
  
  for(ContentDocumentLink cdl: ListOfContentDocumentLink)
  {
    
   SET<ID> SetofUserIDs = new SET<ID>();
   SetofUserIDs = MapOfOppIDSetUsersID.get(cdl.LinkedEntityId);
   if(SetofUserIDs!=null)
   { 
    if(SetofUserIDs.size()>0)
    {
     for(ID userID: SetofUserIDs)
     {
       if(!SetOfOpportunityIDs.contains(userID))
       {
         ListofUserShare.add(
            new ContentDocumentLink (
                  ContentDocumentId = cdl.ContentDocumentId ,
                  LinkedEntityId = userID,
                  ShareType = 'C'
                )
         );
       }
    }
   }
  }  
  } 
  
  System.Debug('AM: ListofUserShare : ' + ListofUserShare);
  
  if(ListofUserShare.size()>0)
  {
    insert ListofUserShare;
  }
}

}


Test Class:

@isTest
public class ContentDocumentTest {
@istest    
 public static  void test() {
            
           
        
                    
           Opportunity o = New Opportunity ();
           o.StageName ='Open';
           
           o.CloseDate=System.today() + 5;
           o.Name='Test NL Opportunity';
           
           insert o;             
            
            
        List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

        ContentDocumentLink contentlink=new ContentDocumentLink();
        contentlink.LinkedEntityId=o.Id;
        contentlink.ShareType= 'v';
        contentlink.LinkedEntityId = o.id;
        contentlink.ContentDocumentId=documents[0].Id;
        contentlink.Visibility = 'AllUsers'; 
        insert contentlink;          
            
               
             
           
        } 
}

Please help​​​​​​​
My SOQL  query:


for(Account[] acc:[Select Id,name,(select Id,name from opportunities), (Select id, email from contact) from account ])


i want in apex. So kindly help me out here
I want Title, First Name, Mobile no. , Query Detail  and  Subject  to be mapped to the lead field that I have created.
After I write their content while sending an email to perform email to lead.
The fields should be automatically filled with the content present in the email.
Please help!
Thanks in advance.
  • October 07, 2019
  • Like
  • 0
How to populate value in Contact.photoURL  

While executing below code, getting below error 

contact c = new contact (id = '0030o00002cWalwAAC');
c.photoURL = '/servlet/servlet.FileDownload?file=0150o00000HDM4s';
update c;    

Field is not writeable: Contact.PhotoUrl.

Could you please help me to execute below error.
 
This is probably a super simple question... I built a lightning component that consists of images and direct you to different pages when you click on them. 
User-added image

The buttons work fine, but the cursor doen't change to a pointer icon when you hover over the image. Please help me update my code:

Component
<aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
    <div class="c-container">
        <div class="slds-grid slds-grid_align-center">
            <div class="slds-col slds-p-right_xx-large" onclick="{!c.startNewApplication}">
                <img src="{!$Resource.LexPartnerPortalCreateNCA}"/>
            </div>
            <div class="slds-col slds-p-right_xx-large" onclick="{!c.createLendingCircle}">
                <img src="{!$Resource.LexPartnerPortalCreateLC}"/>
            </div>
        </div>
    </div>
</aura:component>

Controller
({
    startNewApplication : function (cmp, event, helper) {
        window.location.href = '/lightningPartners/PublicClientApplication';
    },

    createLendingCircle : function (cmp, event, helper) {
        window.location.href = '/lightningPartners/partnercreatelendingcircle';
    },

    submitACase: function (cmp, event, helper) {
        window.location.href = '/lightningPartners/s/createrecord/NewCase';
    }
})

Hello,
the code sent two time post chatter for the sames WhoId.
If condition found two Task
The code sent post chatter in first for the first WhoId, in second for the first and the second WhoId.
What can I do please ?
Thanks

Code: 
public ConnectApi.FeedElement CreatePostChatterRDV(){
        ConnectApi.FeedElement AlertPostChatter;
        
        
        List<Task> TaskAlert = new List<Task>();
        List<Task> listTask = [select OwnerId, WhoId, ActivityDate, Created_from_Visit_planner__c from task];
        for(Task ta: listTask){
            if(ta.ActivityDate == Date.today() && ta.Created_from_Visit_planner__c == true){
                //system.debug(ta);
                TaskAlert.add(ta);
                System.debug(TaskAlert);
                for(Task tb: TaskAlert){
                    List<User> utilisateur = [select Name from user where id = :tb.OwnerId];
                    for(User us: utilisateur){
                        
                        ConnectApi.FeedItemInput feedItemInput = new ConnectApi.FeedItemInput();
                        ConnectApi.MentionSegmentInput mentionSegmentInput = new ConnectApi.MentionSegmentInput();
                        ConnectApi.MessageBodyInput messageBodyInput = new ConnectApi.MessageBodyInput();
                        ConnectApi.TextSegmentInput textSegmentInput = new ConnectApi.TextSegmentInput();
                        messageBodyInput.messageSegments = new List<ConnectApi.MessageSegmentInput>();
                        
                        mentionSegmentInput.id = tb.OwnerId;
                        messageBodyInput.messageSegments.add(mentionSegmentInput);
                        
                        textSegmentInput.text = ' ' + MessagePostChatter(us.Name);
                        messageBodyInput.messageSegments.add(textSegmentInput);
                        
                        feedItemInput.body = messageBodyInput;
                        feedItemInput.feedElementType = ConnectApi.FeedElementType.FeedItem;
                        feedItemInput.subjectId = ta.WhoId;
                        
                        AlertPostChatter = ConnectApi.ChatterFeeds.postFeedElement(null, feedItemInput);
                    }
                }
                
            }
        }
        return AlertPostChatter;
    }

 

Please find my trigger  in code sample and suggest me how to write a test class for helper class.

Trigger :

trigger ContentDocument on ContentDocument (after insert) 
{
 if(Trigger.isAfter && Trigger.isInsert)
   {
   
  //1. SELECT THE OPPORTUNITY TEAM
  SET<ID> SetOfContentDocumentIDs = new SET<ID>();
  for(ContentDocument cdoc: Trigger.New)
  {
    SetOfContentDocumentIDs.add(cdoc.Id);
  } 
 
  //2. Sharing Files With Opportunity Team
  ContentDocumentHelper.shareOpportunityPrivateFileWithOppTeam(SetOfContentDocumentIDs);
  }
  
}

Helper Class:

public class ContentDocumentHelper{

 @future
 public static void shareOpportunityPrivateFileWithOppTeam(SET<ID> SetOfContentDocumentIDs)
 {
    
    System.Debug('AM: SetOfContentDocumentIDs :' + SetOfContentDocumentIDs);
    List<ContentDocumentLink> ListOfContentDocumentLink = new List<ContentDocumentLink>();
    
    integer i = 0;
    while(i <=80 && ListOfContentDocumentLink.size()<=1 )
    {
      ListOfContentDocumentLink = [ SELECT LinkedEntityId,ContentDocumentId 
                                    FROM ContentDocumentLink 
                                    WHERE ContentDocumentId IN : SetOfContentDocumentIDs];
      i++;
    }
                                                             
  //2.Get OpportunityTeamMember  
  SET<ID> SetOfOpportunityIDs = new SET<ID>();
  for(ContentDocumentLink cdl : ListOfContentDocumentLink )
  {
    SetOfOpportunityIDs.add(cdl.LinkedEntityId);
  } 
  
  System.Debug('AM: SetOfOpportunityIDs : ' + SetOfOpportunityIDs );
  
   
  List<OpportunityTeamMember> ListofOpportunityTeamMember =  [SELECT UserId,OpportunityId 
                                                              FROM OpportunityTeamMember 
                                                              WHERE OpportunityId IN : SetOfOpportunityIDs];
  
  
  System.Debug('AM: ListofOpportunityTeamMember :' + ListofOpportunityTeamMember );
  
  MAP<ID,SET<ID>> MapOfOppIDSetUsersID = new MAP<ID,SET<ID>>();
  
  for(OpportunityTeamMember oppteam :ListofOpportunityTeamMember )
  {
    if(MapOfOppIDSetUsersID.get(oppteam.OpportunityId) == null)
    {
      SET<ID> SetofUserID = new SET<ID>();
      SetofUserID.add(oppteam.UserId);
      MapOfOppIDSetUsersID.put(oppteam.OpportunityId,SetofUserID);
    }
    else
    {
      SET<ID> SetofUserID = MapOfOppIDSetUsersID.get(oppteam.OpportunityId);
      SetofUserID.add(oppteam.UserId);
      MapOfOppIDSetUsersID.put(oppteam.OpportunityId,SetofUserID);
      
    }
  }
  
  System.Debug('AM: MapOfOppIDSetUsersID: ' + MapOfOppIDSetUsersID);
 
  //3.Process the documents and share with users
  List<ContentDocumentLink > ListofUserShare = new List<ContentDocumentLink >();
  
  for(ContentDocumentLink cdl: ListOfContentDocumentLink)
  {
    
   SET<ID> SetofUserIDs = new SET<ID>();
   SetofUserIDs = MapOfOppIDSetUsersID.get(cdl.LinkedEntityId);
   if(SetofUserIDs!=null)
   { 
    if(SetofUserIDs.size()>0)
    {
     for(ID userID: SetofUserIDs)
     {
       if(!SetOfOpportunityIDs.contains(userID))
       {
         ListofUserShare.add(
            new ContentDocumentLink (
                  ContentDocumentId = cdl.ContentDocumentId ,
                  LinkedEntityId = userID,
                  ShareType = 'C'
                )
         );
       }
    }
   }
  }  
  } 
  
  System.Debug('AM: ListofUserShare : ' + ListofUserShare);
  
  if(ListofUserShare.size()>0)
  {
    insert ListofUserShare;
  }
}

}


Test Class:

@isTest
public class ContentDocumentTest {
@istest    
 public static  void test() {
            
           
        
                    
           Opportunity o = New Opportunity ();
           o.StageName ='Open';
           
           o.CloseDate=System.today() + 5;
           o.Name='Test NL Opportunity';
           
           insert o;             
            
            
        List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

        ContentDocumentLink contentlink=new ContentDocumentLink();
        contentlink.LinkedEntityId=o.Id;
        contentlink.ShareType= 'v';
        contentlink.LinkedEntityId = o.id;
        contentlink.ContentDocumentId=documents[0].Id;
        contentlink.Visibility = 'AllUsers'; 
        insert contentlink;          
            
               
             
           
        } 
}

Please help​​​​​​​
Does any one have idea to compare two text fields(alphanumeric)?
My requirement is Field1 should always be lesser than Field2.

For eg.
Scenario 1: 
Field1 is ABC000 and Field 2 is XYZ000. In this case, validation will not display an error.

Scenario 2:
Field1 is XYZ000 and Field 2 is ABC000. In this case, validation will  display an error.

Scenario 3: 
Field1 is XYZ006 and Field 2 is XYZ004. In this case, validation will  display an error.

Scenario 3: 
Field1 is XZZ006 and Field 2 is XYZ004. In this case, validation will  display an error.

Thanks!