• Tintu_Babu
  • NEWBIE
  • 140 Points
  • Member since 2017

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 24
    Replies
Looking at SFDC's Trailhead "Get started with apex triggers", I read the following:

"You can call public utility methods from a trigger."

What is an utility method?

Thank you.
  • November 22, 2017
  • Like
  • 0
Hi,

I need to get all the Assignment rules RuleEntry from apex.
I found the AssignmentRules metadata but I don't understand how to use it.

Would anyone know how to retrieve this information?

Thank you.
Hi All,

I have created a apex class with @InvocableMethod to perfrom the action thorugh the process builder but the apex class is not showing in the process builder can you please suggest why. 
Kindly check the below image.

Thanks.User-added image
How do you rationalize the data using SOQL query?
This is an interview question asked by the interviewer ,
can anyone help out .
can suggest any links or books or clear answer .
Thanks in advance
Error on this Trigger:This Error
where i am wrong
Requirement Details:
- Account should have two fields of type text area Current Issues(Products), Past Issues(Products)
- Keep count of total issues/Cases at account level, whenever the count reaches 5, send an email to the Account owner to get in touch with the service team.
- When a case is created the total issue count should increase and the Product for which issue is raised should be shown in comma separated format in field Current Issues (Products).
- When a case is closed the product should be removed from current Issues(Products) and should be added to Past Issues(Products) in comma separated format.


Trigger UpdateCaseCount on Case(After Insert, After Update) {
    Set<id> AccIdUpd = new Set<Id>();
  Map<Id, Id> AccPrd = new Map<Id, Id>();
    set<id> ContactId = new set<id>();
 
  //Create a master list to hold the emails we'll send
  List<Messaging.SingleEmailMessage> mails =
  new List<Messaging.SingleEmailMessage>();
 
   
  for(Case cs:Trigger.New) {       
    if(Trigger.IsInsert || (cs.IsClosed && Trigger.OldMap.get(cs.Id).IsClosed != cs.IsClosed)) {
      AccIdUpd.add(cs.AccountId);
      AccPrd.put(cs.AccountId, cs.Product__c);
    }
 
    }     

  List<AggregateResult> ARListCurrIssue = [select AccountId, Product__c, Count(Id) CaseCount from Case where
                                             AccountId In:AccIdUpd and IsClosed != True group By AccountId, Product__c];
 
  // Logic to update curernt Issues
  List<Account> UpdAccList = new List<Account>();
  for(AggregateResult AR : ARListCurrIssue) {
  String CurrCount = AR.get('CaseCount') + ', ' +  AccPrd.get((ID)AR.get('Product__c'));
        UpdAccList.add(new Account(Id = (ID)AR.get('AccountId'), CurrentCount__c = CurrCount));
        Integer iCount = Integer.valueOf(AR.get('CaseCount'));
        If(iCount == 5) {
            //write logic to sendMail     
 
         Contact con = [Select firstname,lastname,email,id,name,MobilePhone from Contact where id in :ContactId];
      // 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(con.email);
      mail.setToAddresses(sendTo);
  
      // Step 3: Set who the email is sent from
      mail.setReplyTo('lokeshpatil830@gmail.com');
      mail.setSenderDisplayName('lokesh patil');
  
      // (Optional) Set list of people who should be CC'ed
      List<String> ccTo = new List<String>();
      ccTo.add('puja.patil@aress.com');
      mail.setCcAddresses(ccTo);
 
      // Step 4. Set email contents - you can use variables
      mail.setSubject('Get in touch with the service team');
      String body = 'Dear ' + con.FirstName;
    
      mail.setHtmlBody(body);
  
      // Step 5. Add your email to the master list
      mails.add(mail);
        Messaging.sendEmail(mails);             
   
  }


    if(UpdAccList.size()>0){
    update UpdAccList;

}
  // Logic to update Past Issues
      ARListCurrIssue = [select AccountId, Count(Id) CaseCount  from Case where AccountId In:
                                             AccIdUpd and IsClosed = True group By AccountId];
 
  UpdAccList = new List<Account>();
  for(AggregateResult AR : ARListCurrIssue) {
    String PastCount = AR.get('CaseCount') + ', ' +  AccPrd.get((ID)AR.get('AccountId'));
    UpdAccList.add(new Account(Id = (ID)AR.get('AccountId'), PastCount__c = PastCount));
   
  }
   
  if(UpdAccList.size()>0) {
    update UpdAccList;
  }

}

I am working in Lightning web components.

HTML

<template>
<lightning:card>
<lightning-file-upload label="Attach receipt" name="fileUploader" accept={acceptedFormats} record-id={recordId} onuploadfinished={handleUploadFinished}> </lightning-file-upload>
<lightning-button label="Save" variant="brand" onclick={handleClick}></lightning-button>
</lightning:card>
</template>

js

import { LightningElement , wire, track, api} from 'lwc';
export default class PriceScreen extends LightningElement { fileName ;
@api recordId;
get acceptedFormats() { return ['.pdf', '.png','.jpg','.jpeg']; }

handleUploadFinished(event) {
// Get the list of uploaded files
  this.fileName =  event.detail.files[0].Id;  
}
handleClick(event) {
newClient({ photo:this.fileName })
.then(result =>
{ const evt = new ShowToastEvent({ title: 'Saved succesfully', variant: 'success', });
this.dispatchEvent(evt); }) 
.catch(error => { this.error = error; });
}

APEX

@AuraEnabled(cacheable = false)
public static Boolean newClient(String photo ){
Client__c client = new Client__c();
client.Photo__c = photo;
try { insert client; return true; }
catch (Exception e) {
throw new AuraHandledException('exceptionText' + e.getMessage()); } }

'Client' is a custom object, having a rich text area field 'Photo'. I am uploading the photo using lightning:file:upload. But the uploaded image is not getting saved into the custom object. Is there any mistake in my code? Actually, I don't know how to save an image into a custom object via apex code.
I want to build flow page component to display a picklist based on record type filtering. 
Is there a component out there that does this already in the open source world?
 
what are the layout specific rules in order of execution?

 
Hi All,

I want to check FLS permissions at field level since it comes as an issue in checkmarx report. The below code is
global class AsyncApexClass{
@future

public static void sendEmail(Set<Id> sendList){
List <Notes__c> notesList = new List<Notes__c>();
notesList.clear();
for(List<EmailMessage> emailmsglist:[select Id,parentId,Parent.Email__c,Parent.Contact.Email,ToAddress, FromAddress, Subject, TextBody, HTMLBody, CreatedDate from EmailMessage where id in :sendList] )
{
        for(EmailMessage emlist :emailmsglist){

             Notes__c note= new Notes__c(); // Create a note object 
             note.Case__c= emlist.parentid;
                 IF (emlist.HTMLBody != NULL && emlist.HTMLBody != ''){
                 note.Message__c = emlist.HTMLBody;
                 }
                 else {
                 note.Message__c = emlist.TextBody;
                 }    
             note.Sent_To__c = emlist.ToAddress;
             note.From__c = emlist.FromAddress;
             note.Subject__c = emlist.Subject;
             note.Datetime_Created__c = emlist.CreatedDate;
             if (emlist.Parent.Contact.Email == emlist.ToAddress || emlist.Parent.Email__c == emlist.ToAddress) // If the email is the same as Case's contact email or Email__c on Case itself, the type is a response.
             {
             note.Type__c = 'Response';
             }
             else {
             note.Type__c = 'Forward/Others';
             }
             notesList.add(note); // Add note object to the list
         }
}
// If the note list has records, insert the list.
if(notesList.size()>0) {
       insert notesList;
       }
}
}

Kindly help me how to check FLS pers=missions at field level and kindly tell me how to test the code after changes.

Thanks,
Looking at SFDC's Trailhead "Get started with apex triggers", I read the following:

"You can call public utility methods from a trigger."

What is an utility method?

Thank you.
  • November 22, 2017
  • Like
  • 0
HI Team


1. if the modifiable system fields feature turned on the created date can changed for an existing record using the api?
 a) true
 b) false

2. Bulk api is best suited for which of these use cases?
 a) Deleting several records, one record at a time.
 b) Writing a mobile chat app.
 c) Building a new salesforce ui
 d) Deleting 100,000 records at once.

3. you are setting up a profile to be used with integration software. which profile permissions should this profile have?(select all that apply.)
 a) customize application.
 b) password never expires.
 c) api only user.
 d) manage data categories.
 e) modify all data.

4. what are ways in which a record id can be obtained ? (select all that apply)
 a) web services api
 b) url
 c) page layout
 d) report
 e) settings panel

5. what actions are tracked in debug logs?
 a) apex code.
 b) data values for fields.
 c) setting changes.
 d) validation rules
 e) callouts


Please give me the reply for above questions.

Regards
Lakshmi
I am using 
<ui:inputDate aura:id="dateField" label="Birthday" value="2014-01-30" displayDatePicker="true"/>

I want to allow users to select only 1st of every month and want to disable all otherdays, how can i achieve it with lightning design system

Thanks,
Balayesu
Hi everyone,
How to deploy application from production to sand box.
please tell me.
Hi!

In my org, I have the Opportunity object, that has a related list from a custom object named Proposta__c.
Proposta__c stores some Opportunity fields values, and a custom PDF as attachment, that contains other Opportunity informations.
Proposta__c records are generated only by a button, embedded in the Opportunity layout, as a Visualforce page commandButton (not a object's custom buttom).
So, in the Opportunity, the user clicks on this button, it calls a Apex extension class that I wrote, that creates a Proposta__c record with its fields, and generates/attach the PDF on this record.
Until here, everything is working as expected.

But, after create a Proposta__c record, I need open It, so I decided to use the onComplete commandButton property to do It.
The onComplete works fine to open the new Proposta__c record, but, when I use onComplete, the PDF attachment is generated as a blank page.
Even if I include the onComplete with no actions on it, the PDF still generate as a blank page.
If I remove only the onComplete property, the PDF is generated perfectly, with all its contents.

The point is: How can I generate correctly the regs and PDF, and then open it? maybe with a onComplete alternative..

Bellow are some tests fragments codes, to make it clearer:

proposta_pdf: The Apex extension class, that generates the Proposta__c record and its PDF attachment:
public class proposta_pdf{
    
    public     Opportunity     opp_temp, opp_reg;
    public     Id              prop_reg_id {get;set;}
    public     String          url_base {get;set;}
 
    // constructor ==============================
    public proposta_pdf(ApexPages.StandardController controller) {
        
        // Get base URL (+prefix, if community)
        this.url_base = URL.getSalesforceBaseUrl().toExternalForm() + Site.getPathPrefix();
        
        // Get other values
        this.opp_temp = (Opportunity)controller.getRecord();
        this.opp_reg = [
            SELECT     Id, Name, Amount, Prop_Versao__c
            FROM     Opportunity 
            WHERE     Id =: this.opp_temp.Id
        ];
    }
       
    // geenerate PDF bin ========================
    public Blob gera_prop_blob(){
        PageReference prop_pag = Page.Proposta_Mestre;
        prop_pag.getParameters().put('id',opp_reg.Id);
        
        Blob prop_blob;
        if(!Test.isRunningTest())
            prop_blob = prop_pag.getContentAsPDF();
        else
            prop_blob = Blob.valueOf('Este e um teste.');

        return prop_blob;
    }

    // create Proposta__c reg + PDF attachment ======
    public void salva_proposta_registro(){

        // validation
        if(this.opp_reg.Prop_Versao__c == NULL)
            this.opp_reg.Prop_Versao__c = 0;
        else
            this.opp_reg.Prop_Versao__c++;
        
        // create/save Proposta__c reg
        Proposta__c prop_reg = new Proposta__c(
            Oportunidade__c     = this.opp_reg.Id,
            Name                = this.opp_reg.Name + ' Ver:' + this.opp_reg.Prop_Versao__c,
            Versao__c             = this.opp_reg.Prop_Versao__c,
            Valor__c            = this.opp_reg.Amount
        );
        insert prop_reg;
                
        // update Proposta__c version stored in a Opportunity field
        update this.opp_reg;
                
        // create/save/attach PDF in Proposta__c reg
        Attachment prop_anex = new Attachment(
            ParentId             = prop_reg.Id,
            Body                 = gera_prop_blob(),
            Name                 = this.opp_reg.Name + ' Ver:' + this.opp_reg.Prop_Versao__c + '.pdf'
        );
        insert prop_anex;
        
        // retur ID to open new reg
        prop_reg_id = prop_reg.Id;
    }

}

Proposta_Mestre: The Visualforce page, rendered as PDF. The Proposta__c attachment:
<apex:page standardController="Opportunity" renderAs="pdf" applyHtmlTag="false" showHeader="false">
	
	Testing Opportunity My PDF
	<br/>ID: {!Opportunity.Id}
	<br/>Name: {!Opportunity.Name}
	<br/>
	<br/>End.
	
</apex:page>

proposta_botoes: The visualforce page that contains the button, embedded in Opportunity layout:
<apex:page standardController="Opportunity" extensions="proposta_pdf">
    <apex:form>
        <apex:inputHidden value="{!Opportunity.Id}"/>          
        <apex:commandButton 
            value="Save" 
            action="{!salva_proposta_registro}" 
            onComplete="window.top.location.replace('{!url_base}/{!prop_reg_id}');"
        />
    </apex:form>
</apex:page>

This is what the Opportunity detail page looks like:
User-added image

And the Proposta__c record, created by the button:
User-added image

When I do NOT use the onComplete in the button, the PDF is generated in the right way:
User-added image

And finally, if I add the onComplete in the commandButton, only a blank page is generated:
User-added image

Additionally, I already tried:
 - Add the extensions="proposta_pdf" in the Visualforce PDF page
 - Use the controller.addFields() method to pass the required fields
With no sucess.

I'm preety new in Apex development, so this can be just a detail that I didn't notice, or some mistake.. but after days searching a solution, I'm still not able to figure out how to fix it.

I'd apreciate some sugestions..
And sorry for my bad english, I'm still beginner :)
Thanks.
Hi All,

I have created a apex class with @InvocableMethod to perfrom the action thorugh the process builder but the apex class is not showing in the process builder can you please suggest why. 
Kindly check the below image.

Thanks.User-added image
1. I want to display other lookup fields when i select different values from picklist "COST HEAD", If i select value as opportunity, Lookup field should displayed next to the "Select Opportunity" Field, similarly same should be displayed for "Select Campaign" & "Select Project", But How can i give only one lookup field & in that lookup i should select either opporunity, Campaign or project , How should i achieve this???


2. If I give Rerendered to form level it is working but , all mandatory fields are showing error before entering the data,
For example, without entering Expens Report ID, if i select Cost Head picklist it will show error on all mandatory fields...
How should overcome this problem.. 

Please help me with the code & refer the screenshot & Code!! 



User-added image


 
<apex:page standardController="Expense_Line_Item__c" extensions="SaveAndNew" sidebar="false"  showHeader="true" >
  <style> span.dateFormat { display:none; } </style>
  <style>
        .text { font-family:Times New Roman ; font-size:13px; font-style:Bold; color:black;}
         
        .pbHeader{
            color:#01375B;
            width:100%;
            font-size:200%;
            font-family:;
        }
        .pbsHeader1
            color:#01375B;
            width:100%;
            font-size:200%;
            font-family;;
        }
   
     </style>  
 <apex:slds />  
 <div class="slds-scope">   
  
    <apex:form id="TR">
     
       
       
        <apex:pageBlock mode="mainDetail" tabStyle="Account" > 
        <apex:facet name="header">Line Items</apex:facet>
            <apex:pageBlockSection columns="2" title=" " collapsible="false"> 
                  <apex:pageBlockSectionItem > 
                        <apex:outputLabel Value="Expense Report Id" styleClass="text" />
                        <apex:inputField value="{!Expense_Line_Item__c.Expense__c}" style="width:150px;" />
                   </apex:pageBlockSectionItem>
                   <apex:pageBlockSectionItem >
                        <apex:outputLabel Value="Expense Line Item Description" styleClass="text" /> 
                        <apex:inputField value="{!Expense_Line_Item__c.Name}"  style="width:150px;" />
                  </apex:pageBlockSectionItem>
                            <apex:pageBlockSectionItem >
                            <apex:outputLabel Value="Date" styleClass="text" />
                            <apex:inputField value="{!Expense_Line_Item__c.Date__c}"  style="width:150px;" />
                            </apex:pageBlockSectionItem>
                            <apex:pageBlockSectionItem >
                            <apex:outputLabel Value="Bill Available" styleClass="text" /> 
                            <apex:inputField value="{!Expense_Line_Item__c.Bill_Available__c}"  />
                            </apex:pageBlockSectionItem>
                  
                 <!-- <apex:pageBlockSectionItem >
                 
                        <apex:outputLabel Value="Date" styleClass="text" />
                        <apex:inputField value="{!Expense_Line_Item__c.Date__c}" style="width:150px;" />                   
                  </apex:pageBlockSectionItem>-->
                    
                  <!--<apex:pageBlockSectionItem >
                        <apex:outputLabel Value="Expense Line Item Description" styleClass="text" /> 
                        <apex:inputField value="{!Expense_Line_Item__c.Name}" style="width:150px;" />
                  </apex:pageBlockSectionItem>-->
                    
                           
                    
                  <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Merchant" styleClass="text" />
                         <apex:inputField value="{!Expense_Line_Item__c.Merchant__c}" style="width:150px;" />
                  </apex:pageBlockSectionItem>
                    
                  <apex:pageBlockSectionItem >
                         <apex:outputLabel Value=" Merchant GST Number" styleClass="text" />
                         <apex:inputField value="{!Expense_Line_Item__c.Merchant_GST_Number__c}" style="width:150px;"/>
                  </apex:pageBlockSectionItem>
                    
                  </apex:pageBlockSection>
                
                  <apex:pageBlockSection columns="2" title="Expense Details " collapsible="true">
                   
                  <apex:pageBlockSectionItem >  
                         <apex:outputLabel Value="Approved" styleClass="text" />  
                         <apex:inputField value="{!Expense_Line_Item__c.Approved__c}" />
                  </apex:pageBlockSectionItem>    
                  
                  <apex:pageBlockSectionItem > 
                         <apex:outputLabel Value="Amount" styleClass="text" />     
                         <apex:inputField value="{!Expense_Line_Item__c.Amount__c}"  style="width:150px;" />
                  </apex:pageBlockSectionItem>
                    
                 <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Payment Type" styleClass="text" /> 
                         <apex:inputField value="{!Expense_Line_Item__c.Payment_Type__c}" style="width:150px;"  />
                  </apex:pageBlockSectionItem> 
                  
                 
                 
                 <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Cost Head" styleClass="text" />   
                         <apex:inputField value="{!Expense_Line_Item__c.Cost_Head__c}" style="width:150px;" required="true" >
                         <apex:actionSupport event="onchange" rerender="TR" />
                         </apex:inputField>
                  </apex:pageBlockSectionItem>
                    
                  <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Select Campaign" styleClass="text" />   
                         <apex:inputField value="{!Expense_Line_Item__c.Related_to_Campaign__c}" style="width:150px;" rendered="{!IF( Expense_Line_Item__c.Cost_Head__c== 'Campaign',true,false  )}" />
                  </apex:pageBlockSectionItem>
                     
                  <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Select Opportunity" styleClass="text" /> 
                         <apex:inputField value="{!Expense_Line_Item__c.Related_to_Opportunity__c}" style="width:150px;" rendered="{!IF( Expense_Line_Item__c.Cost_Head__c== 'Opportunity',true,false  )}" />
                  </apex:pageBlockSectionItem>
                    
                  <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Select Project" styleClass="text" /> 
                         <apex:inputField value="{!Expense_Line_Item__c.Project__c}" style="width:150px;" rendered="{!IF( Expense_Line_Item__c.Cost_Head__c== 'Project',true,false  )}" />                                                            
                  </apex:pageBlockSectionItem>
                      
                  
                    <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Expense Head" styleClass="text" /> 
                         <apex:inputField value="{!Expense_Line_Item__c.Expense_Head__c}" style="width:150px;" required="true" >
                         <apex:actionSupport event="onchange" rerender="TR" />  
                         </apex:inputField>
                  </apex:pageBlockSectionItem>
                     
                        
                  <!-- <apex:outputPanel id="ren">-->
                    
                  
                  <!-- </apex:outputPanel> -->
                  <!--  <apex:pageBlockTable value="{!Expense_Line_Item__c}" var="item" columns="2" >
                  <apex:column> 
                  <apex:outputLabel >  
                  <apex:inputField label="City"  value="{!item.City__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false )}" /></apex:outputLabel>
                  <apex:inputField label="Mode of travel" value="{!item.Mode_Of_Travel__c}" rendered="{!IF(Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false  )}" />
                  <apex:inputField label="Location from" value="{!item.Location_From__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false  )}" /> 
                  <apex:inputField label="Location to" value="{!item.Location_To__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false  )}" /> </apex:column>
                  <apex:column>       
                  <apex:inputField value="{!item.Sub_Expense__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Food',true,false  )}" /> </apex:column>
                  <apex:column>           
                  <apex:inputField value="{!item.Sub_Expense__c}" rendered="{!IF(Expense_Line_Item__c.Expense_Head__c== 'Entertainment',true,false  )}" /> </apex:column>
                  <apex:column>          
                  <apex:inputField value="{!item.Sub_Expense__c}" rendered="{!IF(Expense_Line_Item__c.Expense_Head__c== 'Lodging',true,false  )}" /> </apex:column>
                  <apex:column> <apex:inputField value="{!item.Sub_Expense__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Others',true,false  )}" /> </apex:column>
                                                              
                  </apex:pageBlockTable>-->
              
               
                  <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c == 'Travel',true,false )}" >
                         <apex:outputLabel Value="City" styleClass="text" />
                         <apex:inputField value="{!Expense_Line_Item__c.City__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false )}" style="width:150px;" />
                  </apex:pageBlockSectionItem>
                   
                  <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false )}" >
                         <apex:outputLabel Value="Mode Of Travel" styleClass="text" />
                         <apex:inputField value="{!Expense_Line_Item__c.Mode_Of_Travel__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false  )}" style="width:150px;" />
                   </apex:pageBlockSectionItem>
                   
                   <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false )}" >
                       <apex:outputLabel Value="Location From" styleClass="text" />
                       <apex:inputField value="{!Expense_Line_Item__c.Location_From__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false  )}" style="width:150px;" />
                   </apex:pageBlockSectionItem>  
                   
                    <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false )}" >
                       <apex:outputLabel Value="Location To" styleClass="text" />
                       <apex:inputField value="{!Expense_Line_Item__c.Location_To__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Travel',true,false  )}" style="width:150px;" />
                   </apex:pageBlockSectionItem>
                   
                   <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Food',true,false  )}" >
                        <apex:outputLabel Value="Sub Expense" styleClass="text" />
                        <apex:inputField value="{!Expense_Line_Item__c.Sub_Expense__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Food',true,false  )}" style="width:150px;"  />
                   </apex:pageBlockSectionItem>
                   
                    <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Entertainment',true,false  )}" >
                        <apex:outputLabel Value="Sub Expense" styleClass="text" />
                        <apex:inputField value="{!Expense_Line_Item__c.Sub_Expense__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Entertainment',true,false  )}" style="width:150px;" />
                   </apex:pageBlockSectionItem>
                   
                    <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Lodging',true,false  )}" >
                        <apex:outputLabel Value="Sub Expense" styleClass="text" />
                   <apex:inputField value="{!Expense_Line_Item__c.Sub_Expense__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Lodging',true,false  )}" style="width:150px;"  />
                   </apex:pageBlockSectionItem>
                   
                    <apex:pageBlockSectionItem rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Others',true,false)}" >
                        <apex:outputLabel Value="Sub Expense" styleClass="text" />
                        <apex:inputField value="{!Expense_Line_Item__c.Sub_Expense__c}" rendered="{!IF( Expense_Line_Item__c.Expense_Head__c== 'Others',true,false  )}" style="width:150px;" />
                   </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                         <apex:outputLabel Value="Comments" styleClass="text" /> 
                         <apex:inputTextarea value="{!Expense_Line_Item__c.Comments__c}" style="width:150px;" />
                  </apex:pageBlockSectionItem>                                  
               </apex:pageBlockSection>   
                     
            </apex:pageBlock>
            <div align="center" draggable="false" >
            <apex:commandButton action="{!Save}" value="Save" style="font-style:BOld;size:20px;font-family:Georgia ;color:Black; background:LightBlue;width:95px;" /> &nbsp;
            <apex:commandButton action="{!Cancel}" value="Cancel" style="font-style:BOld;size:20px;font-family:Georgia ;color:Black; background:LightBlue;width:95px;"  /> &nbsp;
            <apex:commandButton action="{!saveNew}" value="Save & New" style="font-style:BOld;size:20px;font-family:Georgia ;color:Black; background:LightBlue;width:95px;" />
            </div> 
       
    </apex:form>
    </div>
    </apex:page>
  • July 26, 2017
  • Like
  • 0

Hey, team I am facing some issue WHile Updating Accouunts Notes in My Vf page. please advice .


Visualforce Page

 

Case

ABC Firms wants a custom UI which has ability for them to view Account with account notes on one screen. They wish to create/update multiple account notes simultaneously.

Requirement Details

  • Create a custom object Account notes with Account as parent.
  • Set name field as auto-number and a custom field ‘Notes’ of text area type.
  • Create a custom VF tab, ‘Note Update’.
  • VF Page should have capability of pagination and text provided by user should maintain its state throughout pagination.
  • While pagination a loading image should be displayed for user to wait till operation completes.
  • VF Page should display – Account Number(Read Only), Account Name(Read Only), Account Notes (Notes field of related object in editable mode)
  • Against one account only one account notes will be shown (hence pull the most recent record)
  • User will have the ability to create new note if Note field is blank
  • If note field has some existing value, user will have ability to update it
  • Save button should help user in saving all the changes made by him.
  • 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
global class AccountWrapper {
    public String Name{get;set;}
    public String accountNumber{get;set;}
    public Account account{get;set;}
    public List<Account_Note__c> accountNote{get;set;}
    
    public AccountWrapper (String accName,String accNumber,List<Account_Note__c> Acc_Note)
    {
        this.Name = accName;
        this.accountNumber = accNumber;
        this.accountNote = Acc_Note;
        
        for(Account_Note__c accNote : accountNote)
        {
            if(accNote==null)
                accNote = new Account_Note__c();
        }
        
    }
    
    public AccountWrapper(){
        account = new Account();
    }
    public Pagereference save(){
        
        return null;
    }
}
 
==========================Controller=====================

public class AccountWrapperController{
    public List<AccountWrapper> lstWrapper{get; set;}
    public List<Account_Note__c> lstSetController{get; set;}
    public List<account> acc_Lst{get;set;}
    
    public ApexPages.StandardSetController con {
        get {
            if(con == null) {
                con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name,AccountNumber,(SELECT Id, Notes__c FROM Account_Notes__r ORDER BY CreatedDate DESC limit 1) FROM Account])); 
                //here you can set the record size to display                
                con.setPageSize(10);       
            }
            return con;
        }
        set;
    } 
    public List<Account> getAccounts() {
        return (List<Account>) Con.getRecords();
    }
    
    /*****************Creating the constructor***********************/ 
    
    
    public AccountWrapperController() {
        lstWrapper =  new List<AccountWrapper>();
        lstSetController = new List<Account_Note__c>();
        try{ 
            for(Account acc : ([SELECT Name,AccountNumber,(SELECT Id, Notes__c FROM Account_Notes__r ORDER BY CreatedDate DESC limit 1) FROM Account])){
                lstWrapper.add(new AccountWrapper(acc.Name,acc.AccountNumber,acc.Account_Notes__r));
            }
            
        }
        catch(SObjectException se) {
            System.debug('The following exception has occurred: ' + se.getMessage());
        }
        /*  obj = new CustomIterable (lstWrapper); 
obj.setPageSize = 10;
next();   */     
    }
    
    /*********************pagination methods*********************/  
    
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }
    
    public Boolean hasPrevious {
        get {
            return con.getHasPrevious();
        }
        set;
    }
    
    public Integer pageNumber {
        get {
            return con.getPageNumber();
        }
        set;
    }
    
    public void first() {
        con.first();
    }
    
    public void last() {
        con.last();
    }
    
    public void previous() {
        con.previous();
    }
    
    public void next() {
        con.next();
    }
    
    public void cancel() {
        con.cancel();
    }  
    
    
    
    
    /*************************Update Method**********************/   
    public void UpdateNotes() {
        try{
            account_note__c an = new account_note__c();
            for(AccountWrapper AccWrap : lstwrapper){
                for(Account_Note__c Acnt_Note : AccWrap.AccountNote){
                    // upsert Acnt_Note;
                    lstSetController.add(Acnt_Note);
                }
                if(lstSetController.size()>0)
                {
                    upsert lstSetController;
                }
            }
        }
        
        catch(DmlException e) {
            System.debug('DmlException caught: ' + e.getMessage()); 
        }
    }
    public void processAjaxRequest(){  
        //Do some processing here  
        for(Integer i =0 ; i < 10000; i++){  
        }  
    }  
}
 
====================VF page=========================

<apex:page controller="AccountWrapperController" >
    <apex:form >
        <apex:pageBlock id="myPage" mode="edit" >
            
            <apex:pageBlockButtons location="both">
                <apex:commandButton id="update" action="{!UpdateNotes}" value="Save" reRender="myPage" status="actStatusId"/>
                <apex:actionStatus id="actStatusId" >
                    <apex:facet name="start" >
                        <img src="/img/loading.gif" />                    
                    </apex:facet>
                </apex:actionStatus>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection columns="1">
                
                <apex:pageBlockTable value="{!Accounts}" var="acc" >
                    
                    <apex:column >
                        <apex:facet name="header">Account Name</apex:facet>
                        <apex:outputtext value="{!acc.Name}"/>
                    </apex:column>
                    
                    <apex:column >
                        <apex:facet name="header">Account Number</apex:facet>
                        <apex:outputtext value="{!acc.AccountNumber}"/>
                    </apex:column>
                    <apex:inlineEditSupport showOnEdit="update, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/> 
                    
                    <apex:column >
                        <apex:facet name="header">Account Notes</apex:facet>            
                        <apex:repeat value="{!acc.Account_Notes__r }" var="note">
                            
                            <apex:inputText value="{!note.Notes__c}"/>
                            
                        </apex:repeat>
                    </apex:column>  
                    
                </apex:pageBlockTable>
                
                
                <apex:outputPanel >
                    <apex:commandButton value="<<Previous" action="{!previous}" rendered="{!hasPrevious}" reRender="myPage" status="blockUI" />
                    
                    <apex:commandButton value="Next >>" action="{!next}" rendered="{!hasNext}" reRender="myPage"  status="NextStatusId"  />
                    <apex:actionStatus id="NextStatusId" >
                        <apex:facet name="start" >
                            <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel>  
            </apex:pageBlockSection>
            
        </apex:pageBlock>
    </apex:form>
    
</apex:page>



 
How do you rationalize the data using SOQL query?
This is an interview question asked by the interviewer ,
can anyone help out .
can suggest any links or books or clear answer .
Thanks in advance
How long does it typivally take to create environment hub org? I created an org in environment hub in my DE for trailhead, the org is not yet created and it is not even showing up in the environment hub. 

This is the message which i got after i clicked create 
"The new organization "TrailHead Org Development" is being created. When it is ready you will get an email confirmation, and it will appear in the Environment Hub."

Thanks for your help.
I implemented a rest service in java and try to have a correct format of uri for query, insert, update, delete a case record from salesforce.
Is there a resource for this?
Thank you.
Hai,
I am using static resource in my visual force page. But in that visual force i used alert message and toggle function. but it is not working properly.I tried but it is not comming.
Vf page
--------------------------
<apex:page >
  <apex:includeScript value="{!URLFOR($Resource.jqueryui,'/Naveen/jquery/jquery.js')}"/>
  <apex:includeScript value="{!URLFOR($Resource.jqueryui,'/Naveen/jquery/jquery-ui.js')}"/>
  <script>
  j$=jQuery.noConflict();
  if(j$){
            alert('Success');
  }
  else
  {
            alert('Failure');
  }
  function show()
  {
      j$('[id$=one]').toggle()
  }
  </script>
  <apex:pageBlock id="pb" title="FirstBlock" onmouseover="show()">
  This is Block one
  </apex:pageBlock>
  
  <apex:pageBlock id="one" title="FirstBlock">
  This is Block one
  </apex:pageBlock>
</apex:page>

Any one help me to slove this.Please.