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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 21
    Replies
Am Selecting Contract Begining Date in a Visual Force Page
User-added image
When I select Contract Begining Date populating Contract Ending Date
User-added image
Now i would like show Contract Ending Date automatically empty when Contract Begining Date is empty
User-added image
VF Page Code:
<apex:actionRegion >
<apex:inputField value="{!cont.Contract_Beginning_Date__c}" taborderhint="2" Style="margin-left:0.0%;" required="true" >
<apex:actionSupport event="onchange" action="{!AccAddress}" rerender="rty"/>
</apex:inputField>
</apex:actionRegion >

Apex Code:

Public void AccAddress()
    {   
        if(cont.Contract_Beginning_Date__c!= null)
        {
            cont.Contract_Ending_Date__c = cont.Contract_Beginning_Date__c.addMonths(6);
        }
        if(cont.Contract_Beginning_Date__c == null)
        {
             cont.Contract_Ending_Date__c = null;             
        }
    }    
public class IntegrationClss
{
    @future(callout=true)
    public Static void MealTimeCall()
    {
        Http h = new Http();
                    
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint  
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setHeader('Connection','keep-alive');
        req.setTimeOut(120000); 
        req.setHeader('Content-Type', 'application/xml;charset=UTF-8');
        req.setEndpoint('https://lightningnumberofopportunities-dev-ed.my.salesforce.com/MealTime.php');
        HttpResponse res = h.send(req);
        system.debug(res.getbody());
        ProfitCenterCall();
    }
    public Static void ProfitCenterCall()
    {
        Http h = new Http();
                    
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint  
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setHeader('Connection','keep-alive');
        req.setTimeOut(120000); 
        req.setHeader('Content-Type', 'application/xml;charset=UTF-8');
        req.setEndpoint('https://lightningnumberofopportunities-dev-ed.my.salesforce.com/Profit%20Center.php');
        HttpResponse res = h.send(req);
        system.debug(res.getbody());
        StoreCall();
    }
    public Static void StoreCall()
    {
        Http h = new Http();
                    
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint  
        HttpRequest req = new HttpRequest();
        req.setMethod('GET');
        req.setHeader('Connection','keep-alive');
        req.setTimeOut(120000); 
        req.setHeader('Content-Type', 'application/xml;charset=UTF-8');
        req.setEndpoint('https://lightningnumberofopportunities-dev-ed.my.salesforce.com/Store.php');
        HttpResponse res = h.send(req);
        system.debug(res.getbody());
        SalesDepartmentCall();
    }
}
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);       
   
   
    },

})
{!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.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
      }
   accToUpdate.Current_Date__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
   );
}
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
This page has an error. You might just need to refresh it. First, would you give us some details? (We're reporting this as error ID: -352469438)
When i change a pick list value this error is coming
Apex Class:
public with sharing class CreateWorkOrderRecord 
{
    /**
   * Create a new Work Order Record
   *
   * @param WorkOrder Work Order Work Order record to be inserted
   * 
   */
    @AuraEnabled
    public static String createRecord(WorkOrder workorder)
    {
        try
        {
            System.debug('CreateWorkOrderRecord::createRecord::workorder'+workorder);
            
            if(workorder!= null)
                insert workorder;
        } 
        catch (Exception ex)
        {
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,string.valueof(ex)));
             return null; 
        }
        return null; 
    } 
     @AuraEnabled
     public static List <String> getselectOptions(sObject objObject, string fld) 
     {
          List <String> allOpts = new list <String>();
          Schema.sObjectType objType = objObject.getSObjectType();  // Get the object type of the SObject.
          Schema.DescribeSObjectResult objDescribe = objType.getDescribe();  // Describe the SObject using its object type.
          Map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();  // Get a map of fields for the SObject
          List <Schema.PicklistEntry> values = fieldMap.get(fld).getDescribe().getPickListValues();  // Get the list of picklist values for this field.
        
          for(Schema.PicklistEntry a: values) 
           allOpts.add(a.getValue());  // Add these values to the selectoption list.
        
          allOpts.sort();
          return allOpts;
     }
           
}

Component:
<aura:component controller="CreateWorkOrderRecord" 
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" 
                access="global" >
    
    <!-- Include Static Resource-->
    <ltng:require styles="/resource/bootstrap1/css/bootstrap.min.css" 
                  scripts="/resource/bootstrap1/js/jquery.js,/resource/bootstrap/js/bootstrap.min.js"/>
    
    <!-- Define Attribute-->
    <aura:attribute name="selectedLookUpRecord" type="sObject" default="{}"/>
    <aura:attribute name="selectedLookUpRecord1" type="sObject" default="{}"/>
    <aura:attribute name="selectedLookUpRecord2" type="sObject" default="{}"/>
    <aura:attribute name="number" type="integer"/>
    <aura:attribute name="myText" type="String"/>

    <aura:attribute name="workorder" type="WorkOrder" default="{'sobjectType': 'WorkOrder',
                                                                  'Account__c': '',
                                                                  'Contact__c': '',
                                                                  'Opportunity__c': '', 
                                                                  'Priority': '',
                                                                  'StartDate': '',
                                                                  'Status': '',
                                                                     'Number_of_Weeks__c': '',
                                                                  'Visit_Frequency__c': '',
                                                               }"/><br/>
        <div>
            <table>
                <tr>
                    <td>
                        <h2 style="font-weight:bold;font-size:12px;margin-left:5%">New Work Order Edit</h2>
                        <h1 style="font-weight:bold;font-size:18px;margin-left:5%">New Work Order</h1>
                    </td>
                </tr>
            </table>
    </div><br/>
    <center>
        <div class="col-md-4 text-center">
              <lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
        </div>
    </center><br/>
    <div class="slds-box" style="background:rgb(0, 161, 223);font-weight:bold;font-size:15pt;">
        <p>WorkOrder Information</p>
    </div>
    
    <div class="slds-grid slds-gutters">
        <div class="slds-col" style="width:500px;">
            <table class="slds-table slds-table--bordered slds-table--cell-buffer"> 
              <thead>
                 <tr>
                 <td width="45%">
                  <table>
                      <tr>
                        <td><c:customLookup objectAPIName="account" IconName="standard:account" label="Account" selectedRecord="{!v.selectedLookUpRecord}"/></td>
                    </tr>
                      <tr>
                        <td><c:customLookup objectAPIName="contact" IconName="standard:contact" label="Contact" selectedRecord="{!v.selectedLookUpRecord1}"/></td>
                    </tr>
                      <tr>
                        <td><c:customLookup objectAPIName="opportunity" IconName="standard:opportunity" label="Opportunity" selectedRecord="{!v.selectedLookUpRecord2}"/></td>
                    </tr>
                      
                        <div class="form-group">
                            <tr>
                            <td>
                        <p class="title">Priority</p>
                        <ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}"  value="{!v.workorder.Priority}">
                            <ui:inputSelectOption text="Low"/>
                            <ui:inputSelectOption text="Medium"/>
                            <ui:inputSelectOption text="High"/>
                            <ui:inputSelectOption text="Critical"/>
                        </ui:inputSelect>
                     </td>
                     </tr>
                    </div>      
                     
                    </table>
                    </td>
                    <td width="10%"></td>
                    <td width="45%">
                        <table>
                        <tr>
                            <td>
                        <label>StartDate</label>
                        <ui:inputDate displayDatePicker="true" value="{!v.workorder.StartDate}"/>
                               </td>
                         </tr>
                    <div class="form-group">
                        <tr>
                            <td>
                        <p class="title">Status</p>
                        <ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}"  value="{!v.workorder.Status}">
                            <ui:inputSelectOption text="New"/>
                            <ui:inputSelectOption text="In Progress"/>
                            <ui:inputSelectOption text="On Hold"/>
                            <ui:inputSelectOption text="Completed"/>
                            <ui:inputSelectOption text="Closed"/>
                            <ui:inputSelectOption text="Cannot Complete"/>
                            <ui:inputSelectOption text="Canceled"/>
                        </ui:inputSelect>
                        </td>
                      </tr>
                     </div>
                      <tr>
                        <td> 
                            <p class="title">Number of Visits</p>
                        <ui:inputNumber value="{!v.workorder.Number_of_Weeks__c}"/>
                        </td>
                     </tr>
                     <div class="form-group">
                        <tr>
                            <td>
                        <p class="title">Visit Frequency</p>
                        <ui:inputSelect aura:id="InputSelectSingle" change="{!c.onSingleSelectChange}"  value="{!v.workorder.Visit_Frequency__c}">
                            <ui:inputSelectOption text="None"/>
                            <ui:inputSelectOption text="Daily"/>
                            <ui:inputSelectOption text="Weekly"/>
                            <ui:inputSelectOption text="Monthly"/>
                            <ui:inputSelectOption text="Custom Schedule"/>
                        </ui:inputSelect>
                        </td>
                      </tr>
                     </div>
 
                </table>
                </td>
               
                  </tr>
                </thead>
            </table>
            <br/>
            <center>
                    <div class="col-md-4 text-center">
                        <lightning:button variant="brand" label="Save" onclick="{!c.create}"/>
                    </div>
                </center> 
            <br/>
        </div>
                    
      </div>
</aura:component>
Controller:
({
    create : function(component, event, helper) {
        console.log('Create record');
        
        //getting the workorder information
        var workorder = component.get("v.workorder");
        workorder.Account__c = null;
        workorder.Contact__c = null;
        workorder.Opportunity__c = null;
        
        /***************Validation
        if($A.util.isEmpty(workorder.Opportunity__c) || $A.util.isUndefined(workorder.Opportunity__c)){
            alert('Account Name is Required');
            return;           
        }*************************************************/
        if(component.get("v.selectedLookUpRecord").Id != undefined){
            workorder.Account__c = component.get("v.selectedLookUpRecord").Id;
        }
        if(component.get("v.selectedLookUpRecord1").Id != undefined){
            workorder.Contact__c = component.get("v.selectedLookUpRecord1").Id;
        }
        if(component.get("v.selectedLookUpRecord2").Id != undefined){
            workorder.Opportunity__c = component.get("v.selectedLookUpRecord2").Id;
        }
        
        //Calling the Apex Function
        var action = component.get("c.createRecord");
        
        //Setting the Apex Parameter
        action.setParams({
            workorder : workorder
        });
        
        //Setting the Callback
        action.setCallback(this,function(a){
            //get the response state
            var state = a.getState();
            
            //check if result is successfull
            if(state == "SUCCESS"){
                //Reset Form
                var newWorkorder = {'sobjectType': 'WorkOrder',
                                    'Account__c': '',
                                    'Contact__c': '',
                                    'Opportunity__c': '',
                                    'Priority': '',
                                    'StartDate': '',
                                    'Status': '',
                                    'Number_of_Weeks__c': '',
                                    'Visit_Frequency__c': '',
                                   };
                //resetting the Values in the form
                component.set("v.workorder",newWorkorder);
                alert('Record is Created Successfully');
            } else if(state == "ERROR"){
                alert('Error in calling server side action');
            }
        });
        
        //adds the server-side action to the queue        
        $A.enqueueAction(action);
        
    },
    
    onSingleSelectChange: function(cmp) {
         var selectCmp = cmp.find("InputSelectSingle");
         var resultCmp = cmp.find("singleResult");
         resultCmp.set("v.value", selectCmp.get("v.value"));
     },
     onChange: function(cmp) {
         var dynamicCmp = cmp.find("InputSelectDynamic");
         var resultCmp = cmp.find("dynamicResult");
         resultCmp.set("v.value", dynamicCmp.get("v.value"));
     }
})

Hi
Month field :
Data Type: Formula  
CASE(MONTH(CloseDate), 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")

Apex Class:
public class NoofOpportunitiesbymonth{
    @auraenabled
    public static List<MonthWrapper> oppMonth(){
        List<MonthWrapper> wrapper = new List<MonthWrapper>() ; 
        AggregateResult[] Result = [SELECT Count(Id) Total ,
                                    Month__c Months FROM Opportunity GROUP BY Month__c limit 10];
        for (AggregateResult ar : Result) {
            wrapper.add(new MonthWrapper((String)ar.get('Months') ,(Integer)ar.get('Total')));
        }
        
        return wrapper ;
        
    }
    
    public class MonthWrapper{
        @auraenabled
        public String month{get;set;}
        @auraenabled
        public Integer count {get;set;}
        public MonthWrapper(String month, Integer count){
            this.month= month;
            this.count = count; 
            
        }
        
    }
    
}
Component:
<aura:component controller="NoofOpportunitiesbymonth" implements="force:appHostable" >
    
    <aura:attribute name="opportunities" type="List[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.myAction}"/>
    
    <table border="1" class="table">
        <tr>
            <th>Month&nbsp;&nbsp;</th> 
            <th>Number of Opportunities&nbsp;</th>
        </tr><br/>
        <aura:iteration items="{!v.opportunities}" var="cust">
            <tr> 
                <td>{!cust.month}</td>
                <td>{!cust.count}</td>       
            </tr>
        </aura:iteration>
    </table>
    
</aura:component>
Controller:
({
    myAction : function(component, event, helper) {
        var action =component.get("c.oppMonth");
        console.log('The action value is: '+action);
         action.setCallback(this, function(a){ 
             
            component.set("v.opportunities", a.getReturnValue());
            console.log('The opps are :'+JSON.stringify(a.getReturnValue()));
          
        });
        $A.enqueueAction(action);
    }
})

Thanks 
 
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