• Jan Kopejtko 2
  • NEWBIE
  • 135 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 36
    Questions
  • 20
    Replies
This is a very concerning issue.

We need to access favourites in our mobile app. It suddenly stopped working. Has anyone found a way to deal with this? This is causing big trouble now.
Hello, I don't know how to bulkify this. Please help
 
trigger QuoteLineItemEmailBeforeDelete on QuoteLineItem (after delete) {
    Set<Id> quids = new Set<Id>();

    for(QuoteLineItem qli :Trigger.Old) {
        quids.add(qli.QuoteId);
    }

    Quote[] quo = [Select Id, Name, Status, RecordTypeId from Quote Where id In :quids];

    if((quo[0].Status == '2. Validated - Waiting for order' || quo[0].Status == '3. Offer partially entered in SAP' || quo[0].Status == '4. Offer fully entered in SAP')&& (Quo[0].Name.Contains('H3'))) {
  Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (QuoteLineItem qli : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'becommingaprogrammer@example.com'});
        email.setSubject('Oznámení o změně nabídky');
        email.setPlainTextBody('Došlo ke změně nabídky ' + Quo[0].Name + '.\n\n' + 'Pro otevření záznamu v Salesforce klikněte na následující odkaz:\n\n' +  'https://sg--testing.lightning.force.com/lightning/r/Quote/' + quo[0].Id + '/view');
        emails.add(email);
    }

    Messaging.sendEmail(emails);
        
    }
}

 
I need to automate a process that will always copy specified parts of uploaded attachments that are in PDF format.

Let's say I want to always copy the logo which appears on such PDF and always is on the same place in the PDF. I want to copy it and paste it as another attachment but with a link to different object.

How should I proceed? Is it even possible?
This one is level: insanity. I'll try my luck anyways.

I have a Field Service Lightning mobile app. We take digital signatures and create service reports.

I need to copy those digital signatures after the user inputs them into the phone. I need to copy them and move them to another object related to Service Appointment, where the service report is saved.

Issue: Trigger on object DigitalSignature is not supported by Salesforce. Is there any other way how to do this?
Hello, I have a simple trigger to send an email after deletion of a Quote line item record. It takes some information from the parent Quote like:
Status and Name.
 
trigger QuoteLineItemEmailBeforeDelete on QuoteLineItem (after delete) {
    Set<Id> quids = new Set<Id>();
    for(QuoteLineItem qli :Trigger.Old) {
        quids.add(qli.QuoteId);
    }
    Quote[] quo = [Select Id, Name, Status, RecordTypeId from Quote Where id In :quids];
    if((quo[0].Status == '2. Validated - Waiting for order' || quo[0].Status == '3. Offer partially entered in SAP' || quo[0].Status == '4. Offer fully entered in SAP')&& (Quo[0].Name.Contains('H3'))) {
  Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (QuoteLineItem qli : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'becommingaprogrammer@example.com'});
        email.setSubject('Oznámení o změně nabídky');
        email.setPlainTextBody('Došlo ke změně nabídky ' + Quo[0].Name + '.\n\n' + 'Pro otevření záznamu v Salesforce klikněte na následující odkaz:\n\n' +  'https://sg--testing.lightning.force.com/lightning/r/Quote/' + quo[0].Id + '/view');
        emails.add(email);
    }
    Messaging.sendEmail(emails);
        
    }
}

The thing is I don't know how to bulkify the code. What if someone mass deletes let's say 100 records? What if those records will each have a different Quote?

How do I then pair the deleted record with the parent quote to evalute if the email should be sent based on Status or Name?
Hello, I've got a trigger, which causes that I am unable to delete records. This shows up:

There's a problem saving this record. You might not have permission to edit it, or it might have been deleted or archived. Contact your administrator for help.

 
trigger QuoteLineItemEmailBeforeDelete on QuoteLineItem (before delete) {
    Set<Id> quids = new Set<Id>();
    for(QuoteLineItem qli :Trigger.Old) {
        quids.add(qli.QuoteId);
    }
    Quote[] quo = [Select Id from Quote Where id In :quids];
  Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (QuoteLineItem qli : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'test@example.com'});
        email.setSubject('Oznámení o změně nabídky');
        email.setPlainTextBody('Došlo ke změně nabídky' + Quo[0].Name + '.<br>' + 'Pro otevření záznamu v Salesforce klikněte na následující odkaz:<br>' +  URL.getSalesforceBaseUrl().toExternalForm() + '/' + qli.Id);
        emails.add(email);
    }
    Messaging.sendEmail(emails);
}

 
Hey guys, I need to notify a user when complaint line item was created 25 days ago and complaint status is not equal to completed. How do I do that?

With process builder I did not find a way, check the screenshot.

User-added image
Okay fellas, this one is a toughie.

I have a trigger that is before update on object A. I have a field on the same object which is updated by a process.

I need to somehow make an if statement in the trigger NOT to fire if the value in the field is changed. This is a before update trigger. Is it even possible?
Hello,

I'm trying to scheldule an action 10 days after creation of a record.

That is easy, just use process builder and scheldule action after 10 days of creation. But there is a catch:

The schelduled action should run only if the status of the record is not equal to COMPLETED. Is that possible???
How do I send an email notification to a user?

I need to send it 25 days after creation of a record. This should be simple but I don't know if there is some standard function for this or I have to use formula?
I have a simple trigger on ContentDocumentLink. The trigger finds the linked record's field and stores it's value in a ContentVersion field Title.

So we have four objects that are linked like this: ContentVersion -> ContentDocument -> ContentDocumentLink -> Some object

I take field from Some object and populate ContentVersion Title with the value. There is the code:
 
trigger ContentDocumentLink on ContentDocumentLink (before insert) {
    Set<Id> aids = new Set<Id>();
    Set<Id> bids = new Set<Id>();
    Set<Id> cids = new Set<Id>();
    Set<Id> dids = new Set<Id>();
    
    for(ContentDocumentLink a :Trigger.New) {
        aids.add(a.Id);
        bids.add(a.ContentDocumentId);
        cids.add(a.LinkedEntityId);
        
    }
	ContentDocument[] b = [Select Id, LatestPublishedVersionId, Title from ContentDocument Where Id in :bids];
    
    for(ContentDocument c :b) {
        dids.add(c.LatestPublishedVersionId);
     
    ContentVersion[] d = [Select Id, Title from ContentVersion where Id in :dids];
        for(ContentVersion e :d) {
            e.Title = 'letitgo';
            update e;
        }
        
    }
    

}

Question is how do I write the test class? I have 4 linked objects I need to use. Which one do I insert first?
 
Hey guys, I'm trying to get through this. I have this code:
 
trigger ContentVersionTitleUpdate on ContentVersion (before insert) {
      List<Id> saids = new List<Id>();
    Set<Id> cdids = new Set<Id>();
    for(ContentVersion a :Trigger.New) {
        if(a.ContentDocumentId != null){
            cdids.add(a.ContentDocumentId);
        }
        ContentDocument[] cd = [Select Id, ParentId From ContentDocument where Id in :cdids];
        if(cd[0] != null) {
            saids.add(cd[0].ParentId);
        }
        ServiceAppointment[] sa = [Select Id, FileTitle__c From ServiceAppointment where Id in :saids];
        for (ContentVersion b :Trigger.New){
            
        if(sa != null) {
            if(sa[0].FileTitle__c != 'DefaultValue') {
            b.Title = sa[0].FileTitle__c;
            }
            
        }
        }
        
       
    }

}

The problem is when I upload a file, it says this:
 
Trigger.ContentVersionTitleUpdate: line 9, column 1
19:08:54.0 (12583025)|FATAL_ERROR|System.ListException: List index out of bounds: 0

I think it means that the "a.ContentDocumentId" does not exist, so I can not use it. That is why cdaids is empty, hence the error.

The idea is that the trigger must get the ID of the related record of the file. Everything else is easy now. ContentVersion does not have a link to the related record, only ContentDocument has that (ParentId). Please give me an idea how to fix this?
Following the previous question: https://developer.salesforce.com/forums/ForumsMain?id=9062I000000XsipQAC

Hello,

I need to update a file title after it's upload.

That is an easy trigger, but here is the catch:

On object A is a text field. Each record of object A has some value in the text field. After I upload the file to the object A's record, I need to take the value in the text field of the record and set is as a title of the newly uploaded file.

Mr. PRAKASH JADA 13 helped me with the code:
 
Hi,


Trigger:
--------------------------
trigger AttcahmentTrigger on Attachment (before insert) {
    if(Trigger.isBefore) {
        if(Trigger.isInsert) {
            AttcahmentTriggerHandler.onBeforeInsert(Trigger.New);
        }
    }
}


Trigger Handler:
----------------------------------
/*
 * Author: Prakash
 * CreatedDate: Feb 14, 20202
*/
public with sharing class AttcahmentTriggerHandler {
    public static void onBeforeInsert(List<Attachment> attachments) {
        
        List<Id> accountIds = new List<Id>();
        
        //Loop to iterate over the list of attachments        
        for(Attachment att : attachments) {
            if(att.ParentId != null) {
                accountIds.add(att.ParentId); // Preparing the account Ids
            }
        }
        
        if(!accountIds.isEmpty()) {
            // Preparing the map that holds the account Name as a value and Id as a key
            Map<Id, Account> accountMap = new Map<Id,Account>([SELECT ID, Name FROM Account WHERE Id = :accountIds]);
            
            // Loop to iterate over the list of Attachments
            for(Attachment att : attachments) {
                att.Name = accountMap.get(att.ParentId).Name;
            }
            
        }
        
    }
}
But there is another catch to it - by object A I mean object SERVICE APPOINTMENT, which does not support the Attachment object.

Help me please!
 
Hello,

I need to update a file title after it's upload.

That is an easy trigger, but here is the catch:

On object A is a text field. Each record of object A has some value in the text field. After I upload the file to the object A's record, I need to take the value in the text field of the record and set is as a title of the newly uploaded file.

I don't know how to query for that. File is ContentDocument, but there has to be a different way. Thanks alot. Jan
Hey guys, I have a simple trigger before change:
 
trigger AssemblyDiaryEditValidation on Assembly_diary__c (before update) {
    Set<Id> aids = new Set<Id>();
	Set<Id> saids = new Set<Id>();
    Set<Id> sraids = new Set<Id>();
    for(Assembly_diary__c a :trigger.old) {
        aids.add(a.Id);
        saids.add(a.Service_Appointment__c);
    }
    ServiceAppointment[] sa = [Select Id From ServiceAppointment where Id in :saids];
    AssignedResource[] ar = [Select Id, ServiceResourceId From AssignedResource where ServiceAppointmentId in :saids];
    if(ar != null) {
        sraids.add(ar[0].ServiceResourceId);
    }
    ServiceResource[] sr = [Select Id, RelatedRecordId From ServiceResource where Id in :sraids]; 
    for (Assembly_diary__c b :trigger.old) {
    for(integer i = 0; i < Trigger.new.size(); i++) {
        if(sr != null) {
            if(sr[0].RelatedRecordId != UserInfo.getUserId()) {
                b.addError('Nejste oprávněni upravit tuto položku');
            }
        }
    }
    }
}

I get the error message SObject row does nto allow errors on line 19. I know that you can use the addError method for only those records that are avaliable in Trigger Context. But I thought i fixed it? How do I fix this?
Hey guys,

Person Accounts are enabled. I need a formula on an object to reflect whether an Account is person account or not. How do I do that?

Let's say I have an object A that has lookup to Account. On this object A I also need a formula checkbox that will equal to TRUE if the lookup is populated with an Account that is a Person Account.

How do I do that?

Thanks all
Hey guys,

when I open a Service Appointment and go to Related -> Assembly Diaries and from the Assembly Diary record go to Related -> Assembly Diary Entries and click on the Assembly Diary Entry record, it won't open!

It says I need to download Salesforce1 app to open those related entries of Assembly diary. I need to access them directly from FSL Mobile app, how is that possible?
Guys, is there a way in Salesforce how to populate a TEXT field with an ID that is in a lookup field?

I am creating a record in Flow and the ID just wont get passed to the field. The field remains null.
Hey, when I am adding a line item to an object, I can search the object via name and then one another field:

User-added image

Can I customize which field is searchable? I'd like to leave the Product Name as it is, just change the second field under it so the products are searchable by this field.
Hey guys,

is there any way how to fire a process from a formula change? I heard that before it was possible but not now.

I'd really need to use that.
This is a very concerning issue.

We need to access favourites in our mobile app. It suddenly stopped working. Has anyone found a way to deal with this? This is causing big trouble now.
Hello, I've got a trigger, which causes that I am unable to delete records. This shows up:

There's a problem saving this record. You might not have permission to edit it, or it might have been deleted or archived. Contact your administrator for help.

 
trigger QuoteLineItemEmailBeforeDelete on QuoteLineItem (before delete) {
    Set<Id> quids = new Set<Id>();
    for(QuoteLineItem qli :Trigger.Old) {
        quids.add(qli.QuoteId);
    }
    Quote[] quo = [Select Id from Quote Where id In :quids];
  Messaging.reserveSingleEmailCapacity(trigger.size);
    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
    for (QuoteLineItem qli : Trigger.old) {
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'test@example.com'});
        email.setSubject('Oznámení o změně nabídky');
        email.setPlainTextBody('Došlo ke změně nabídky' + Quo[0].Name + '.<br>' + 'Pro otevření záznamu v Salesforce klikněte na následující odkaz:<br>' +  URL.getSalesforceBaseUrl().toExternalForm() + '/' + qli.Id);
        emails.add(email);
    }
    Messaging.sendEmail(emails);
}

 
Okay fellas, this one is a toughie.

I have a trigger that is before update on object A. I have a field on the same object which is updated by a process.

I need to somehow make an if statement in the trigger NOT to fire if the value in the field is changed. This is a before update trigger. Is it even possible?
Hello,

I'm trying to scheldule an action 10 days after creation of a record.

That is easy, just use process builder and scheldule action after 10 days of creation. But there is a catch:

The schelduled action should run only if the status of the record is not equal to COMPLETED. Is that possible???
I have a simple trigger on ContentDocumentLink. The trigger finds the linked record's field and stores it's value in a ContentVersion field Title.

So we have four objects that are linked like this: ContentVersion -> ContentDocument -> ContentDocumentLink -> Some object

I take field from Some object and populate ContentVersion Title with the value. There is the code:
 
trigger ContentDocumentLink on ContentDocumentLink (before insert) {
    Set<Id> aids = new Set<Id>();
    Set<Id> bids = new Set<Id>();
    Set<Id> cids = new Set<Id>();
    Set<Id> dids = new Set<Id>();
    
    for(ContentDocumentLink a :Trigger.New) {
        aids.add(a.Id);
        bids.add(a.ContentDocumentId);
        cids.add(a.LinkedEntityId);
        
    }
	ContentDocument[] b = [Select Id, LatestPublishedVersionId, Title from ContentDocument Where Id in :bids];
    
    for(ContentDocument c :b) {
        dids.add(c.LatestPublishedVersionId);
     
    ContentVersion[] d = [Select Id, Title from ContentVersion where Id in :dids];
        for(ContentVersion e :d) {
            e.Title = 'letitgo';
            update e;
        }
        
    }
    

}

Question is how do I write the test class? I have 4 linked objects I need to use. Which one do I insert first?
 
Hey guys, I'm trying to get through this. I have this code:
 
trigger ContentVersionTitleUpdate on ContentVersion (before insert) {
      List<Id> saids = new List<Id>();
    Set<Id> cdids = new Set<Id>();
    for(ContentVersion a :Trigger.New) {
        if(a.ContentDocumentId != null){
            cdids.add(a.ContentDocumentId);
        }
        ContentDocument[] cd = [Select Id, ParentId From ContentDocument where Id in :cdids];
        if(cd[0] != null) {
            saids.add(cd[0].ParentId);
        }
        ServiceAppointment[] sa = [Select Id, FileTitle__c From ServiceAppointment where Id in :saids];
        for (ContentVersion b :Trigger.New){
            
        if(sa != null) {
            if(sa[0].FileTitle__c != 'DefaultValue') {
            b.Title = sa[0].FileTitle__c;
            }
            
        }
        }
        
       
    }

}

The problem is when I upload a file, it says this:
 
Trigger.ContentVersionTitleUpdate: line 9, column 1
19:08:54.0 (12583025)|FATAL_ERROR|System.ListException: List index out of bounds: 0

I think it means that the "a.ContentDocumentId" does not exist, so I can not use it. That is why cdaids is empty, hence the error.

The idea is that the trigger must get the ID of the related record of the file. Everything else is easy now. ContentVersion does not have a link to the related record, only ContentDocument has that (ParentId). Please give me an idea how to fix this?
Following the previous question: https://developer.salesforce.com/forums/ForumsMain?id=9062I000000XsipQAC

Hello,

I need to update a file title after it's upload.

That is an easy trigger, but here is the catch:

On object A is a text field. Each record of object A has some value in the text field. After I upload the file to the object A's record, I need to take the value in the text field of the record and set is as a title of the newly uploaded file.

Mr. PRAKASH JADA 13 helped me with the code:
 
Hi,


Trigger:
--------------------------
trigger AttcahmentTrigger on Attachment (before insert) {
    if(Trigger.isBefore) {
        if(Trigger.isInsert) {
            AttcahmentTriggerHandler.onBeforeInsert(Trigger.New);
        }
    }
}


Trigger Handler:
----------------------------------
/*
 * Author: Prakash
 * CreatedDate: Feb 14, 20202
*/
public with sharing class AttcahmentTriggerHandler {
    public static void onBeforeInsert(List<Attachment> attachments) {
        
        List<Id> accountIds = new List<Id>();
        
        //Loop to iterate over the list of attachments        
        for(Attachment att : attachments) {
            if(att.ParentId != null) {
                accountIds.add(att.ParentId); // Preparing the account Ids
            }
        }
        
        if(!accountIds.isEmpty()) {
            // Preparing the map that holds the account Name as a value and Id as a key
            Map<Id, Account> accountMap = new Map<Id,Account>([SELECT ID, Name FROM Account WHERE Id = :accountIds]);
            
            // Loop to iterate over the list of Attachments
            for(Attachment att : attachments) {
                att.Name = accountMap.get(att.ParentId).Name;
            }
            
        }
        
    }
}
But there is another catch to it - by object A I mean object SERVICE APPOINTMENT, which does not support the Attachment object.

Help me please!
 
Hello,

I need to update a file title after it's upload.

That is an easy trigger, but here is the catch:

On object A is a text field. Each record of object A has some value in the text field. After I upload the file to the object A's record, I need to take the value in the text field of the record and set is as a title of the newly uploaded file.

I don't know how to query for that. File is ContentDocument, but there has to be a different way. Thanks alot. Jan
trigger TestTrigger on TestObj2__c (after insert) {
    Set<Id> ids = new Set<Id>();
    
    for(TestObj2__c a: Trigger.New) {
        ids.add(a.Account__c);
    }
    Account[] acs = [select Id from Account where Id in :ids];
    for(Account b :acs) {
        b.TestField__c = 'BECOMING A PROGRAMMER';
    }

}

Expectation: After I create a record of object TestObj2__c, a field of it's master object Account will get populated with "BECOMING A PROGRAMMER".

It does not do that though. Even wrote a test method for this, says the same:
 
@isTest
public class TestTestTrigger {
    @isTest static void td(){
        Account a = new Account(Name = 'fun');
        insert a;
        TestObj2__c b = new TestObj2__c();
        b.Name = 'Fun';
        b.Account__c = a.Id;
        insert b;
        
        Account isPopulated = [select TestField__c from Account where id = :b.Account__c];
        System.assertEquals('BECOMING A PROGRAMMER', isPopulated.TestField__c);
    
    }

}
Error Message	System.AssertException: Assertion Failed: Expected: BECOMING A PROGRAMMER, Actual: test
Stack Trace	Class.TestTestTrigger.td: line 12, column 1


Can anyone tell me what's missing in the puzzle?
 
Hey guys, I've got a very simple trigger:
 
trigger TF on Account (before update, before insert) {
    for (Account a: trigger.New) {
        a.TestField__c = 'test';
    }

}

I wrote a test class for it:
 
@isTest
public class TFTest {
    @isTest static void testName() {
       Account cat = new Account();
        cat.Name = 'cat';
        insert cat;
        System.assertEquals('test', cat.TestField__c);
       }

}
When I run the test, I get an error:
 
Error Message	System.AssertException: Assertion Failed: Expected: test, Actual: null
Stack Trace	Class.TFTest.testName: line 7, column 1

I have two questions:
1) What am I doing wrong?
2) How come my trigger does not need to be tested and works already? I added an Account record already and the field gets populated.

Have a nice day


 

This validation rule is supposed to prevent users from adding Quote Line Items if parent Quote has Status of API name 1. Waiting for validation.

It looks like this:

ISPICKVAL(Quote.Status, "1. Waiting for validation")

It does not fire. API name is alright. It works on other Statuses (0, 2 ,3 ,4 , 5), but with this Status number 1 it does not work.
 

What's the problem?

Hey, I have object A.

A has lookup to Account. All records on A have the same owner.

I need to change the owner of A records to the owner of the Account in lookup.

Example: John owns 10 records of object A. All of those records have lookup to an Account called McDonalds. Owner of the McDonalds record is user McDonald. I need to change ownership of John's records to the user in related Account (that might not only be McDonald, but others...).

I'm experiencing difficulties with my code:

List <TestObj__c> list1 = New List<TestObj__c>();
list1 = [SELECT id, NAME From TestObj__c WHERE (OwnerId = '0052o000009Stq8')];
for(TestObj__c a :list1) {
   
    /**
   /* variable a;
   /* variable a = [Select AccountOwner from Account where (TestObj__c.lookupToAccount equals AccountId];
    /* a.Owner = a;
    /*
                                                          
}

The for look works, but I don't know what to put inside, because it gives me errors, so I just deleted it and put something vague inside and commented it. How do I do this?