• Vanisha_Gupta
  • NEWBIE
  • 61 Points
  • Member since 2020

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 15
    Replies
Hi Everyone,

I am trying to copy attachment from Contact to account using below trigger code:
trigger CopyAttachmentsAccountToContact on Attachment (before insert) {
	Set<id> conids=new Set<id>();
    Map<id, Attachment> contactAttachments = new Map<id, Attachment>();
    Map<id, contact> contactsWithAccount = new Map<id, contact>();
    List<Attachment> toBeInserted=new List<Attachment>();
    System.debug('Collecting Accounts having attachment --');
    for(Attachment a : trigger.New){
        if(a.ParentId.getSObjectType()==Account.SObjectType){
            contactAttachments.put(a.ParentID, a);
        }
    }
    
    System.debug('Printing Map<id, Attachment> contactAttachments ----');
    for(ID id:contactAttachments.keySet()){
     	Attachment a = contactAttachments.get(id);
        System.debug('a : '+a);
    
    
    if(contactAttachments.keySet().size()>0){
        contactsWithAccount = new Map<Id, Contact>(
            [SELECT Id, AccountId FROM Contact WHERE Id IN :contactAttachments.keySet()]);
        Contact c=contactsWithAccount.get(a.ParentId);
        Contact con = [Select AccountId,Name from Contact where ID = :c.Id];
        Attachment at = new Attachment (Name = a.Name,Body=a.Body,ParentId=con.AccountId);
        toBeInserted.add(at);
    }
        
    }
    insert toBeInserted;
}

But all i am getting is:
User-added image I am trying to insert new attachment with new parent ID = Account ID.
Then what's the reason behind this error, I am also not seeing debug statements in logs.

Thanks in advance.
Hi!
I am an admin, not a developer and I am trying to overcome the fact that I cannot access the Name of a team member declaratively. 

I found a trigger that does what I need but I am unable to write the test code for the deployment to pass. Can someone help, please??
So frustrating!

Thanks,

Belen
trigger TRG_OpptyTeamMemberName on OpportunityTeamMember (before insert, before update)
{
	Set<Id> setTeamMemberID = new Set<Id>();
	
	for (OpportunityTeamMember otm: Trigger.new)
	{
		setTeamMemberID.add(otm.UserId);
	}

	Map<Id, User> usrMap = new Map<Id, User>([SELECT Id, Name, LastName FROM User WHERE Id IN :setTeamMemberId]);
	
	for (OpportunityTeamMember otm: Trigger.new)
	{
		User usr = usrMap.get(otm.UserId);

		otm.Team_Member_Name__c = usr.Name;
	}
}

 
Hi Everyone,

I am trying to copy attachment from Contact to account using below trigger code:
trigger CopyAttachmentsAccountToContact on Attachment (before insert) {
	Set<id> conids=new Set<id>();
    Map<id, Attachment> contactAttachments = new Map<id, Attachment>();
    Map<id, contact> contactsWithAccount = new Map<id, contact>();
    List<Attachment> toBeInserted=new List<Attachment>();
    System.debug('Collecting Accounts having attachment --');
    for(Attachment a : trigger.New){
        if(a.ParentId.getSObjectType()==Account.SObjectType){
            contactAttachments.put(a.ParentID, a);
        }
    }
    
    System.debug('Printing Map<id, Attachment> contactAttachments ----');
    for(ID id:contactAttachments.keySet()){
     	Attachment a = contactAttachments.get(id);
        System.debug('a : '+a);
    
    
    if(contactAttachments.keySet().size()>0){
        contactsWithAccount = new Map<Id, Contact>(
            [SELECT Id, AccountId FROM Contact WHERE Id IN :contactAttachments.keySet()]);
        Contact c=contactsWithAccount.get(a.ParentId);
        Contact con = [Select AccountId,Name from Contact where ID = :c.Id];
        Attachment at = new Attachment (Name = a.Name,Body=a.Body,ParentId=con.AccountId);
        toBeInserted.add(at);
    }
        
    }
    insert toBeInserted;
}

But all i am getting is:
User-added image I am trying to insert new attachment with new parent ID = Account ID.
Then what's the reason behind this error, I am also not seeing debug statements in logs.

Thanks in advance.
Hi,

I need to find difference between a date field and todays date and check if its equal to exact 60 days.

I used the below statement in code bt its throwing error as 
"Invalid field 60 for object "
Statement:
if(60==Integer.ValueOf(Date.valueof(startdate).daysBetween(System.today())))

Could you please let me know how to achieve this?

Thanks
 
I want to set the formula to set the start date for billing for start of month of always and similarly to set the end date of billing to end of the month. How can i do this.?

Heere is the code.
public class batchApex implements Database.Batchable<sobject> {
    public static List<account> aclist = new List<Account>();
    public static Database.QueryLocator start(Database.BatchableContext bc){
        return Database.getQueryLocator('select Name From Account');
    }
    public static void execute(Database.BatchableContext bc,List<Account> accList){
        
        for(integer i=0;i<50002;i++){
            Account acc = new Account();
            acc.Name='Test'+i;
            acc.AccountNumber='1234567';
            aclist.add(acc);            
        }
        insert aclist;
    }
    public static void finish(Database.BatchableContext bc){
        
    }
    
}

batchApex obj = new batchApex();
Database.executeBatch(obj,2000);
It show error that Too many DML rows: 10001.
Batch apex can process upto 5million record .Why it showin error.
And
If the first transaction succeeds but the second fails, the database updates made in the first transaction are not rolled back. How it works ?
This code doesnt work.



trigger CreateCase on Contact (before insert) {
 
    List<Case> listCase = new List<Case>();
     for(Contact a : Trigger.New) {  
          listCase.add(new Case(
          AccountID=a.AccountID,        
          ContactID = a.Name,
          Priority ='High',
          Origin = 'Phone',
          Status = 'Working')); 
          }
       
     if(listCase.size() > 0)
  {
        insert listCase;
    }
}
I have a very simple formula so I can render the Schedule Date down to the actual Month. However, there are 175 instances where even though the schedule date is clearly a specific month, the formula is rendering a 'NONE' output meaning the month does not numerically line up with a specific MONTH.


API Name of the field in the line item schedule objct=Schedule_Date_Month_NAME__c

CASE(MONTH(ScheduleDate),
1, "January",
2, "February",
3, "March",
4, "April",
5, "May",
6, "June",
7, "July",
8, "August",
9, "September",
10, "October",
11, "November",
12, "December", "None")
1. Associate the content delivery with Salesforce record
2. Password Protect content delivery that contain sensitive data
3. Customize the URL assigned to the Content delivery
4. Encrypt certain content delivery files

Kindly Help!