• Eric Chan 45
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies

Hello! 

I have a trigger that copies AccountTeam to OpportunityTeam After Insert

However, im getting a referencing null exception error when there are no AccountTeamMembers to copy

 

How do i change this to only run if there are AccountTeamMembers to copy over?



 

trigger AcctTeamtoOpp on Opportunity (after insert) {

    List<OpportunityTeamMember> oppTeamMembersList = new List<OpportunityTeamMember>();

Map< Id , Id > opportunityIdToAccountId = new Map< Id , Id >();
for(Opportunity o : Trigger.new)  {
   
        opportunityIdToAccountId.put(o.Id,  o.AccountId );
  
}


Map<id, List<AccountTeamMember > > accountIdToAccountTeamMembers = new    Map<id,  List<AccountTeamMember > > ();
for(AccountTeamMember accountTeamMember : [SELECT a.UserId,a.User.Name,a.TeamMemberRole, a.Id, a.AccountId
                        FROM AccountTeamMember a])   {

        List<AccountTeamMember > accountTeamMembers = ( accountIdToAccountTeamMembers.get(accountTeamMember.Accountid) == null) ?
                                                       new  List<AccountTeamMember >() :
                                                       accountIdToAccountTeamMembers.get(accountTeamMember.Accountid);

        accountTeamMembers.add(accountTeamMember);
        accountIdToAccountTeamMembers.put(accountTeamMember.Accountid, accountTeamMembers);

}



for(Opportunity o : Trigger.new) {
    
        Id accountId  = opportunityIdToAccountId.get(o.Id);
        for ( AccountTeamMember accountTeamMember : accountIdToAccountTeamMembers.get(accountId) )  {
            OpportunityTeamMember opportunityTeamMember  = new OpportunityTeamMember();
            opportunityTeamMember.UserId = accountTeamMember.UserId;
            opportunityTeamMember.TeamMemberRole = accountTeamMember.TeamMemberRole;
            opportunityTeamMember.OpportunityId = o.ID;
            oppTeamMembersList.add(opportunityTeamMember);
       
     }
}

insert oppTeamMembersList;
    
    
}

Hello, im trying to write this trigger for ContentDocuments on Cases

but it seems when i try to locate the Content im not getting any results for my query. 
FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

What am i doing wrong here??

 





trigger JiraAttachmentTrigger on ContentDocument (after insert, after update) {
     // create a set of all the account ids for SOQL below
    Set<id> caseIds = new Set<id>();
    for (ContentDocument c : Trigger.new)    
    caseIds.add(c.Id);
    
    for (ContentDocument att:Trigger.new)
    {
        String id = att.id;
        String parentObjId = att.ParentId;
     
        // create a map so that the account is locatable by its Id
        Map<id, Case> caseMap = new Map<id, Case>(
        [Select id, Jira_Key__c FROM Case WHERE Id = :parentObjId LIMIT 1]);
        
        //Map<id, ContentVersion> cv = new Map<id, ContentVersion>(
        //[SELECT id,VersionData,ContentDocumentId FROM ContentVersion WHERE ContentDocumentId = :id AND IsLatest = true LIMIT 1]);
        
        ContentVersion cv = [SELECT id,VersionData FROM ContentVersion WHERE ContentDocumentId = :id AND IsLatest = true LIMIT 1];
        
        String key = caseMap.Get(parentObjId).Jira_Key__c;
        String file_name = att.title;
        Blob file_body = cv.VersionData;
        
        System.debug('Size of upload file: ' + att.ContentSize);
                  
        JiraAttachment.uploadFile(file_body, file_name, key);
    } 
}

Hey all I just installed Account Contact Relationship Hierarchy by Salesforce Labs
https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000Ecr7DUAR

Its a great app honestly and it does mostly what i want it to do, but it feels like an unfinished product.
I know salesforce labs doesnt offer support and i cant find the source code of this app.

1. whats the point of having a general empty silhouette picture of a head without letting you populate a picture there?
Is there any one that know how i can get this picture to populate form my Linkedin Sales navigator integration?

2. How can i copy the "contact hierarchy" button or have another button link to it? my URL hacking skills are not there.


Thanks!

Hello! 

I have a trigger that copies AccountTeam to OpportunityTeam After Insert

However, im getting a referencing null exception error when there are no AccountTeamMembers to copy

 

How do i change this to only run if there are AccountTeamMembers to copy over?



 

trigger AcctTeamtoOpp on Opportunity (after insert) {

    List<OpportunityTeamMember> oppTeamMembersList = new List<OpportunityTeamMember>();

Map< Id , Id > opportunityIdToAccountId = new Map< Id , Id >();
for(Opportunity o : Trigger.new)  {
   
        opportunityIdToAccountId.put(o.Id,  o.AccountId );
  
}


Map<id, List<AccountTeamMember > > accountIdToAccountTeamMembers = new    Map<id,  List<AccountTeamMember > > ();
for(AccountTeamMember accountTeamMember : [SELECT a.UserId,a.User.Name,a.TeamMemberRole, a.Id, a.AccountId
                        FROM AccountTeamMember a])   {

        List<AccountTeamMember > accountTeamMembers = ( accountIdToAccountTeamMembers.get(accountTeamMember.Accountid) == null) ?
                                                       new  List<AccountTeamMember >() :
                                                       accountIdToAccountTeamMembers.get(accountTeamMember.Accountid);

        accountTeamMembers.add(accountTeamMember);
        accountIdToAccountTeamMembers.put(accountTeamMember.Accountid, accountTeamMembers);

}



for(Opportunity o : Trigger.new) {
    
        Id accountId  = opportunityIdToAccountId.get(o.Id);
        for ( AccountTeamMember accountTeamMember : accountIdToAccountTeamMembers.get(accountId) )  {
            OpportunityTeamMember opportunityTeamMember  = new OpportunityTeamMember();
            opportunityTeamMember.UserId = accountTeamMember.UserId;
            opportunityTeamMember.TeamMemberRole = accountTeamMember.TeamMemberRole;
            opportunityTeamMember.OpportunityId = o.ID;
            oppTeamMembersList.add(opportunityTeamMember);
       
     }
}

insert oppTeamMembersList;
    
    
}

Hello, im trying to write this trigger for ContentDocuments on Cases

but it seems when i try to locate the Content im not getting any results for my query. 
FATAL_ERROR|System.QueryException: List has no rows for assignment to SObject

What am i doing wrong here??

 





trigger JiraAttachmentTrigger on ContentDocument (after insert, after update) {
     // create a set of all the account ids for SOQL below
    Set<id> caseIds = new Set<id>();
    for (ContentDocument c : Trigger.new)    
    caseIds.add(c.Id);
    
    for (ContentDocument att:Trigger.new)
    {
        String id = att.id;
        String parentObjId = att.ParentId;
     
        // create a map so that the account is locatable by its Id
        Map<id, Case> caseMap = new Map<id, Case>(
        [Select id, Jira_Key__c FROM Case WHERE Id = :parentObjId LIMIT 1]);
        
        //Map<id, ContentVersion> cv = new Map<id, ContentVersion>(
        //[SELECT id,VersionData,ContentDocumentId FROM ContentVersion WHERE ContentDocumentId = :id AND IsLatest = true LIMIT 1]);
        
        ContentVersion cv = [SELECT id,VersionData FROM ContentVersion WHERE ContentDocumentId = :id AND IsLatest = true LIMIT 1];
        
        String key = caseMap.Get(parentObjId).Jira_Key__c;
        String file_name = att.title;
        Blob file_body = cv.VersionData;
        
        System.debug('Size of upload file: ' + att.ContentSize);
                  
        JiraAttachment.uploadFile(file_body, file_name, key);
    } 
}

Hey all I just installed Account Contact Relationship Hierarchy by Salesforce Labs
https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000Ecr7DUAR

Its a great app honestly and it does mostly what i want it to do, but it feels like an unfinished product.
I know salesforce labs doesnt offer support and i cant find the source code of this app.

1. whats the point of having a general empty silhouette picture of a head without letting you populate a picture there?
Is there any one that know how i can get this picture to populate form my Linkedin Sales navigator integration?

2. How can i copy the "contact hierarchy" button or have another button link to it? my URL hacking skills are not there.


Thanks!