• Lokesh__Pareek
  • NEWBIE
  • 55 Points
  • Member since 2015

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 8
    Replies
Hi, I'm trying to have all pictures and pdfs in the attachment of a record displayed in a Visualforce page when a user klick on a button"View all files". I keep getting the Error:
"System.ListException: List index out of bounds: 0
Class.displayImageExtension.getFileId: line 15, column 1"

I'm an administrator and just beginning to code. Please help. Thank you.

here is my Code:
Controller:
Public Class displayImageExtension {

    String recId;
    
    public displayImageExtension(ApexPages.StandardController controller) {
        recId = controller.getId();    
    }
    
    public List<String> getFileId() {
        String[] fileId = new List<String>();
        List<Attachment> attachedFiles = [select Id from Attachment where parentId =:recId order By LastModifiedDate DESC ];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
        for (Integer i=0 ; i < attachedFiles.size(); i++) {   
            
            fileId[i] = attachedFiles[i].Id;
            }      
        }
        return fileId;
            
    }
}

Visualforce page:
<apex:page standardController="Account" extensions="displayImageExtension">
<apex:form >
<apex:image url="/servlet/servlet.FileDownload?file={!FileId}"/>
</apex:form>
</apex:page>
Hi all. I'm just startig with Apex, so I'm really noob to these matters :(
What I'm trying to achieve is to assign an unique number to every Opportunity Line Item is created in each Opportunity.
I've created two custom fields:
- One in the Opportunity object: Product_Count
- One in the Opportunity Product Objetct: Item_Number

I've created some worflows, so when an Opportunity Line Item is created:
- Item_Number = Product_Count + 1
- Product_Count = Product_Count +1

Through worflows, the thing seems to be running fine, but the problem is that when I insert more than one product at a time, they all get the same Item_Number.

Now, I'm trying to write an Apex trigger to do the same thing, but I'm really stuck. I can only set a fix value for each item (the same number to all of them), but I can't update the Opportunity field Product_Count or the Opportunity product Item_Number

This is how may trigger looks:

trigger NumeroItem on OpportunityLineItem (before insert) {    
        for (OpportunityLineItem OLI: Trigger.new)   {     
        OLI.N_de_Item__c = 3;         
        }      
}

Would you be so kind as to give me a hand with this?
I don't think it should be really hard, but as I'm just starting with Apex, I'm a bit overwhelmed :(

Thank you ver very much for your help.
Kind regards.
Hi guys,
i am gettting an error showing that attachment pdf doesnot exit any solution for this. 

PageReference pdf = Page.attachmentPDF;
pdf.getParameters().put('id',(String)account.id); pdf.setRedirect(true);
// Take the PDF content Blob b = pdf.getContent();
// Create the email attachment
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('attachment.pdf');
efa.setBody(b);

Thanks
Reddy
Hi, I'm trying to have all pictures and pdfs in the attachment of a record displayed in a Visualforce page when a user klick on a button"View all files". I keep getting the Error:
"System.ListException: List index out of bounds: 0
Class.displayImageExtension.getFileId: line 15, column 1"

I'm an administrator and just beginning to code. Please help. Thank you.

here is my Code:
Controller:
Public Class displayImageExtension {

    String recId;
    
    public displayImageExtension(ApexPages.StandardController controller) {
        recId = controller.getId();    
    }
    
    public List<String> getFileId() {
        String[] fileId = new List<String>();
        List<Attachment> attachedFiles = [select Id from Attachment where parentId =:recId order By LastModifiedDate DESC ];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
        for (Integer i=0 ; i < attachedFiles.size(); i++) {   
            
            fileId[i] = attachedFiles[i].Id;
            }      
        }
        return fileId;
            
    }
}

Visualforce page:
<apex:page standardController="Account" extensions="displayImageExtension">
<apex:form >
<apex:image url="/servlet/servlet.FileDownload?file={!FileId}"/>
</apex:form>
</apex:page>
Hi all. I'm just startig with Apex, so I'm really noob to these matters :(
What I'm trying to achieve is to assign an unique number to every Opportunity Line Item is created in each Opportunity.
I've created two custom fields:
- One in the Opportunity object: Product_Count
- One in the Opportunity Product Objetct: Item_Number

I've created some worflows, so when an Opportunity Line Item is created:
- Item_Number = Product_Count + 1
- Product_Count = Product_Count +1

Through worflows, the thing seems to be running fine, but the problem is that when I insert more than one product at a time, they all get the same Item_Number.

Now, I'm trying to write an Apex trigger to do the same thing, but I'm really stuck. I can only set a fix value for each item (the same number to all of them), but I can't update the Opportunity field Product_Count or the Opportunity product Item_Number

This is how may trigger looks:

trigger NumeroItem on OpportunityLineItem (before insert) {    
        for (OpportunityLineItem OLI: Trigger.new)   {     
        OLI.N_de_Item__c = 3;         
        }      
}

Would you be so kind as to give me a hand with this?
I don't think it should be really hard, but as I'm just starting with Apex, I'm a bit overwhelmed :(

Thank you ver very much for your help.
Kind regards.
1)Which declarative method helps ensure quality data?
  Choose 3 answers

  A.Validation rules
  B.Workflow alerts
  C.Lookup filters
  D.Page Layout


2)A developer creates an Apex helper class to handle complex trigger logic.
  How can the helper class warn users when the trigger exceeds DML governor limits?

  A. By using Messaging.SendEmail() to continue the transaction and send an alert to the user after the number of DML statements is exceeded.
  B. By using ApexMessage.Message() to display an error message after the number of DML statements is exceeded.
  C. By using Limits.getDMLRows() and then displaying an error message before the number of DML statements is exceeded.
  D. By using PageReference.setRedirect() to redirect the user to a custom Visualforce page before the number of DML statements is exceeded.

3)In the Lightning Component framework, which resource can be used to fire events?
   2 Answers correct
  
   A.Third-party Javascript code
   B.Javascript controller actions
   C.Third-party web service code.
   D.Visualforce controller actions.
Hi Team,

I have a requirement like page1 and page2. in the page1 have one dropdown with values, if user selects one of the value within the dropdown then respective result set will be displayed in the dashboard.in that dashboard one of the column contains the id, after clicking on the id it will redirects to the respective page.
now my requirement is if user want to come back the page1 then user need to clicks on the cancel button then user will get the page1, but last selected dropdown value i need to display.
can anyone please help me on this.

Thanks in advance.

 
Hi  Experts,

 Below code is working fine have no problem because of this too many queries am gettin 50001 issue when migrated to production

  Is there any alternative way to load the query count to the variable please suggest me
     
String query = 'SELECT Id, Name, OwnerId, Owner.Name, NextStep, StageName, Total_List_Price_Amount__c, ForecastCategoryName, '+
                        'CloseDate, Amount,Formula_Amount__c,(Select Id,Name,Status__c from SPR__r ORDER BY CreatedDate DESC LIMIT 1) '+
                       'FROM '+
                        'Opportunity '+
                       'WHERE '+
                        'Id != null';


  List<Id> listOppIds = new List<Id>(); 
        //List<Opportunity> CountOppRecords = Database.query(query);
        total_size = CountOppRecords.size();

Thanks
Sudhir