• Ralf Wittenberger
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 20
    Replies
@all, for each Object, there is a History Report, but there is no report for users including all Objects, my question/idea is to have only report for users including all Objects. Does anyone already have an idea for that?

I thought, as each user has an id and each object has an id, so shouldn´t it be possible to disconnect the user history from each object to only one object, maybe history (as an object) and fill in a custom field with the id for the object?

Thanks for your ideas
i have a new problem, I receive the error message

List has more than 1 row for assignment to SObject Trigger.MoveAtt: line 9, column 1

for the following trigger.

trigger MoveAtt on Attachment (after insert) {
    List<Id> forDeletionIds = new List<Id>();
    for (Attachment a : trigger.new){
    String parentIdString = String.valueof(a.parentId);
    if (parentIdString.substring(0,3) == '00T'){
        System.debug(a.parentId);
        if(Task.WhatId != null){
            if(Customer_Document__c.Task_ID__c != null){
            Customer_Document__c parent1 = [SELECT Id  FROM Customer_Document__c WHERE Task_ID__c = :a.parentId and CreatedDate__c = :a.CreatedDate ];
        if (parent1.Id  != null){
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                Description = 'Email Attachment from ' + date.today(),
                OwnerId = a.OwnerId,
                ParentId = parent1.Id
            );
        }} 
        task parent = [SELECT Id,WhoId  FROM Task WHERE Id = :a.parentId];
        if (parent.WhoId  != null){
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                Description = 'Email Attachment from ' + date.today(),
                OwnerId = a.OwnerId,
                ParentId = parent.WhoId
            );
            insert newA;
            forDeletionIds.add(a.Id);
        }
      }
    }
List<Attachment> forDeletion = [SELECT Id FROM Attachment WHERE Id IN :forDeletionIds];
delete forDeletion;
    }}
Hi, I would like to post this question again, maybe somebody has an idea, what am i missing or where i failed.

I have a trigger, which can duplicate a attachment, which is linked to an Task to an account with the following trigger


trigger CheckforAttachement on Attachment (before insert) {
    //Check to see if the Attachment has a Task as the Parent Record
   for (Attachment a : trigger.new){
       String parentIdString = String.valueof(a.parentId);
    if (parentIdString.substring(0,3) == '00T'){
        //Select the AccountId from the Task
        task parent = [SELECT AccountId FROM Task WHERE WhatId = :a.parentId];
        //Check to see if the Account exists
        if (parent.AccountID != null){
            //Select the Attachment body (it isn't in memory for an update)
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            //Create a new Attachment, preserving as much as is possible
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                OwnerId = a.OwnerId,
                ParentId = parent.AccountId
            );
            //Insert the new Attachment
            insert newA;
        }}
    }
}


When I tried to adopt this to Leads, it doesn´t work and I have no clue, is there someone, that can maybe help me out here?

When I tried to replace AccountId with LeadId, console tells me "No such column 'LeadID' on entity 'Task'
Therefore, I have added a formular field "LeadID__c" to the Task, which pulls the LeadId from the field WhoId, which is the Name Field (Lookup) for Leads in Tasks.

This is the trigger, i adopted and it doesn´t work

trigger MoveAttToLead on Attachment (after insert, after update) {
    for (Attachment a : trigger.new){
    String parentIdString = String.valueof(a.parentId);
    if (parentIdString.substring(0,3) == '00T'){
        task parent = [SELECT LeadID__c FROM Task WHERE WhoId = :a.parentId];
        if (parent.LeadID__c != null){
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                OwnerId = a.OwnerId,
                ParentId = parent.LeadID__c
            );
            insert newA;
        }}}}
Hi,
i am using email to salesforce, here, whenever an customer is sending email to a specific email it will be automatically forwarded to email to salesforce email. Then the email will be added as a Task to either Lead or Contact, whereever the emailaddress from the customer is linked to.

Now, all attachements are only saved to the Task but I would like to attach them to the Parent Object, such as Lead or Account, is that possible by writing a trigger on Attachement?

Thanks in advance
Hi,
i have a Trigger where I am searching for a value in a case to lookup on accounts to fill in the account id to the case.

The Trigger works well so far in the sandbox, but when i want to validate to get in in production deployed, it returns the following issue:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountOnCases: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times) Trigger.AccountOnCases: line 7, column 1 


Here is the trigger:

trigger AccountOnCases on Case (before insert) {
List<String> Account = new List<String>(); 
for (Case a:Trigger.new)
{
Account.add(a.Customer_Number_Lookup_C__c);
}
List <Account> AccountList = [Select ID from Account where Customer_Number__c in :Account];
    if (AccountList.size() > 0) {
        for (Integer i = 0; i < Trigger.new.size(); i++)
            
        
if (Trigger.new[i].Customer_Number_C__c != null) 
{
Trigger.new[i].AccountID = AccountList[i].ID;
}
else
{
Trigger.new[i].AccountID = null;
}
}
}

Do you have an idea, how to solve this?

Thanks in advance

Ralf
Hi, I have used a Trigger from here to add it to my needs, unfortunately, it seems, I can´t use 2 credentials for the Listlookup, or am i just missing something here?

Trigger ContactOnCases on Case (before insert, before update) {
List<String> Contact = new List<String>(); 
for (Case a:Trigger.new)
{
Contact.add(a.SuppliedEmail && a.Customer_Number_C__c);
}
    List <Contact> ContactList = [Select ID from Contact where  Email && Customer_Number__c  in :Contact ];
    for (Integer i = 0; i < Trigger.new.size(); i++)
        
if (Trigger.new[i].SuppliedEmail != null) {

    Trigger.new[i].ContactID = ContactList[i].ID; 
}
else
{
Trigger.new[i].ContactID = null;
}
}
Hi again,

I have another Question. I have a Code (8digit number) as an internal ID, which is saved into accounts and Contacts.

Now, when a new case is created via Webform, this Code will be submitted, how can i have the relevant Account ID in the Account Lookup field?

Thanks in advance for your help!

Ralf
Hi,
I need to have a lookup field on Account to be filled with Grouping ID upon creating or converting a Account.
Unfortunately, it is not possible to do this with a workflow, so i guess, writing a Trigger oder Code would be the easiest way here, right?
There is another condition for a specific field, if this is filled with specific content.
So, formular, I would have written like:
If(And(isnew(),ispickval(country_responsible_for_account__c,"Germany")),a0fD00...,null)

Is there anyone out here, that can help me with that? 

Thanks a lot in advance for your help

PS: is there anything, you can recommend to learn how to write trigger etc?
i have a new problem, I receive the error message

List has more than 1 row for assignment to SObject Trigger.MoveAtt: line 9, column 1

for the following trigger.

trigger MoveAtt on Attachment (after insert) {
    List<Id> forDeletionIds = new List<Id>();
    for (Attachment a : trigger.new){
    String parentIdString = String.valueof(a.parentId);
    if (parentIdString.substring(0,3) == '00T'){
        System.debug(a.parentId);
        if(Task.WhatId != null){
            if(Customer_Document__c.Task_ID__c != null){
            Customer_Document__c parent1 = [SELECT Id  FROM Customer_Document__c WHERE Task_ID__c = :a.parentId and CreatedDate__c = :a.CreatedDate ];
        if (parent1.Id  != null){
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                Description = 'Email Attachment from ' + date.today(),
                OwnerId = a.OwnerId,
                ParentId = parent1.Id
            );
        }} 
        task parent = [SELECT Id,WhoId  FROM Task WHERE Id = :a.parentId];
        if (parent.WhoId  != null){
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                Description = 'Email Attachment from ' + date.today(),
                OwnerId = a.OwnerId,
                ParentId = parent.WhoId
            );
            insert newA;
            forDeletionIds.add(a.Id);
        }
      }
    }
List<Attachment> forDeletion = [SELECT Id FROM Attachment WHERE Id IN :forDeletionIds];
delete forDeletion;
    }}
Hi, I would like to post this question again, maybe somebody has an idea, what am i missing or where i failed.

I have a trigger, which can duplicate a attachment, which is linked to an Task to an account with the following trigger


trigger CheckforAttachement on Attachment (before insert) {
    //Check to see if the Attachment has a Task as the Parent Record
   for (Attachment a : trigger.new){
       String parentIdString = String.valueof(a.parentId);
    if (parentIdString.substring(0,3) == '00T'){
        //Select the AccountId from the Task
        task parent = [SELECT AccountId FROM Task WHERE WhatId = :a.parentId];
        //Check to see if the Account exists
        if (parent.AccountID != null){
            //Select the Attachment body (it isn't in memory for an update)
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            //Create a new Attachment, preserving as much as is possible
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                OwnerId = a.OwnerId,
                ParentId = parent.AccountId
            );
            //Insert the new Attachment
            insert newA;
        }}
    }
}


When I tried to adopt this to Leads, it doesn´t work and I have no clue, is there someone, that can maybe help me out here?

When I tried to replace AccountId with LeadId, console tells me "No such column 'LeadID' on entity 'Task'
Therefore, I have added a formular field "LeadID__c" to the Task, which pulls the LeadId from the field WhoId, which is the Name Field (Lookup) for Leads in Tasks.

This is the trigger, i adopted and it doesn´t work

trigger MoveAttToLead on Attachment (after insert, after update) {
    for (Attachment a : trigger.new){
    String parentIdString = String.valueof(a.parentId);
    if (parentIdString.substring(0,3) == '00T'){
        task parent = [SELECT LeadID__c FROM Task WHERE WhoId = :a.parentId];
        if (parent.LeadID__c != null){
            Attachment body = [SELECT Body FROM Attachment WHERE Id = :a.Id];
            Attachment newA = New Attachment(
                Name = a.Name,
                Body = body.Body,
                OwnerId = a.OwnerId,
                ParentId = parent.LeadID__c
            );
            insert newA;
        }}}}
Hi,
i am using email to salesforce, here, whenever an customer is sending email to a specific email it will be automatically forwarded to email to salesforce email. Then the email will be added as a Task to either Lead or Contact, whereever the emailaddress from the customer is linked to.

Now, all attachements are only saved to the Task but I would like to attach them to the Parent Object, such as Lead or Account, is that possible by writing a trigger on Attachement?

Thanks in advance
Hi,
i have a Trigger where I am searching for a value in a case to lookup on accounts to fill in the account id to the case.

The Trigger works well so far in the sandbox, but when i want to validate to get in in production deployed, it returns the following issue:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountOnCases: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times) Trigger.AccountOnCases: line 7, column 1 


Here is the trigger:

trigger AccountOnCases on Case (before insert) {
List<String> Account = new List<String>(); 
for (Case a:Trigger.new)
{
Account.add(a.Customer_Number_Lookup_C__c);
}
List <Account> AccountList = [Select ID from Account where Customer_Number__c in :Account];
    if (AccountList.size() > 0) {
        for (Integer i = 0; i < Trigger.new.size(); i++)
            
        
if (Trigger.new[i].Customer_Number_C__c != null) 
{
Trigger.new[i].AccountID = AccountList[i].ID;
}
else
{
Trigger.new[i].AccountID = null;
}
}
}

Do you have an idea, how to solve this?

Thanks in advance

Ralf
Hi, I have used a Trigger from here to add it to my needs, unfortunately, it seems, I can´t use 2 credentials for the Listlookup, or am i just missing something here?

Trigger ContactOnCases on Case (before insert, before update) {
List<String> Contact = new List<String>(); 
for (Case a:Trigger.new)
{
Contact.add(a.SuppliedEmail && a.Customer_Number_C__c);
}
    List <Contact> ContactList = [Select ID from Contact where  Email && Customer_Number__c  in :Contact ];
    for (Integer i = 0; i < Trigger.new.size(); i++)
        
if (Trigger.new[i].SuppliedEmail != null) {

    Trigger.new[i].ContactID = ContactList[i].ID; 
}
else
{
Trigger.new[i].ContactID = null;
}
}
Hi again,

I have another Question. I have a Code (8digit number) as an internal ID, which is saved into accounts and Contacts.

Now, when a new case is created via Webform, this Code will be submitted, how can i have the relevant Account ID in the Account Lookup field?

Thanks in advance for your help!

Ralf
Hi,
I need to have a lookup field on Account to be filled with Grouping ID upon creating or converting a Account.
Unfortunately, it is not possible to do this with a workflow, so i guess, writing a Trigger oder Code would be the easiest way here, right?
There is another condition for a specific field, if this is filled with specific content.
So, formular, I would have written like:
If(And(isnew(),ispickval(country_responsible_for_account__c,"Germany")),a0fD00...,null)

Is there anyone out here, that can help me with that? 

Thanks a lot in advance for your help

PS: is there anything, you can recommend to learn how to write trigger etc?

I'm trying a different approach for programming a trigger I need to update a lookup field called Zipcode_Lookup__c on our Account object from a previous post of mine. I used an example from pacstrats. Here is my code:

 

trigger ZipcodeLookup on Account (before insert, before update) {
List<String> BillingPostalCodes = new List<String>();
for (Account a:Trigger.new)
{
BillingPostalCodes.add(a.BillingPostalCode);
}
List <Zip_Code__c> ZipCodeList = [Select Name from Zip_Code__c where Name in :BillingPostalCodes];
for (Integer i = 0; i < Trigger.new.size(); i++)
{
if (Trigger.new[i].BillingPostalCode != null)
{
Trigger.new[i].Zipcode_Lookup__c = ZipcodeList[i].Name;
}
else
{
Trigger.new[i].Zipcode_Lookup__c = null;
}
}
}

 

The jest of it is to populate the Zipcode_Lookup__c custom lookup field on Account with the BillingPostalCode field on Account if it is available. The lookup is to the Name field on a custom object called Zip_Code__c.

 

When I go to update a record (or add one) I recieve this error: ZipCodeUpdate: execution of BeforeUpdate caused by: System.StringException: Invalid id: 32403: Trigger.ZipCodeUpdate: line 12, column 1

 

I've received this Invalid id exception error with a simple version of this trigger also.

 

I would appreciate any advise as I need this lookup field populated to get around the limitations of Account Assignment rules in the Manage Territories Hierarchy.

 

Thank you!