• Raghavendra M 13
  • NEWBIE
  • 55 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 21
    Replies
User-added image
Apex Controller:
public with sharing class UploadimagesController {
@AuraEnabled
    public static void getfilenamesupdated(list<string> contdocumntidlst)
    {
            list<ContentDocument> condoclst = new list<ContentDocument>();
            condoclst = [select id,Title,FileType from ContentDocument where id in: contdocumntidlst];
            for(ContentDocument cd : condoclst)
    {
               cd.Title = cd.Title+'_'+'reqirdextension';   
    }
  update condoclst;
    }
}
Component:
<aura:component controller="UploadimagesController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
 <aura:attribute name="contentdocumentlist" type="List"/>
    <aura:attribute name="recordId" type="Id" description="Record to which the files should be attached" />
            <lightning:fileUpload label="Add attachment"           
                                  multiple="true"          
                                  accept=".jpg, .png"          
                                  recordId="{!v.recordId}"            
                                  onuploadfinished="{!c.handleUploadFinished}"/>
 
</aura:component>
Controller:
({
        handleUploadFinished: function (cmp, event) {
    // Get the list of uploaded files
    var uploadedFiles = event.getParam("files");
    var idslst = component.get("v.contentdocumentlist");
    for (var i= 0; i< uploadedFiles.length;i++)
   {
        
       idslst.push(JSON.stringify(uploadedFiles[i].documentId));
   }

   componenet.set("v.contentdocumentlist",idslst);
 
    var action = component.get("c.getfilenamesupdated");
            action.setParams({
                contdocumntidlst : component.get("v.selectedsobjct"),
               
            });
            action.setCallback(this, function(actionResult) 
            {
                var state = actionResult.getState();
                if (state === "SUCCESS") 
                {
                     // show success message – with no of files uploaded
    var toastEvent = $A.get("e.force:showToast");
    toastEvent.setParams({
    "title": "Success!",
    "type" : "success",
    "message": uploadedFiles.length+ "files has been updated successfully!"
    });
    toastEvent.fire();
    
    $A.get("e.force:refreshView").fire();
    
    // Close the action panel
    var dismissActionPanel = $A.get("e.force:closeQuickAction");
    dismissActionPanel.fire();   
                }
            });
            $A.enqueueAction(actionResult);       
   
   
    },

})
Time field data type is Time
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

try{
    var accToUpdate = new sforce.SObject("Account");

    accToUpdate.Id = "{!Account.Id}";
    var today = new Date();

   function fixTime(time){
       if(time < 10) {time = "0" + time};
         return time;
    }

    function fixDate(date){
          var Month = fixTime(date.getMonth() + 1);
          var Day = fixTime(date.getDate());
          var UTC = date.toUTCString();
          var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
          var Minutes = fixTime(date.getMinutes());
          var Seconds = fixTime(date.getSeconds());
          return date.getHours() + ":"+date.getMinutes();
       }
    accToUpdate.Current_Time__c= fixDate(today);
    
    var result = 
        sforce.connection.update([accToUpdate]);

    if(result[0].success == "true"){
        location.reload();
    }
    else{
        alert("An Error has Occurred. Error: " + 
            result[0].errors.message
        );
    }
}
catch(e){
    alert(
        "An Error has Occurred. Error: " + 
        e
    );
}
When clicking on a lightning button displaying a visual force pdf page , how can i insert that pdf attachment in notes and attachments