• Rudu
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies
Hi Guys,
I'm trying to build a lightning component which calculates real time.
I want Calculate TimeSpan__c(Number data type) field on Account object on the basis of Account (Execute_datetime__c) field and picklist value of metal(Metal__c)
Formula field for the same.
if(
AND (
$CustomMetadata.Metal_Setting__mdt.1ML.Metal__c = TEXT(Metal__c),
($CustomMetadata.Metal_Setting__mdt.1ML.SLA_Length__c - Floor((Now() - Execute_datetime__c) * 24 * 60) > -700)
),
$CustomMetadata.Metal_Setting__mdt.1ML.SLA_Length__c - Floor((Now() - Execute_datetime__c) * 24 * 60),
-700
)

Custom metadata type Metal
Metal      Legnth
Platinium 20
Silver    10

But due to some formula field limitation i want another solution to calculate TimeSpan__c field.
I can do the same thing using Apex trigger but issue is update field on Insert and update operation(Trigger event).
Its not reflect real time in this field.
Can you please give me the any suggestion or any lightning component functionality example to achive this.
Note:(Fields calcates real time data like counter) 
Any help would be appreciated!! 

Thanks
Ridu
  • October 29, 2020
  • Like
  • 0
Hi team,
I want to create a Vf page for below requirment
I am crating a button on Account Object When Click on the button then open the Vf page of the Related contact with Account.
I am Facing problem In pagination ,sorting Name column and open each contact.
Reguirment:-
ABC Firm wants to view all the contacts against an account in a custom UI where
10 records are displayed at a time and user has ability to paginate over all
records. User should have ability to sort records in asc/desc order on Name as
needed.
Requirement Details
 Create a custom button on Account andu.
 Connect developed VF Page with the Account custom button
 VF Page should have capability of pagination
 VF Page should have ability of sorting Name column
 While sorting a loading image should be displayed for user to wait till
operation completes.
 VF Page should display – Name, Birthdate, Lead Source, Email, Phone
 You are free to decide on Pages Look and Feel
 Adhere to salesforce best practices.
 Create test class to ensure developed code can be deployed; adhere to
best practices of testing framework.
<apex:page standardController="Account" sidebar="false" >
    <apex:form >

        <apex:pageBlock title="Contacts List" id="contacts_list">
    
            
            <apex:pageBlockTable value="{! Account.contacts }" var="ct">
                
            
                
            <apex:column value="{!ct.Name}"/>
                <apex:column value="{!ct.Birthdate}"/>
                <apex:column value="{!ct.Phone}"/>
                <apex:column value="{!ct.Email}"/>
                 <apex:column value="{!ct.LeadSource}"/>
            </apex:pageBlockTable>
          

            
           
        </apex:pageBlock>

    </apex:form>
</apex:page>

 
  • August 23, 2017
  • Like
  • 0
Controller Class:-
public class newOpportunityController {

  
   Account account;
   Contact contact;
   
   public Account getAccount() {
      if(account == null) account = new Account();
      return account;
   }

   public Contact getContact() {
      if(contact == null) contact = new Contact();
      return contact;
   }

 
   public PageReference step1() {
      return Page.opptyStep1;
   }

   public PageReference step2() {
      return Page.opptyStep2;
   }

 
    public PageReference cancel() {
			PageReference opportunityPage = new ApexPages.StandardController(Contact).view();
			opportunityPage.setRedirect(true);
			return opportunityPage; 
    }

  
   public PageReference save() {

   
      account.phone = contact.phone;
      insert account;

      // Create the contact. Before inserting, use the id field
      // that's created once the account is inserted to create
      // the relationship between the contact and the account.
      contact.accountId = account.id;
      insert contact;

     

      PageReference opptyPage = new ApexPages.StandardController(Contact).view();
      opptyPage.setRedirect(true);

      return opptyPage;
   }
    public blob file { get; set; }
      public PageReference upload()
    {
      
        ContentVersion v = new ContentVersion();
        v.versionData =file;
        v.title = 'testing upload';
        v.pathOnClient ='/somepath.jpg / somepath.png';
        insert v;
        return new PageReference('/' + v.id);
    }

}




opptyStep1
<apex:page controller="newOpportunityController" tabStyle="Account">
  <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
      return false;
  }  
  </script>
  <apex:sectionHeader title="Edit Account" subtitle="New Account"/>
    <apex:form >
      <apex:pageBlock title="Account Information" mode="edit">

        <!-- The pageBlockButtons tag defines the buttons that appear at the top
             and bottom of the pageBlock. Like a facet, it can appear anywhere in
             a pageBlock, but always defines the button areas.-->
        <!-- The Next button contained in this pageBlockButtons area
             calls the step2 controller method, which returns a pageReference to
             the next step of the wizard. -->
        <apex:pageBlockButtons >
          <apex:commandButton action="{!step2}" value="Next"/>
          <apex:commandButton action="{!cancel}" value="Cancel" 
                              onclick="return confirmCancel()" immediate="true"/>
        </apex:pageBlockButtons>
          
      <apex:pageBlockSection title="Account Inpformation">

        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->
         
        <apex:inputField id="AccountName" value="{!account.Name}" required="true"/>
        <apex:inputField id="AccountType" value="{!account.Type}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Address Information">
          <apex:inputField value="{!Account.BillingStreet}"/>
          <apex:inputField value="{!Account.BillingCity}"/>
            <apex:inputField value="{!Account.ShippingStreet}"  required="true"/>  
            <apex:inputField value="{!Account.ShippingCity	}" required="true"/>
           <apex:inputField value="{!Account.ShippingState}" required="true"/>
           <apex:inputField value="{!Account.ShippingPostalCode}" required="true"/>
           <apex:inputField value="{!Account.ShippingCountry}" required="true"/>
           </apex:pageBlockSection>
          <apex:pageBlockSection title="Additional Information">
          <apex:inputField value="{!Account.Website}"/>
          <apex:inputField value="{!Account.Industry}"/>
          <apex:inputField value="{!Account.Phone}"/>
            <apex:inputField value="{!Account.Fax}"/>
            <apex:inputField value="{!Account.Description}"/>
        
     </apex:pageBlockSection>
     
          
    </apex:pageBlock>
  </apex:form>
</apex:page>


opptyStep2:-
<apex:page controller="newOpportunityController" tabStyle="Contact">
  <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
  
     return false;
  }  
  </script>
  <apex:sectionHeader title="New Contact" subtitle="Step 2 of 3"/>
  <apex:form >
    <apex:pageBlock title="Contact Information" mode="edit">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!step1}" value="Previous"/>
        <apex:commandButton action="{!Save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel" 
                            onclick="return confirmCancel()" immediate="true"/>
      </apex:pageBlockButtons>
     <apex:pageblocksection title="Contact Information">
     <apex:inputField value="{!Contact.FirstName}"/>
     <apex:inputField value="{!Contact.LastName}"/>
          <apex:inputField value="{!Contact.Department}"/>
          <apex:inputField value="{!Contact.Birthdate}"/>
          <apex:inputField value="{!Contact.Phone}"/>
          <apex:inputField value="{!Contact.MobilePhone}"/>
          <apex:inputField value="{!Contact.Email}"/>
         
            <apex:inputFile value="{!file}" />
 <apex:commandbutton action="{!upload}" value="upload" />


      </apex:pageblocksection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Requirment:-Create a custom VF Tab ‘Quick Create’. • Create a VF Page wizard. This wizard will have two pages. • First Page will let user enter Account details. Fields to be present on Account Page Wizard : Account Name(Mandatory), Account Type, Billing Address, Shipping Address(Mandatory), Website, Industry, Phone, Fax, Description • Second Page will let user enter Contact Details: Contact Name, Department, Birthdate, Phone, Mobile, Email. • Additionally Contact page will provide ability to upload Contact photo. • User should have ability to move between the first and second page of Wizard and values should remain intact. • Save button will be available only on the second page. On click of save first create Account record then create contact record and link it with Account. • When user will click on Next button of first page. Validation should be in place to ensure all mandatory fields are populated. Then only allow user to move to Contact Page for filling information.
  • August 18, 2017
  • Like
  • 0
Create a VF Page wizard. This wizard will have two pages.First Page will let user enter Account details.Second Page will let user enter Contact Details: Contact Name, Department, Birthdate, Phone, Mobile, Email. Additionally Contact page will provide ability to upload Contact photo.Save button will be available only on the second page. On click of save first create Account record then create contact record and link it with Account. this is the my whole requirment....i complete all code but i am facing issue in  Contact page will provide ability to upload Contact photo
public class newOpportunityController {

   // These four member variables maintain the state of the wizard.
   // When users enter data into the wizard, their input is stored
   // in these variables. 
   Account account;
   Contact contact;
  
   // The next four methods return one of each of the four member
   // variables. If this is the first time the method is called,
   // it creates an empty record for the variable.
   public Account getAccount() {
      if(account == null) account = new Account();
      return account;
   }

   public Contact getContact() {
      if(contact == null) contact = new Contact();
      return contact;
   }

  

   // The next three methods control navigation through
   // the wizard. Each returns a PageReference for one of the three pages
   // in the wizard. Note that the redirect attribute does not need to
   // be set on the PageReference because the URL does not need to change
   // when users move from page to page.
   public PageReference step1() {
      return Page.opptyStep1;
   }

   public PageReference step2() {
      return Page.opptyStep2;
   }

 
    public PageReference cancel() {
			PageReference opportunityPage = new ApexPages.StandardController(Contact).view();
			opportunityPage.setRedirect(true);
			return opportunityPage; 
    }

   // This method performs the final save for all four objects, and
   // then navigates the user to the detail page for the new
   // opportunity.
   public PageReference save() {

      // Create the account. Before inserting, copy the contact's
      // phone number into the account phone number field.
      account.phone = contact.phone;
      insert account;

      // Create the contact. Before inserting, use the id field
      // that's created once the account is inserted to create
      // the relationship between the contact and the account.
      contact.accountId = account.id;
      insert contact;


      PageReference opptyPage = new ApexPages.StandardController(Contact).view();
      opptyPage.setRedirect(true);

      return opptyPage;
   }
    public blob file { get; set; }
      public PageReference upload()
    {
      
        ContentVersion v = new ContentVersion();
        v.versionData =file;
        v.title = 'testing upload';
        v.pathOnClient ='/somepath.jpg / somepath.png';
        insert v;
        return new PageReference('/' + v.id);
    }

}





Vf pages:-opptyStep1

<apex:page controller="newOpportunityController" tabStyle="Account">
  <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
      return false;
  }  
  </script>
  <apex:sectionHeader title="Edit Account" subtitle="New Account"/>
    <apex:form >
      <apex:pageBlock title="Account Information" mode="edit">

        <!-- The pageBlockButtons tag defines the buttons that appear at the top
             and bottom of the pageBlock. Like a facet, it can appear anywhere in
             a pageBlock, but always defines the button areas.-->
        <!-- The Next button contained in this pageBlockButtons area
             calls the step2 controller method, which returns a pageReference to
             the next step of the wizard. -->
        <apex:pageBlockButtons >
          <apex:commandButton action="{!step2}" value="Next"/>
          <apex:commandButton action="{!cancel}" value="Cancel" 
                              onclick="return confirmCancel()" immediate="true"/>
        </apex:pageBlockButtons>
          
      <apex:pageBlockSection title="Account Inpformation">

        <!-- Within a pageBlockSection, inputFields always display with their
             corresponding output label. -->
         
        <apex:inputField id="AccountName" value="{!account.Name}" required="true"/>
        <apex:inputField id="AccountType" value="{!account.Type}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection title="Address Information">
          <apex:inputField value="{!Account.BillingStreet}"/>
          <apex:inputField value="{!Account.BillingCity}"/>
            <apex:inputField value="{!Account.ShippingStreet}"  required="true"/>  
            <apex:inputField value="{!Account.ShippingCity	}" required="true"/>
           <apex:inputField value="{!Account.ShippingState}" required="true"/>
           <apex:inputField value="{!Account.ShippingPostalCode}" required="true"/>
           <apex:inputField value="{!Account.ShippingCountry}" required="true"/>
           </apex:pageBlockSection>
          <apex:pageBlockSection title="Additional Information">
          <apex:inputField value="{!Account.Website}"/>
          <apex:inputField value="{!Account.Industry}"/>
          <apex:inputField value="{!Account.Phone}"/>
            <apex:inputField value="{!Account.Fax}"/>
            <apex:inputField value="{!Account.Description}"/>
        
     </apex:pageBlockSection>
     
          
    </apex:pageBlock>
  </apex:form>
</apex:page>



Second Page:-opptyStep2

<apex:page controller="newOpportunityController" tabStyle="Contact">
  <script>
  function confirmCancel() {
      var isCancel = confirm("Are you sure you wish to cancel?");
      if (isCancel) return true;
  
     return false;
  }  
  </script>
  <apex:sectionHeader title="New Contact" subtitle="Step 2 of 3"/>
  <apex:form >
    <apex:pageBlock title="Contact Information" mode="edit">
      <apex:pageBlockButtons >
        <apex:commandButton action="{!step1}" value="Previous"/>
        <apex:commandButton action="{!Save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel" 
                            onclick="return confirmCancel()" immediate="true"/>
      </apex:pageBlockButtons>
     <apex:pageblocksection title="Contact Information">
     <apex:inputField value="{!Contact.FirstName}"/>
     <apex:inputField value="{!Contact.LastName}"/>
          <apex:inputField value="{!Contact.Department}"/>
          <apex:inputField value="{!Contact.Birthdate}"/>
          <apex:inputField value="{!Contact.Phone}"/>
          <apex:inputField value="{!Contact.MobilePhone}"/>
          <apex:inputField value="{!Contact.Email}"/>
         
            <apex:inputFile value="{!file}" />
 <apex:commandbutton action="{!upload}" value="upload" />


      </apex:pageblocksection>
    </apex:pageBlock>
  </apex:form>
</apex:page>
  • August 17, 2017
  • Like
  • 0
Hi Team,
I want To write This Trigger test class any one help me to how to write....
Approach:Write Custom Code in salesforce to stop deleting any event forcefully Through this event will not get deleted in salesforce even in outlook

- If someone need to really delete the event they need to click on extra checkbox and save then delete in salesforce
 pls tell me is it correct trigger to this Apporch

Note: Pls Test Class Should Be Bulkify........
 
trigger avoidDeletionEvent on Event (before delete) {
for(event e:trigger.old)
{
    if(e.Override_Deletion__c==false)
        e.addError('You do not have permission to delete this event');
   }
}


 
  • August 08, 2017
  • Like
  • 0
Hi Guys,
I'm trying to build a lightning component which calculates real time.
I want Calculate TimeSpan__c(Number data type) field on Account object on the basis of Account (Execute_datetime__c) field and picklist value of metal(Metal__c)
Formula field for the same.
if(
AND (
$CustomMetadata.Metal_Setting__mdt.1ML.Metal__c = TEXT(Metal__c),
($CustomMetadata.Metal_Setting__mdt.1ML.SLA_Length__c - Floor((Now() - Execute_datetime__c) * 24 * 60) > -700)
),
$CustomMetadata.Metal_Setting__mdt.1ML.SLA_Length__c - Floor((Now() - Execute_datetime__c) * 24 * 60),
-700
)

Custom metadata type Metal
Metal      Legnth
Platinium 20
Silver    10

But due to some formula field limitation i want another solution to calculate TimeSpan__c field.
I can do the same thing using Apex trigger but issue is update field on Insert and update operation(Trigger event).
Its not reflect real time in this field.
Can you please give me the any suggestion or any lightning component functionality example to achive this.
Note:(Fields calcates real time data like counter) 
Any help would be appreciated!! 

Thanks
Ridu
  • October 29, 2020
  • Like
  • 0