• Ashish Dev 3
  • NEWBIE
  • 35 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 11
    Replies
Hi everyone, 

I am newbie in apex, then I am having a trouble with function aggregate result,
I have created apex class below : 
public class AdvanceRequestClass 
{
    /*public static void isActiveValidation(Advance_Request__c[] AdvRequest)
    {
        for(Advance_Request__c adv : AdvRequest)
        {
            if(adv.Is_Active__c == false)
            {
                adv.addError('You cannot update or delete this advance request, it has been used in expense request.');
            }
        }
        
    }*/
	
	List<Work__c> works ;
  Utilities util;
  public AdvanceRequestClass(List<Advance_Request__c> triggerNew, List<Advance_Request__c> triggerOld, Boolean deleteFlag){
    Set<String> InvoiceId = new Set<String>();
        Set<String> WorkIds = new Set<String>();
        List<Advance_Request__c> AdvanceRequest;
        if(deleteFlag){
          AdvanceRequest = triggerOld;
        }else{
          AdvanceRequest = triggerNew;
        }
        for (Advance_Request__c advanceReq: AdvanceRequest) 
        {           
            WorkIds.add(advanceReq.Work_Id__c);
        }
        works = new List<Work__c>([SELECT Id, Name, Total_Invoice_Amount__c,  Project_Code__c, BAST_Submit_Term_I__c, Work_Status__c, Invoice_Date_Term_I__c, Invoice_Date_Term_II__c, Invoice_Date_DP_II__c, Invoice_Date_DP_III__c FROM Work__c WHERE Id in :WorkIds]);
    util = new Utilities();
    
  }
  
	
	
	
}
 
 public void setWorkAmount(List<Advance_Request__c> AdvanceRequest){
    system.debug('works --------------'+ works);
    AggregateResult[] advReq = 
                [select Work_Id__c, SUM(Converted_Amount__c)totalAdvance FROM Advance_Request__c    
                 where Work_Id__c IN :works AND Status__c != 'Rejected' GROUP BY Work_Id__c];
                 system.debug('advReq ---------'+advReq +'------');
        Map<Id, AggregateResult> advMap = new Map <Id, AggregateResult>();
        for(AggregateResult ar : advReq){
            advMap.put((Id)ar.get('Work_Id__c'), ar);
        }
    
        //List <Work__c> workList = [SELECT Id, Name, Total_Advance_Request__c FROM Work__c WHERE Id IN :workIdSet  ];
        
        for(Work__c wid : works ){
          if(advMap.get(wid.Id) != null){
              AggregateResult ar = advMap.get(wid.Id);
              wid.Total_Advance_Request__c = (Decimal)ar.get('totalAdvance');
            }
        }
        
        
  }

then I get error : Error: Compile Error: unexpected token: public at line 40 column 1


could you please help me?

Thanks in advance.
I have formula(text) field in Contact which return text, i want its value in Email field on Opportunity object.
I have tried by workflow rule and field update, but it is not working.
Hi,

I have been working on approval process....................
I have 3 fields in loan object.....1. asst manager 2. senior manager 3. regional manager 
Based on the managers i need to pull dynamically in approval process for every loan record.
  • October 19, 2015
  • Like
  • 0
 
how can i implement a custom encryption blowfish algorithm (apart from inbuilt feature providved by sfdc) on a visualforce page by make the use of apex class and custom controller.

The functionality of this page should be like this:- I enter the object details on visualforce page in plain text and it will store the data in cipher text on object detail page.
I have my own app integrated with salesforce org, I maintain all my Contacts on my app. I want to know the best way to pull only the records that are recently updated in my org, so that I can make a callout from my app to only those records which are recently updated.
 In this way I can keep the Contacts updated on my app. It should not call all the Contacts while this process.
Thanks
Hi everyone, 

I am newbie in apex, then I am having a trouble with function aggregate result,
I have created apex class below : 
public class AdvanceRequestClass 
{
    /*public static void isActiveValidation(Advance_Request__c[] AdvRequest)
    {
        for(Advance_Request__c adv : AdvRequest)
        {
            if(adv.Is_Active__c == false)
            {
                adv.addError('You cannot update or delete this advance request, it has been used in expense request.');
            }
        }
        
    }*/
	
	List<Work__c> works ;
  Utilities util;
  public AdvanceRequestClass(List<Advance_Request__c> triggerNew, List<Advance_Request__c> triggerOld, Boolean deleteFlag){
    Set<String> InvoiceId = new Set<String>();
        Set<String> WorkIds = new Set<String>();
        List<Advance_Request__c> AdvanceRequest;
        if(deleteFlag){
          AdvanceRequest = triggerOld;
        }else{
          AdvanceRequest = triggerNew;
        }
        for (Advance_Request__c advanceReq: AdvanceRequest) 
        {           
            WorkIds.add(advanceReq.Work_Id__c);
        }
        works = new List<Work__c>([SELECT Id, Name, Total_Invoice_Amount__c,  Project_Code__c, BAST_Submit_Term_I__c, Work_Status__c, Invoice_Date_Term_I__c, Invoice_Date_Term_II__c, Invoice_Date_DP_II__c, Invoice_Date_DP_III__c FROM Work__c WHERE Id in :WorkIds]);
    util = new Utilities();
    
  }
  
	
	
	
}
 
 public void setWorkAmount(List<Advance_Request__c> AdvanceRequest){
    system.debug('works --------------'+ works);
    AggregateResult[] advReq = 
                [select Work_Id__c, SUM(Converted_Amount__c)totalAdvance FROM Advance_Request__c    
                 where Work_Id__c IN :works AND Status__c != 'Rejected' GROUP BY Work_Id__c];
                 system.debug('advReq ---------'+advReq +'------');
        Map<Id, AggregateResult> advMap = new Map <Id, AggregateResult>();
        for(AggregateResult ar : advReq){
            advMap.put((Id)ar.get('Work_Id__c'), ar);
        }
    
        //List <Work__c> workList = [SELECT Id, Name, Total_Advance_Request__c FROM Work__c WHERE Id IN :workIdSet  ];
        
        for(Work__c wid : works ){
          if(advMap.get(wid.Id) != null){
              AggregateResult ar = advMap.get(wid.Id);
              wid.Total_Advance_Request__c = (Decimal)ar.get('totalAdvance');
            }
        }
        
        
  }

then I get error : Error: Compile Error: unexpected token: public at line 40 column 1


could you please help me?

Thanks in advance.
Greetings, I've been working with Jeff Douglas' Roll Your Salesforce Lookup (http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/) as part of an app I've been building in our org. This app serves to replace the dreaded quickcreate system and allows for the inline creation of contact records, should they not be available.

One of the initial issue we have encountered is the inability to look up or add contact records with quotes (') in their first or last name as part of the query. This returns an exception error. A step I took to address was to escapesinglequote, which allows for looking up contacts with ('). Now with Single Quote escaped, I am unable to close the popup when I create new records or select a record with a (') in the result. I'm certain this may have to do with the code in the VF page. I am wondering what steps I need to take.

Are there any steps, I can take to address. Class and Page attached below.

Class
public class ContactLookupControl {

  public Contact contact {get;set;} // new contact to create
  public List<Contact> results{get;set;} // search results
  public string searchString{get;set;} // search keyword

  public ContactLookupControl() {
    contact = new Contact();
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    runSearch();  
  }

  // performs the keyword search
  public PageReference search() {
    runSearch();
    return null;
  }

  // prepare the query and issue the search command
  private void runSearch() {
    // TODO prepare query string for complex serarches & prevent injections
    results = performSearch(searchString);               
  } 

  // run the search and return the records found. 
  private List<Contact> performSearch(string searchString) {

    String soql = 'select id, name,account.Name,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Phone,Email from contact';
    if(searchString != '' && searchString != null)
      soql = soql +  ' where name LIKE \'%' + searchString +'%\'';
    soql = soql + ' limit 25';
    System.debug(soql);
    return database.query(soql); 

  }

  // save the new contact record
  public PageReference saveContact() {
    insert contact;
    contact=[select id,name,FirstName,LastName,AccountId,MailingStreet,MailingCity,MailingState,MailingPostalCode,MailingCountry,Phone,Email from contact where id=:contact.id];
    // reset the contact
    //contact = new Contact();
    return null;
  }

  // used by the visualforce page to send the link to the right dom element
  public string getFormTag() {
    return System.currentPageReference().getParameters().get('frm');
  }

  // used by the visualforce page to send the link to the right dom element for the text box
  public string getTextBox() {
    return System.currentPageReference().getParameters().get('txt');
  }
  }




Page
<apex:page controller="ContactLookupControl"
  title="Search"
  showHeader="false"
  sideBar="false"
  tabStyle="Contact"
  id="pg">
  <apex:form >
  <apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
  <apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel">
    <!-- SEARCH TAB -->
      <apex:tab label="Search" name="tab1" id="tabOne"> 
      <apex:actionRegion > 
      <apex:outputPanel id="top" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
        <apex:outputLabel value="Search" style="font-weight:Bold;padding-right:10px;" for="txtSearch"/>
        <apex:inputText id="txtSearch" value="{!searchString}" />
          <span style="padding-left:5px"><apex:commandButton id="btnGo" value="Go" action="{!Search}" rerender="searchResults"></apex:commandButton></span>
      </apex:outputPanel>
   
       <apex:outputPanel id="pnlSearchResults" style="margin:10px;height:350px;overflow-Y:auto;" layout="block">
        <apex:pageBlock id="searchResults">
          <apex:pageBlockTable value="{!results}" var="a" id="tblResults">
            <apex:column >
              <apex:facet name="header">
                <apex:outputPanel >Name</apex:outputPanel>
              </apex:facet>
               <apex:outputLink value="javascript:top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!a.Id}','{!a.Name}', false);self.close();" rendered="{!NOT(ISNULL(a.Id))}">{!a.Name}</apex:outputLink>    
            </apex:column>
        <apex:column >
              <apex:facet name="header">
                <apex:outputPanel >Account Name</apex:outputPanel>
              </apex:facet>
               {!a.Account.Name}   
            </apex:column>
        <apex:column >
              <apex:facet name="header">
                <apex:outputPanel >Street</apex:outputPanel>
              </apex:facet>
               {!a.MailingStreet}   
            </apex:column>
  <apex:column >
              <apex:facet name="header">
                <apex:outputPanel >City</apex:outputPanel>
              </apex:facet>
               {!a.MailingCity}   
            </apex:column>
 <apex:column >
              <apex:facet name="header">
                <apex:outputPanel >State</apex:outputPanel>
              </apex:facet>
               {!a.MailingState}   
            </apex:column>
 <apex:column >
              <apex:facet name="header">
                <apex:outputPanel >Postal Code</apex:outputPanel>
              </apex:facet>
               {!a.MailingPostalCode}   
            </apex:column>
<apex:column >
              <apex:facet name="header">
                <apex:outputPanel >Phone</apex:outputPanel>
              </apex:facet>
               {!a.Phone}   
            </apex:column>
<apex:column >
              <apex:facet name="header">
                <apex:outputPanel >Email</apex:outputPanel>
              </apex:facet>
               {!a.Email}   
            </apex:column>
          </apex:pageBlockTable>
        </apex:pageBlock>
       </apex:outputPanel>
      </apex:actionRegion>
    </apex:tab>
    <!-- NEW CONTACT TAB -->
    <apex:tab label="New Contact" name="tab2" id="tabTwo">
        <apex:pageBlock id="newContact" title="New Contact" >
          <apex:pageBlockButtons >
            <apex:commandButton action="{!saveContact}" value="Save & Close"/>
          </apex:pageBlockButtons>
          <apex:pageMessages />
          <apex:pageBlockSection columns="2">
              <apex:inputField value="{!Contact.FirstName}"/>
              <apex:inputField value="{!Contact.LastName}"/>
              <apex:inputField value="{!Contact.AccountId}"/>
              <apex:inputField value="{!Contact.MailingStreet}"/>
              <apex:inputField value="{!Contact.MailingCity}"/>
              <apex:inputField value="{!Contact.MailingState}"/>
           <apex:inputField value="{!Contact.MailingPostalCode}"/>
           <apex:inputField value="{!Contact.MailingCountry}"/>
           <apex:inputField value="{!Contact.Phone}"/>
           <apex:inputField value="{!Contact.Email}"/>
          </apex:pageBlockSection>
        </apex:pageBlock>   
        <script>
        if({!Contact.id!=null}){
            //alert('{!Contact.Name} {!Contact.id}');
            top.window.opener.lookupPick2('{!FormTag}','{!TextBox}_lkid','{!TextBox}','{!Contact.Id}','{!Contact.Name}', false);self.close();
        }
        </script>
    </apex:tab>
  </apex:tabPanel>
  </apex:outputPanel>
  </apex:form>
</apex:page>

Hope it helps.
Hi all,

I made some changes to Apex class code and all tests come back without a failure. However, when I try to deploy and run the validation, I still get below 75% coverege but there is no explanation. Does anyone know how to resolve this?

Deployment Validation Error

Thanks
Nitzan
In the class i am accessing the parent record attribute with __r in the select query in child query like below .
Childrecord__c child = [ select Parentobj__r.Account__c  from childobject__c where name ='Test' limit 1 ];
if(child.Parentobj__r.Account__c != null)
{
do something();
}
In test class i have created parent and child record ,
but value of Parentobj__r.Account__c  always giving  null value while debug please help here ,
 
is there any way to create fields from apex. if yes how?
 
There’ve been cases when particular task is deleted by someone by mistake (no data would be available in these cases about who deleted it, but the result is – lack of task). Is there a way to prevent a tasks from being deleted or somehow to create a restriction so that no task could be deleted after creation?

Regards,

Dilyan
When task is created and assigned to a particular person/assignee the task is visible to one person only with no option other people to see and to be notified of the existence of the task. This creates a concern in cases when the recipient is not in the office, the task may not be seen on time and handled by the person who substitutes the recipient. Is there a way to notify more than one person when task is created, for example to add an additional CC field and include more people similar to the way it is done in the mail clients - Microsoft Outlook for example?

Regards,

Dilyan