• Prasath
  • NEWBIE
  • 168 Points
  • Member since 2016
  • Programmer Analyst
  • Cognizant Technology Solutions


  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 39
    Replies
public with sharing class NumberOfAccountsRelatedToUser {

	public static void triggerHandler( System.TriggerOperation triggerEvent , list<Account> newAccounts, List<Account> oldAccounts) {

		Set<ID> sdr_owner_IDs = new Set<ID>();
		Set<ID> account_owner_IDs = new set<ID>();


		if(triggerEvent == TriggerOperation.AFTER_INSERT){
			for(Account a: newAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
		}
		if(triggerEvent == TriggerOperation.AFTER_UPDATE){
			for(Account a: newAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
			for(Account a: oldAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
		}

		if(triggerEvent == TriggerOperation.AFTER_DELETE){
			for(Account a: oldAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
		}

		System.debug(sdr_owner_IDs);
		System.debug(account_owner_IDs);


		List<AggregateResult> sdr_prospect_accounts = [SELECT COUNT(ID) sdr_accounts, SDR_Owner__c FROM Account WHERE SDR_Owner__c in :sdr_owner_IDs and (type ='Prospect - Being Worked' OR type='Prospect - Open' ) GROUP BY SDR_Owner__c];
		List<AggregateResult> owner_prospect_accounts = [SELECT COUNT(ID) owner_accounts, OwnerID FROM Account WHERE OwnerID in :account_owner_IDs and (type ='Prospect - Being Worked' OR type='Prospect - Open' ) GROUP BY OwnerID];

		Map<Id, List<Integer>> userID_And_num_of_accounts = new Map<Id, List<Integer>>();

		for(AggregateResult ar: sdr_prospect_accounts){
			// put the id in the list
			userID_And_num_of_accounts.put((ID)ar.get('SDR_Owner__c'), new List<Integer>());

			// add the number of sdr accounts to that IDs map
			userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add((Integer)ar.get('sdr_accounts'));
			userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add(0);
		}

		for(AggregateResult ar: owner_prospect_accounts){

			// if the id already exists
			if(userID_And_num_of_accounts.containsKey((ID)ar.get('OwnerID'))){

				userID_And_num_of_accounts.get((ID)ar.get('OwnerID')).add(1, (Integer)ar.get('owner_accounts'));
			} else {
				userID_And_num_of_accounts.put((ID)ar.get('SDR_Owner__c'), new List<Integer>());

				userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add(0);
				userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add((Integer)ar.get('owner_accounts'));
			}
		}

		// now we want to update the users field
		List<ID> user_IDs = new List<ID>();

		for(ID user_ID: userID_And_num_of_accounts.keySet()){
			user_IDs.add(user_ID);
		}

		// now we want to get the actual user object
		List<User> users = [SELECT ID, SDR_Owner_Prospect__c , Account_Owner_Prospect__c FROM User WHERE ID in :user_IDs];


		List<User> users_to_update = new List<User>();
		for(User u: users){
			List<Integer> sdr_and_owner_accounts = userID_And_num_of_accounts.get(u.ID);
			u.SDR_Owner_Prospect__c = sdr_and_owner_accounts[0];
			u.Account_Owner_Prospect__c = sdr_and_owner_accounts[1];
			users_to_update.add(u);
		}

		// update users
		update users_to_update;

	}


}

Line 45 is saying I am out of bounds. Does not make sense.
Hi All,

I have a vf page where i have a field Contact name on case which is a lookup to contact. I want when the user logged in as community user it should autopopulate his/her name in that contact field.

vf-page:
<apex:page standardController="Case" extensions="AutoPopulateExample">
   
    <apex:form id="form">
    	<apex:pageBlock >
          
            <apex:pageBlockButtons location="top">
              <apex:commandButton value="Save" action="{!Save}"/>
              
              <apex:commandButton value="Cancel" action="{!Cancel}"/>
            </apex:pageBlockButtons> 
            <apex:actionRegion >
           <apex:pageBlockSection title="Basic Details" columns="2">
               <apex:inputField label="Contact Name" value="{!Case.ContactId}" >
               	<apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/>
               </apex:inputField>
               <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/>
               <apex:inputField label="Account Name" value="{!Case.AccountId}"/>
               <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/>
               <apex:inputField label="Status" value="{!Case.Status}"/>
               <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/>
               <apex:inputField label="Subject" value="{!Case.Subject}"/>
               <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/>
               <apex:inputField label="Product" value="{!Case.Products__c}"/>
               <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/>
               <apex:inputField label="Components" value="{!Case.Componet__c}"/>
               <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/>
               <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/>
               <apex:inputField label="Environment" value="{!Case.Environment__c}"/>
               <apex:inputField label="Description" value="{!Case.Description__c}"/>
           </apex:pageBlockSection>
            </apex:actionRegion>
            </apex:pageBlock>
       
             <!--<apex:commandButton value="Upload files" action="{!save}" reRender="theSection"/> -->
            <apex:outputPanel id="theSection" rendered="true">
            <apex:pageblock >
                 <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1">
        <div id="upload" class="upload">                                   
            <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/>                            
        </div> 
         </apex:pageBlockSection>      
   		 </apex:pageBlock>
            </apex:outputPanel>       
     </apex:form>
</apex:page>

 
Hi 
I am creating case through vf page where i have to attach attchment to that case while creating that case record but when i hit the save button. I am geeting error as 
"Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
Error is in expression '{!Save}' in component <apex:commandButton> in page newcase_page_for_community: Class.AutoPopulateExample.save: line 64, column 1"
Please let me know if i am doing something wrong.

VF page
<apex:page standardController="Case" extensions="AutoPopulateExample">
   
    <apex:form id="form">
    	<apex:pageBlock >
          
            <apex:pageBlockButtons location="top">
              <apex:commandButton value="Save" action="{!Save}"/>
              <apex:commandButton value="Cancel" action="{!Cancel}"/>
            </apex:pageBlockButtons> 
            
           <apex:pageBlockSection title="Basic Details" columns="2">
               <apex:inputField label="Contact Name" value="{!Case.ContactId}" >
               	<apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/>
               </apex:inputField>
               <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/>
               <apex:inputField label="Account Name" value="{!Case.AccountId}"/>
               <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/>
               <apex:inputField label="Status" value="{!Case.Status}"/>
               <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/>
               <apex:inputField label="Subject" value="{!Case.Subject}"/>
               <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/>
               <apex:inputField label="Product" value="{!Case.Products__c}"/>
               <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/>
               <apex:inputField label="Components" value="{!Case.Componet__c}"/>
               <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/>
               <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/>
               <apex:inputField label="Environment" value="{!Case.Environment__c}"/>
               <apex:inputField label="Description" value="{!Case.Description__c}"/>
           </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
		
        <apex:form >
            <apex:outputPanel id="theSection" rendered="true">
            <apex:pageblock >
                <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1">
        <div id="upload" class="upload">                                   
            <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/>                            
        </div> 
         </apex:pageBlockSection>      
   		 </apex:pageBlock>
            </apex:outputPanel>       
     </apex:form>
	 
</apex:page>

Apex Controller :
public class AutoPopulateExample
{
public string fileName{get;set;} 
public Blob fileBody{get;set;}
public Contact con{get;set;}
public Case caseObject{get;set;}
public Attachment attachmentObject  {
  get {
      if (attachmentObject  == null)
        attachmentObject  = new Attachment();
      return attachmentObject ;
    }
  set;
  }
public ApexPages.StandardController stdCntrlr {get; set;}
    
public AutoPopulateExample(ApexPages.StandardController controller)
{
    con = new Contact();
    caseObject = new case();
    caseObject = (Case)controller.getRecord();
    attachmentObject = new Attachment();
}

//function is called from actionsupport event

public void autoCal()
{

Id conid = caseObject.ContactId;     // collecting contact id from visualforce page
List<Contact> conLst = [select id,AccountId,FirstName,LastName,Email,Phone from contact where id=:conid];
if(conLst.isEmpty())
{
 return;
}    
caseObject.Requestor_First_Name__c = conLst[0].FirstName;      
caseObject.AccountId = conLst[0].AccountId; 
caseObject.Requestor_Last_Name__c = conLst[0].LastName;
caseObject.Requester_Email__c = conLst[0].Email; 
caseObject.Requester_Contact_Number__c = conLst[0].Phone; 
}

public PageReference save()
{
        // Save the Case
        insert caseObject;

        // Save the Attachment using the Case id as the parent Id
        System.debug('@@@@@fileBody'+fileBody);     
        attachmentObject = new Attachment();
              Integer i=0;
              attachmentObject .clear();
              attachmentObject.Body = fileBody; 
              attachmentObject.Name = 'Logo_'+caseObject.id+'.jpeg' ; 
              attachmentObject.ParentId = caseObject.id;             
              insert attachmentObject;                 
        pagereference pr = new pagereference('/'+caseObject.id);                           
        return pr;
}
}

Please suggest.
Hello,

One of the lines in this code is using a kind of syntax that I do not know. See line 13:  Account acct = accts[j]
On the left of the = it is declaring the object acct of the Class Account, that is clear.
On the right of the = I do not know what it is doing, I have not used this syntax before. The object accts is a List that is declared on line 04 and [j] here is limiting the frecuency of iterations in the loop on line 14. But, I do not understand (yet) what this (= accts[j]) is doing .
@isTest
public class TestDataFactory {
    public static List<Account> createAccountsWithOpps(Integer numAccts, Integer numOppsPerAcct) {
        List<Account> accts = new List<Account>();
        
        for(Integer i=0;i<numAccts;i++) {
            Account a = new Account(Name='TestAccount' + i);
            accts.add(a);
        }
        insert accts;
        
        List<Opportunity> opps = new List<Opportunity>();
        for (Integer j=0;j<numAccts;j++) {
            Account acct = accts[j];
            // For each account just inserted, add opportunities
            for (Integer k=0;k<numOppsPerAcct;k++) {
                opps.add(new Opportunity(Name=acct.Name + ' Opportunity ' + k,
                                         StageName='Prospecting',
                                         CloseDate=System.today().addMonths(1),
                                         AccountId=acct.Id));
            }
        }
        // Insert all opportunities for all accounts.
        insert opps;
        
        return accts;
    }
}
Could you possibly explain what is = accts[j] actually doing?

Thank you very much.

 
  • November 29, 2017
  • Like
  • 0
I get the error written in the title. When i add <apex:form></apex:form> tags it gives the error: Error: <messaging:emailTemplate> cannot contain <apex:form>.   So im stuck in a loop. Could someon help me out. Here is my VF email template, class and componet:
<messaging:emailtemplate recipienttype="contact" subject="Product Enquiry">
  <messaging:htmlemailbody > 
     Congratulations!
     This is your new Visualforce Email Template. Following are a list of randomly choosen accounts in my org:
    <!-- Embedding visualforce component here -->
    <c:emailcontroller >
  </c:emailcontroller></messaging:htmlemailbody> 
</messaging:emailtemplate>
 
<apex:component access="global" controller="SendemailController" >

<script type="text/javascript">
function init() {
sendEmail();
}
if(window.addEventListener)
window.addEventListener('load',init,true)
else
window.attachEvent('onload',init)
</script>
<apex:form>
<apex:actionFunction name="sendEmail" action="{!sendEmailFunction}">
</apex:actionFunction>
</apex:form>
</apex:component>
 
public class SendemailController {
public String AttachmentId {get;set;}

Public SendemailController(){
AttachmentId = ApexPages.currentPage().getParameters().get('Id');
system.debug('Attachment id->'+AttachmentId );
}

Public Pagereference sendEmailFunction(){
Attachment getEmail = [SELECT Id,Name,ContentType FROM Attachment where ParentId ='0Q00Y000000LIVL' LIMIT 1];
if(getEmail.Id != null) {
String toaddress = 'info@test.com';
system.debug(toaddress);

try {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {toaddress};
String[] ccAddresses = new String[] {'info@test.com'};
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setReplyTo(toaddress);
mail.setSenderDisplayName('You have don it');
mail.setSubject('Testing email through apex');
mail.setBccSender(false);
mail.setUseSignature(true);
mail.setPlainTextBody('This is test email body. This mail is being sent from apex code');
//mail.setHtmlBody('<b> This is HTML body </b>' );

List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (Attachment a : [select Name, Body, BodyLength from Attachment where ParentId = '0Q00Y000000LIVL']){
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
//mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
}
mail.setFileAttachments(fileAttachments);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

} catch(Exception e) {}
}

PageReference reference = new PageReference('https://eu11.salesforce.com/'+AttachmentId);
reference.setRedirect(true);
return reference;
}

}

 
Hi All,

I wanted to run a query on a Opp Stage value = Closed Won. I wanted to see in what automation tools that value is used. Is it possible to do that in Developer Console and if yes, could someone helo me with the query?
Many thanks in advance
Ewa
Hello,

I have trigger on contentdocumentlink where number files added is rollep up on one of the field(Total_no_of_attachment__c) of custom object(promotion__c).But when updating the list,it throwing List index out of bounds: 1  exception.

below is the code:
trigger UploadFilesToPromo on ContentDocumentlink (after insert,after delete,after undelete) {
        List<ContentDocumentLink > data=trigger.isinsert?trigger.new:trigger.old;    
        set<id> promotionid = new set<id>();
        set<id> docId = new set<id>();
        System.debug('data***********'+data+'************');
        
        
        for(ContentDocumentLink att:data)
        {
            promotionid.add(att.LinkedEntityId );
            System.debug('parentID ************'+att.LinkedEntityId +'************');
            System.debug('id in set -promotionid ************'+promotionid);
        }
        
        List<promotion__c> oldpromotionWithAtt = new List<promotion__c>();
        oldpromotionWithAtt =[select id,total_no_of_attachment__c from promotion__c where Id IN:promotionid ];
        for(promotion__c promo : oldpromotionWithAtt) {
            docId.add(promo.Id);
        }
        system.debug('promotionlist.....................................'+oldpromotionWithAtt );
        system.debug('docID set id--------'+docId);
        List<AggregateResult> totalCount= [SELECT count(Id) total FROM ContentDocumentLink WHERE LinkedEntityId IN: docId];
        System.debug('totalcount of files----------------------'+totalCount+'************');
        Integer i=0;
        List<promotion__c> ls = new List<promotion__c>();
        try{
            for(ContentDocumentLink atr:data)
            {
                promotion__c pr=oldpromotionWithAtt.get(i); 
              
                try{
                        pr.Total_No_of_Attachment__c=Integer.valueOf(totalCount[i].get('total'));
                        system.debug('output...............'+pr.Total_No_of_Attachment__c);
                } catch(Exception ex)
                  {    
                        System.debug('exception new   ............'+ex);
                        pr.Total_no_of_attachment__c=0;
                        system.debug('output...............'+pr.Total_no_of_attachment__c);
                  } 
                     i++;
                    ls.add(pr);
                    system.debug('ls list from adding pr'+ls);
                
            }
            
            system.debug('final op============================'+ls);
            if(ls.size()>0 && !ls.IsEmpty()){
                system.debug('ls.size++++++++++++++++++'+ls.size());
                update ls;
            } 
        }
        catch(exception ex1)
        {
            System.debug('exception   ............'+ex1);
        }
        
   }


Thanks in advance.
public with sharing class NumberOfAccountsRelatedToUser {

	public static void triggerHandler( System.TriggerOperation triggerEvent , list<Account> newAccounts, List<Account> oldAccounts) {

		Set<ID> sdr_owner_IDs = new Set<ID>();
		Set<ID> account_owner_IDs = new set<ID>();


		if(triggerEvent == TriggerOperation.AFTER_INSERT){
			for(Account a: newAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
		}
		if(triggerEvent == TriggerOperation.AFTER_UPDATE){
			for(Account a: newAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
			for(Account a: oldAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
		}

		if(triggerEvent == TriggerOperation.AFTER_DELETE){
			for(Account a: oldAccounts){
				sdr_owner_IDs.add(a.SDR_Owner__c);
				account_owner_IDs.add(a.OwnerID);
			}
		}

		System.debug(sdr_owner_IDs);
		System.debug(account_owner_IDs);


		List<AggregateResult> sdr_prospect_accounts = [SELECT COUNT(ID) sdr_accounts, SDR_Owner__c FROM Account WHERE SDR_Owner__c in :sdr_owner_IDs and (type ='Prospect - Being Worked' OR type='Prospect - Open' ) GROUP BY SDR_Owner__c];
		List<AggregateResult> owner_prospect_accounts = [SELECT COUNT(ID) owner_accounts, OwnerID FROM Account WHERE OwnerID in :account_owner_IDs and (type ='Prospect - Being Worked' OR type='Prospect - Open' ) GROUP BY OwnerID];

		Map<Id, List<Integer>> userID_And_num_of_accounts = new Map<Id, List<Integer>>();

		for(AggregateResult ar: sdr_prospect_accounts){
			// put the id in the list
			userID_And_num_of_accounts.put((ID)ar.get('SDR_Owner__c'), new List<Integer>());

			// add the number of sdr accounts to that IDs map
			userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add((Integer)ar.get('sdr_accounts'));
			userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add(0);
		}

		for(AggregateResult ar: owner_prospect_accounts){

			// if the id already exists
			if(userID_And_num_of_accounts.containsKey((ID)ar.get('OwnerID'))){

				userID_And_num_of_accounts.get((ID)ar.get('OwnerID')).add(1, (Integer)ar.get('owner_accounts'));
			} else {
				userID_And_num_of_accounts.put((ID)ar.get('SDR_Owner__c'), new List<Integer>());

				userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add(0);
				userID_And_num_of_accounts.get((ID)ar.get('SDR_Owner__c')).add((Integer)ar.get('owner_accounts'));
			}
		}

		// now we want to update the users field
		List<ID> user_IDs = new List<ID>();

		for(ID user_ID: userID_And_num_of_accounts.keySet()){
			user_IDs.add(user_ID);
		}

		// now we want to get the actual user object
		List<User> users = [SELECT ID, SDR_Owner_Prospect__c , Account_Owner_Prospect__c FROM User WHERE ID in :user_IDs];


		List<User> users_to_update = new List<User>();
		for(User u: users){
			List<Integer> sdr_and_owner_accounts = userID_And_num_of_accounts.get(u.ID);
			u.SDR_Owner_Prospect__c = sdr_and_owner_accounts[0];
			u.Account_Owner_Prospect__c = sdr_and_owner_accounts[1];
			users_to_update.add(u);
		}

		// update users
		update users_to_update;

	}


}

Line 45 is saying I am out of bounds. Does not make sense.
Hi All,

I have a vf page where i have a field Contact name on case which is a lookup to contact. I want when the user logged in as community user it should autopopulate his/her name in that contact field.

vf-page:
<apex:page standardController="Case" extensions="AutoPopulateExample">
   
    <apex:form id="form">
    	<apex:pageBlock >
          
            <apex:pageBlockButtons location="top">
              <apex:commandButton value="Save" action="{!Save}"/>
              
              <apex:commandButton value="Cancel" action="{!Cancel}"/>
            </apex:pageBlockButtons> 
            <apex:actionRegion >
           <apex:pageBlockSection title="Basic Details" columns="2">
               <apex:inputField label="Contact Name" value="{!Case.ContactId}" >
               	<apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/>
               </apex:inputField>
               <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/>
               <apex:inputField label="Account Name" value="{!Case.AccountId}"/>
               <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/>
               <apex:inputField label="Status" value="{!Case.Status}"/>
               <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/>
               <apex:inputField label="Subject" value="{!Case.Subject}"/>
               <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/>
               <apex:inputField label="Product" value="{!Case.Products__c}"/>
               <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/>
               <apex:inputField label="Components" value="{!Case.Componet__c}"/>
               <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/>
               <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/>
               <apex:inputField label="Environment" value="{!Case.Environment__c}"/>
               <apex:inputField label="Description" value="{!Case.Description__c}"/>
           </apex:pageBlockSection>
            </apex:actionRegion>
            </apex:pageBlock>
       
             <!--<apex:commandButton value="Upload files" action="{!save}" reRender="theSection"/> -->
            <apex:outputPanel id="theSection" rendered="true">
            <apex:pageblock >
                 <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1">
        <div id="upload" class="upload">                                   
            <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/>                            
        </div> 
         </apex:pageBlockSection>      
   		 </apex:pageBlock>
            </apex:outputPanel>       
     </apex:form>
</apex:page>

 
Hi All,

I have tried using the below code to bring through a report table onto a visualforce page but its only showing the head etc and no report on the page.. I know you can easily display a report chart, but this isnt what i am after. I could really do with this or another solution. Hopefully someone can help. 

Code below..
<apex:page standardController="User" sidebar="false" showHeader="false">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <apex:pageBlock>
    <apex:pageBlockSection title="Dealer Logins" id="DealerLogins" columns="1" />
    
    <script language="JavaScript">
    $('[id$="00O1o000004sZc3 "] > .pbSubsection > .detailList').load('/00O1o000004sZc3 table.reportTable.matrixReportTable');
</script>

<style type="text/css">
    [id$="EmbeddedReport"] > .pbSubsection { margin-top:10px; }
    [id$="EmbeddedReport"] > .pbSubsection tr:first-of-type th, 
    [id$="EmbeddedReport"] > .pbSubsection tr:first-of-type td {
      border-top:1px solid #d4dadc!important; }
    [id$="EmbeddedReport"] > .pbSubsection th, 
    [id$="EmbeddedReport"] > .pbSubsection td {
        font-size: 12px; padding:3px 6px 3px 5px; background-color:#fff; border-color:#d4dadc!important; border-bottom:1px solid #d4dadc!important; } 
   [id$="EmbeddedReport"] > .pbSubsection th { background-color:#eee; }
   [id$="EmbeddedReport"] > .pbSubsection .grandTotal { background-color:#d4dadc; }
   [id$="EmbeddedReport"] > .pbSubsection .drilldown { display:none; }
</style>
</apex:pageBlock>

</apex:page>

 
Hi 
I am creating case through vf page where i have to attach attchment to that case while creating that case record but when i hit the save button. I am geeting error as 
"Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
Error is in expression '{!Save}' in component <apex:commandButton> in page newcase_page_for_community: Class.AutoPopulateExample.save: line 64, column 1"
Please let me know if i am doing something wrong.

VF page
<apex:page standardController="Case" extensions="AutoPopulateExample">
   
    <apex:form id="form">
    	<apex:pageBlock >
          
            <apex:pageBlockButtons location="top">
              <apex:commandButton value="Save" action="{!Save}"/>
              <apex:commandButton value="Cancel" action="{!Cancel}"/>
            </apex:pageBlockButtons> 
            
           <apex:pageBlockSection title="Basic Details" columns="2">
               <apex:inputField label="Contact Name" value="{!Case.ContactId}" >
               	<apex:actionSupport event="onchange" action="{!autoCal}" reRender="form"/>
               </apex:inputField>
               <apex:inputField label="Requestor First Name" value="{!Case.Requestor_First_Name__c}"/>
               <apex:inputField label="Account Name" value="{!Case.AccountId}"/>
               <apex:inputField label="Requestor Last Name" value="{!Case.Requestor_Last_Name__c}"/>
               <apex:inputField label="Status" value="{!Case.Status}"/>
               <apex:inputField label="Requestor Email" value="{!Case.Requester_Email__c}"/>
               <apex:inputField label="Subject" value="{!Case.Subject}"/>
               <apex:inputField label="Requestor Contact Number" value="{!Case.Requester_Contact_Number__c}"/>
               <apex:inputField label="Product" value="{!Case.Products__c}"/>
               <apex:inputField label="Business Impact" value="{!Case.Business_Impact__c}"/>
               <apex:inputField label="Components" value="{!Case.Componet__c}"/>
               <apex:inputField label="Business Urgency" value="{!Case.Business_Urgency__c}"/>
               <apex:inputField label="On Behalf of" value="{!Case.On_Behalf_of__c}"/>
               <apex:inputField label="Environment" value="{!Case.Environment__c}"/>
               <apex:inputField label="Description" value="{!Case.Description__c}"/>
           </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
		
        <apex:form >
            <apex:outputPanel id="theSection" rendered="true">
            <apex:pageblock >
                <apex:pageBlockSection title="Uploading the Attachment" collapsible="false" dir="LTR" columns="1">
        <div id="upload" class="upload">                                   
            <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/>                            
        </div> 
         </apex:pageBlockSection>      
   		 </apex:pageBlock>
            </apex:outputPanel>       
     </apex:form>
	 
</apex:page>

Apex Controller :
public class AutoPopulateExample
{
public string fileName{get;set;} 
public Blob fileBody{get;set;}
public Contact con{get;set;}
public Case caseObject{get;set;}
public Attachment attachmentObject  {
  get {
      if (attachmentObject  == null)
        attachmentObject  = new Attachment();
      return attachmentObject ;
    }
  set;
  }
public ApexPages.StandardController stdCntrlr {get; set;}
    
public AutoPopulateExample(ApexPages.StandardController controller)
{
    con = new Contact();
    caseObject = new case();
    caseObject = (Case)controller.getRecord();
    attachmentObject = new Attachment();
}

//function is called from actionsupport event

public void autoCal()
{

Id conid = caseObject.ContactId;     // collecting contact id from visualforce page
List<Contact> conLst = [select id,AccountId,FirstName,LastName,Email,Phone from contact where id=:conid];
if(conLst.isEmpty())
{
 return;
}    
caseObject.Requestor_First_Name__c = conLst[0].FirstName;      
caseObject.AccountId = conLst[0].AccountId; 
caseObject.Requestor_Last_Name__c = conLst[0].LastName;
caseObject.Requester_Email__c = conLst[0].Email; 
caseObject.Requester_Contact_Number__c = conLst[0].Phone; 
}

public PageReference save()
{
        // Save the Case
        insert caseObject;

        // Save the Attachment using the Case id as the parent Id
        System.debug('@@@@@fileBody'+fileBody);     
        attachmentObject = new Attachment();
              Integer i=0;
              attachmentObject .clear();
              attachmentObject.Body = fileBody; 
              attachmentObject.Name = 'Logo_'+caseObject.id+'.jpeg' ; 
              attachmentObject.ParentId = caseObject.id;             
              insert attachmentObject;                 
        pagereference pr = new pagereference('/'+caseObject.id);                           
        return pr;
}
}

Please suggest.
Hi,
 
[{"Name": "US-0000314","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000312","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000315","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000318","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000313","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000317","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000320","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000316","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000322","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000319","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000321","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000324","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000328","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000335","Project":"TestPOC","Release":"Feb-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000337","Project":"TestPOC","Release":"Feb-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000329","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000330","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000336","Project":"TestPOC","Release":"Feb-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000332","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000331","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000334","Project":"TestPOC","Release":"Feb-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000333","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000342","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000344","Project":"TestPOC","Release":"Dec-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000345","Project":"TestPOC","Release":"Feb-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"},{"Name": "US-0000343","Project":"TestPOC","Release":"Feb-GGGG","Username":"AAA.g@ccc.com","Useremail":"AAA.g@BBB.com"}]

I want display the above JSON in below table format in Visualforce page. Please help me.

User-added image
Thanks and Regards,
Diwakar G

SUM OF 1) Make two number fields on Opportunity object
Amount_X
Amount_Y

2) Make one picklist field "Type" , values ('Positive', 'Negative')

3) Make two number fields on account
Rollup_Amount_X
Rollup_Amount_Y
Rollup_Amount

4) Make one trigger on Opportunity object, which will do following:
--> Sum all child of Opportunity's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive"
--> Sum all child of Opportunity's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative"
--> Sum all child of Opportunity's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"

5) Make trigg
global class DailyLeadProcessor implements Schedulable{    
global void execute(SchedulableContext ctx){        
List<lead> newLead=new List<Lead>([Select Id,LeadSource from Lead where LeadSource!=null ]) ;        
if(!newLead.isEmpty()!=null){            
for(Lead l:newLead){                
l.LeadSource='Dreamforce';          
  }        
}    

}
}