• Krishnaveni A 2
  • 10 Points
  • Member since 2018

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 5
Hi All,

I have a requirement where an email with link will be sent to the users. The link will redirect to the web to lead form which will be designed by us. Once the users fills the details in the form and click on the save button, the same should be created as a lead in salesforce(this will be done automatically as it is a web to lead process) and an e-book should be downloaded. The e-book will be available in the sharepoint. Do we need integration for this? If yes how? I can complete till generating lead from web to lead form but I am struck with the e-book download task. Please help as soon as possible :) Thanks in advance!
My requirement is to encrypt few files while uploading and restrict the view access to specific users for the same files. There will be a checkbox available based on which the files should be encrypted or not. If the checkbox is TRUE, encrypt the file while uploading and also restrict the view access to specific users for the same file. I know it is possible with configuration but here I need to achieve this via apex code. 
In order to restrict view access for users I tried the below code:

ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE Id ='0687F000006FlIjQAK'].ContentDocumentId;
cdl.LinkedEntityId = '0057F000002yWGe';
cdl.ShareType = 'V';
insert cdl;

When I tried this, it worked. Only if I give sharetype = 'V' only the files are visisble to the user. The user here is LinkedEntityId. 
I am not sure whether  this approach is correct.

In order to encypt a file I tried using CRYPTO class methods available in Apex. But I was not able to fetch the content of the file using this. How do fetch the file content and encrypt it? Also the view access should be restricted.

Please help me with both the requirements.
Thanks in Advance!
I am trying to prevent trigger from creating duplicate requests.
For example, if the case status is changed from something else to close, then create a new request. but, if the case status is not changed from something else to closed but it was already closed and edit button was clicked and without doing any changes, it was saved, in this case it should not create a new request.

I have trigger and handler class all set up for this but, i don't know why old values are being passed in both of my maps in handler class even though inside the trigger, it is fetching new and old values. still in my map inside handler class, it is passing old values where status is New.
I checked the log.

Below is what i have tried
public class MaintenanceRequestHelper {
    public static Boolean isFirstTime = true;

public static void updateWorkOrders(Map<Id,Case> newVal, Map<Id,Case> oldVal) {
    Map<Id,Case> maintenance_Req_List =new Map<Id,Case>([SELECT id,Origin,Status,Date_Due__c,priority, Case.vehicle__c,Equipment__c,Equipment__r.Maintenance_Cycle__c,
                                         Type,Subject,Date_Reported__c FROM Case Where Status in:newVal.KeySet()]);
  Map<Id,Case> maintenance_Req_Listt =new Map<Id,Case>([SELECT id,Origin,Status,Date_Due__c,priority, Case.vehicle__c,Equipment__c,Equipment__r.Maintenance_Cycle__c,
                                         Type,Subject,Date_Reported__c FROM Case Where id in:oldVal.KeySet()]);
        public static void closedMaintenanceRequestList(Map<Id, Case> newMap,  Map<Id, Case> oldMap)
            List<Case> new_Maintenance_Req_Lst = new List<Case>();
            for (Case c: newMap.Values()) {
                if(c.Type=='Repair'||c.Type=='Routine Maintenance'){
                     System.debug('routine if is true');
                 if (c.Status == 'Closed' && oldMap.get(c.Id).Status != 'Closed' ) {
                System.debug('if executed after being true');
                  Case new_req = new Case();
                  new_req.Subject='Maintenance request';
                  new_req.Type='Routine Maintenance';
         insert new_Maintenance_Req_Lst;
and trigger

trigger MaintenanceRequest on Case (before update,after update) {
            System.debug('Trigegr fired');
            MaintenanceRequestHelper.updateWorkOrders(Trigger.newMap, Trigger.oldMap);          
Here are the values from log.
For new values:
SSIGNMENT [5]|newVal|{"5002o00002Br9G9AAJ":{"Origin":"Phone","Status":"Closed","LastModifiedDate":"2019-08-05T12:29:24.000Z","IsDeleted":false,"Date_Due__c":"2019-08-09T00:00:00.000Z","Priority":"Medium","Equipment__c":"01t2o000007zDQfAAM","IsClosed":false,"SystemModstamp":"2019-08-05T12:29:24.000Z","BusinessHoursId":"01m2o000000U4OdAA

For old values:
IGNMENT [5]|oldVal|{"5002o00002Br9G9AAJ":{"Origin":"Phone","Status":"New","LastModifiedDate":"2019-08-05T12:29:24.000Z","IsDeleted":false,"Date_Due__c":"2019-08-09T00:00:00.000Z","Priority":"Medium","Equipment__c":"01t2o000007zDQfAAM","IsClosed":false,"SystemModstamp":"2019-08-05T12:29:24.000Z","BusinessHoursId":"01m2o000000U4OdAAK&q

But in my map inside handler class. both values are where status is New. 

Please help. I am totally lost here.
Hi Everyone,

Let me know the solution please: How to upload an image through Visualforce page and store in salesforce custom object and display in Custom object detail page. 

It's urgent.  
Note: When users fill all the data with an Image after a click on the save button then all those details and including inserted image should get save first and then display in that custom object detail page.  

Many thanks in advance. 
This is my trigger And the test class
When running the test class I get 100% coverage yet the test fails and I get the following error:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ARGUMENT_TYPE, The argument is null or invalid.: []


trigger NewFileAlert on ContentDocument (after insert) 
// Step 0: Create a master list to hold the emails we'll send
  List<Messaging.SingleEmailMessage> mails = 
  new List<Messaging.SingleEmailMessage>();
  for (ContentDocument newDoc : Trigger.new) 
      // Step 1: Create a new Email
      Messaging.SingleEmailMessage mail = 
      new Messaging.SingleEmailMessage();
      // Step 2: Set list of people who should get the email
      List<String> sendTo = new List<String>();
      sendTo.add(list of all addresses)
      // Step 3: Set who the email is sent from
      mail.setSenderDisplayName('Aidel Bruck');

      // Step 4. Set email contents - you can use variables!
      mail.setSubject('New Document Added');
      String body = 'Please note: A new document has been added/n  ';
      body += 'File name: '+ newdoc.title+'/n' ;
      body += 'Created By: '+ newdoc.createdbyid+ '/n';
      body += 'Created Date: '+ newdoc.CreatedDate+ '/n';
      body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+newdoc.id;
      // Step 5. Add your email to the master list
  // Step 6: Send all emails in the master list

public class TestNewFileAlert 

    public static testmethod void MyUnitTest()
    Account acct = new Account(Name='TEST_ACCT');
    insert acct;
    ContentVersion contentVersionobj = new ContentVersion();
    contentVersionobj.Title = 'Google.com';            
    insert contentVersionobj;