• mustafatop
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 9
    Replies

I have created a batchable class for a production system. If following code doesn't work, any code does not work.

The code is in production system now. It takes daily exchange rates from a site everyday and creates Currency__c records. If it works when exchange rates haven't published, it takes last day exchange rates. But it does not work the way I want and I would like to test it at debug logs.

Following method "getXML(Date today)" has never invoked when I viewed debug logs. Therefore System.debug('test: ' + result); has also never invoked.

How can I see this log?


public String getXML(Date today){  
    counter += 1;       
    if(counter == 11) return '';
    try{
        Http h = new Http();
        HttpRequest req = new HttpRequest();       

        String m = today.month() + '';
        if((today.month()+'').length()==1) m = '0' + today.month();
        String d = today.day() + '';
        if((today.day()+'').length()==1) d = '0' + today.day();
        String donem = today.year() + '' + m;
        String formattedDate = d + '' + m + today.year();

        req.setEndpoint('http://www.tcmb.gov.tr/kurlar/' + donem + '/' + formattedDate + '.xml'); 
        req.setMethod('GET');            
        String result = '';
        if (!Test.isRunningTest()){
            HttpResponse res = h.send(req);
            result = res.getBody();
        }
        else {
            result += 'test';
        }         
        System.debug('test: ' + result);
        if(res.getStatusCode()==404){
            return getXML(today.addDays(-1));
        }   
        return result;
    }catch(Exception e){
        return getXML(today);
    }
}

 

Following url takes away to a lookup page that is returning all contact records.

https://c.cs7.visual.force.com/_ui/common/data/LookupPage?lkfm=j_id0:j_id2&lknm=j_id0:j_id2:j_id30:who&lktp=001&lksrch=

 

I want to restrict returned contact records in lookup page. Is there a query parameter like lkqry=SELECT FirstName FROM Contact WHERE id='012345678912345'

I need to AJAX toolkit for call apex method.  But disrupt to work updateInput(t) and other all function when I add first two line to vf code. How can I solve this problem?

 

    <apex:includeScript value="/soap/ajax/27.0/connection.js"/>
    <apex:includeScript value="/soap/ajax/27.0/apex.js"/>
    <script>
        function updateInput(t){
            var a = 72;
            for(var i=0;i<10;i++)
                document.getElementById("j_id0:j_id2:j_id30:j_id" + (a + i*25)).value = t.value;
        function setId(id){
            var name = sforce.apex.execute("AddMultipleEvent","getAccountShortName", {projectId:id}); 
            var a = 51;
            for(var i=0;i<10;i++)
                document.getElementById("j_id0:j_id2:j_id30:j_id" + (a + i*25)).value = name;
        }
    </script>

 

l get syntax error following line,
<apex:selectlist value="{!IF({!counter}={!1},{!selectedItem},{!selectedItem2})}" size="1">

 

How to use this formula functions in apex tags?

<apex:variable var="counter" value="{!1}"/>          
                <apex:repeat value="{!events}" var="itr"> 
                    <br/><br/>     
                    
                    <table>            
                        <tr>
                            <td><apex:OutputText value="{!counter}"/></td>        
                            <td><apex:inputfield value="{!itr.Subject}" id="subject"/></td><td>
                            <apex:inputfield value="{!itr.IsAllDayEvent}" id="day"/></td><td>
                            <apex:inputfield value="{!itr.StartDateTime}" id="start"/></td><td>
                            <apex:selectlist value="{!IF({!counter}={!1},{!selectedItem},{!selectedItem2})}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.EndDateTime}" id="end"/></td><td>
                            <apex:selectlist value="{!SelectedItem2}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.Status__c}" id="status" /></td><td>
                            <apex:inputField value="{!itr.Type__c}" id="type"/></td><td>
                            <apex:inputField value="{!itr.Consultancy_Duration__c}" id="duration"/></td><td>
                            <apex:inputField value="{!itr.Project_Phase__c}" id="phase"/></td><td>
                            <apex:inputField value="{!itr.Location}" id="location"/></td><td>
                            <apex:inputField value="{!itr.Description}" id="description"/></td>
                        </tr>    
                    </table>
                    <apex:variable var="counter" value="{!counter+1}"/>                     
               </apex:repeat>

 

s and s2 variables don't set selected value that is come from piclist in vf page when I use apex:selectlist tag in apex:repeat tag. So s and s2 are always '09:00'. When I remove apex:repeat tag, the problem is solved. But I need it.

 

How to solve this problem without save button into apex:repeat tag?

 

 A piece of the the my code is following.

     String s = '09:00';
     String s2 = '09:00';
     
     public String getSelectedItem(){
          return s;
     }
     public void setSelectedItem(String s){
         this.s = s;
     }
     
     public String getSelectedItem2(){
          return s2;
     }
     public void setSelectedItem2(String s2){
         this.s2 = s2;
     }

     public List<SelectOption> getItems(){
            List<SelectOption> options = new list<SelectOption>();
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;
   
                options.add(new SelectOption(key, key));
            }
            return options;      
     }
 

 

                <apex:repeat value="{!events}" var="itr">
                    <br/><br/>     
                    
                    <table>            
                        <tr>        
                            <td><apex:inputfield value="{!itr.Subject}" id="subject"/></td><td>
                            <apex:inputfield value="{!itr.IsAllDayEvent}" id="day"/></td><td>
                            <apex:inputfield value="{!itr.StartDateTime}" id="start"/></td><td>
                            <apex:selectlist value="{!SelectedItem}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.EndDateTime}" id="end"/></td><td>
                            <apex:selectlist value="{!SelectedItem2}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.Status__c}" id="status" /></td><td>
                            <apex:inputField value="{!itr.Type__c}" id="type"/></td><td>
                            <apex:inputField value="{!itr.Consultancy_Duration__c}" id="duration"/></td><td>
                            <apex:inputField value="{!itr.Project_Phase__c}" id="phase"/></td><td>
                            <apex:inputField value="{!itr.Location}" id="location"/></td><td>
                            <apex:inputField value="{!itr.Description}" id="description"/></td>
                        </tr>    
                    </table>
                                         
               </apex:repeat>
                                
                   <br/><br/>
                
                <p align="center"><apex:commandButton action="{!save}" value=" Save " /></p>

 

I'm working on a job for entering multiple event records. I have used event standard field in my vf page but already exist validation rules haven't worked. Therefore I have created validation rules manually before insert process in save() method. And as a result, I can not create test method for validation rules in save() method.

 

How can I test save() method in following apex code?

<apex:page standardController="Event" extensions="AddMultipleEvent">
    <apex:form >
        <apex:outputPanel id="eventPage">
            <apex:pageMessages />
            <apex:pageBlock mode="edit">
                <apex:pageBlockSection title="SECTION1"/>
                
                <apex:repeat value="{!events2}" var="itr">                   
                    Assign To: <apex:inputField value="{!itr.OwnerId}"/>
                    Related To: <apex:inputField value="{!itr.WhatId}"/>
                    Name: <apex:inputField value="{!itr.WhoId}"/>
                </apex:repeat>

               <apex:pageBlockSection title="SECTION2"/>
                  <p align="center"><apex:commandButton action="{!save}" value=" Save " /></p>
                 
                          
                <apex:repeat value="{!events}" var="itr"> 
                    <br/><br/>     
                    
                    <table>            
                        <tr>        
                            <td><apex:inputfield value="{!itr.Subject}" id="subject"/></td><td>
                            <apex:inputfield value="{!itr.IsAllDayEvent}" id="day"/></td><td>
                            <apex:inputfield value="{!itr.StartDateTime}" id="start"/></td><td>
                            <apex:selectlist value="{!SelectedItem}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.EndDateTime}" id="end"/></td><td>
                            <apex:selectlist value="{!SelectedItem2}" size="1">
                                <apex:selectOptions value="{!Items2}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.Status__c}" id="status" /></td><td>
                            <apex:inputField value="{!itr.Type__c}" id="type"/></td><td>
                            <apex:inputField value="{!itr.Consultancy_Duration__c}" id="duration"/></td><td>
                            <apex:inputField value="{!itr.Project_Phase__c}" id="phase"/></td><td>
                            <apex:inputField value="{!itr.Location}" id="location"/></td><td>
                            <apex:inputField value="{!itr.Description}" id="description"/></td>
                        </tr>    
                    </table>
                                         
               </apex:repeat>
                                
                   <br/><br/>
                
                <p align="center"><apex:commandButton action="{!save}" value=" Save " /></p>
            </apex:pageBlock>

        </apex:outputPanel>

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

 

public class AddMultipleEvent{

    public List<Event> events{get; set;}
    
    public List<Event> events2{get; set;}
 
    public AddMultipleEvent(ApexPages.StandardController myController) {
        events2 = new List<Event>();
        events2.add(new Event());
        Integer i = 10;
        
        events = new List<Event>();
        for(Integer j=0; j<i; j+=1){
//            if(Test.isRunningTest()) events.add(new Event(startdatetime = datetime.now(),enddatetime = datetime.now()));
            events.add(new Event());
        }
    
    }
   
    public Datetime sDate(Integer i){
        Integer day = events.get(i).startdatetime.day();
        Integer month = events.get(i).startdatetime.month();
        Integer year = events.get(i).startdatetime.year();
        
        String[] s = getSelectedItem().split(':',2);
        Datetime dt = datetime.newInstance(year, month, day, Integer.valueOf(s[0]), Integer.valueOf(s[1]),0);
        return dt;
    }
    
    public Datetime eDate(Integer i){
        Integer day = events.get(i).enddatetime.day();
        Integer month = events.get(i).enddatetime.month();
        Integer year = events.get(i).enddatetime.year();
        
        String[] s = getSelectedItem2().split(':',22);
        Datetime dt = datetime.newInstance(year, month, day, Integer.valueOf(s[0]), Integer.valueOf(s[1]),0);
        return dt;
    }
     
    public Boolean C1(Datetime d1, Datetime d2){
        if(!(d1==null && d2==null)) return true; 
        return false;
    } 
    
    public PageReference save() {
        Boolean k = false;
        for(Integer i=0; i<events.size(); i+=1){
            if(C1(events.get(i).startdatetime, events.get(i).enddatetime)){
                k = true;
            }
            
        }
        if(!k){
            events.get(0).startdatetime.addError('Please enter a record');
            events.get(0).enddatetime.addError('Please enter a record');
            return null;
        }
        
        for(Integer i=0; i<events.size(); i+=1){
            events.get(i).ownerId = events2.get(0).ownerId;
            events.get(i).whatId= events2.get(0).whatId;
            events.get(i).whoId = events2.get(0).whoId ;
            
            if(events.get(i).startdatetime!=null)
                events.get(i).startdatetime= sDate(i);
            if(events.get(i).enddatetime!=null)
                events.get(i).enddatetime= eDate(i);
            
        }
        Boolean b = false;
        for(Integer i=0; i<events.size(); i+=1){
            if((events.get(i).Type__c+'')=='CB-Client Billable' || (events.get(i).Type__c+'').equals('CN-Client Non-Billable')){
               if(!(events.get(i).whatId+'').subString(0,3).equals('a0S')){
                    events.get(i).whatId.addError((i+1) + '.ROW: You cannot enter a site visit without a Project. Please link your site visit to a Project or contact with your manager.');
                    b = true;
               }
               if(events.get(i).whatId==null){
                    events.get(i).whatId.addError((i+1) + '.ROW: Site Visits should be related with a Project, Contract or Opportunity.');
                    b = true;
               }
            }
            if(events.get(i).subject==null){
                 events.get(i).subject.addError((i+1) + '.ROW: You must enter a value');
                 b = true;
            }
            if(events.get(i).startdatetime==null && events.get(i).enddatetime!=null){
                events.get(i).startdatetime.addError((i+1) + '.ROW: Please enter a start date');              
                return null;
            }
            if(events.get(i).startdatetime!=null && events.get(i).enddatetime==null){
                events.get(i).enddatetime.addError((i+1) + '.ROW: Please enter a end date');
                return null;
            }
        }
        
        if(b) return null;
        
        for(Integer i=0; i<events.size(); i+=1){
            if(events.get(i).startdatetime==null || events.get(i).enddatetime==null){
                events.remove(i);
                i = 0;
            }
        }
                
        insert events;     
        return new PageReference ('/00U/l');
     }
    
                
     String s = '09.00';
     String s2 = '09.00';
     
     public String getSelectedItem(){
          return s;
     }
     public void setSelectedItem(String s){
         this.s = s;
     }
     
     public String getSelectedItem2(){
          return s2;
     }
     public void setSelectedItem2(String s2){
         this.s2 = s2;
     }

     public List<SelectOption> getItems(){
            List<SelectOption> options = new list<SelectOption>();
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;
   
                options.add(new SelectOption(key, key));
            }
            return options; 
                  
     }
     public List<SelectOption> getItems2(){
            List<SelectOption> options = new list<SelectOption>();
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;
   
                options.add(new SelectOption(key, key));
            }
            return options; 
                  
     }
 
     public static testMethod void myTest(){
         AddMultipleEvent a = new AddMultipleEvent(null);
         System.assertEquals(a.save(),null);
         System.assertEquals(a.C1(Datetime.now(),Datetime.now()),true);
       
         System.assertEquals(a.getItems().get(0).getValue(),'00:00');
         System.assertEquals(a.getItems2().get(0).getValue(),'00:00');
         System.assertEquals(a.getSelectedItem(),'09.00');
         System.assertEquals(a.getSelectedItem2(),'09.00');
         a.setSelectedItem('00:00');
         a.setSelectedItem2('00:00');
         System.assertEquals(a.getSelectedItem(),'00:00');
         System.assertEquals(a.getSelectedItem2(),'00:00');
  //       System.assertEquals(a.sDate(Datetime.newInstance(2012,2,2)),'00:00');
         
         Event event = new Event(startdatetime = datetime.now(),enddatetime = datetime.now());
         PageReference pref = Page.addmultipleevent;
         pref.getParameters().put('id',event.id);
         Test.setCurrentPage(pref);
         
         
         ApexPages.StandardController con = new ApexPages.StandardController(event);
         AddMultipleEvent ade = new AddMultipleEvent(con);
         
     
         
    } 
   
    
}

 

I have used toPdf() method of Blob object in an apex class, that is triggered with a custom button for pdf file is attached to Account record.

Some css style features as style="border-top-style:dotted;", style="font-family: Arial Unicode MS;" are not display in pdf file. This style features are working in apex page that using renderAs="pdf" attribute. But it isn't work when pdfContent variable is used as parameter by toPdf() method.

Can somebody help me?

 

global class AccountPDFGenerator{
    
    webservice static void generateInvoicePDF(String accountId){
//        Account account = [SELECT Id,Name FROM Account WHERE Id=:accountId];
        
        String accId = accountId;
        
        String pdfContent = '';
        try
        {                       
           pdfContent +=   '<html>' +
                                '<body>' +
                                    '<p align="left" style="font-family: Arial Unicode MS;">öçşığü</p>' + 
                                    '<br/><br/>' +
                                    '<table>' +                     
                                        '<tr>' +
                                           '<td align="center" style="border-top-style:dotted; border-bottom-style:dotted;">ÖÇŞİĞÜ</td>' +
                                        '</tr>' +                                        
                                    '</table>' +
                                '</body>' +
                            '</html>';
        }catch(Exception e)
        {
            pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
        }
        
        Attachment attachmentPDF = new Attachment();
        attachmentPDF.parentId = accId;
        attachmentPDF.Name = 'Invoice.pdf';
        attachmentPDF.body = Blob.toPDF(pdfContent);
        insert attachmentPDF; 
    }
}

 This is javascript code of custom button.

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
sforce.apex.execute("AccountPDFGenerator","generateInvoicePDF", {accountId:"{!Account.Id}

I have used toPdf() method of Blob object in an apex class that is triggered with a custom button for attach pdf document to a custom object. But pdf content can not be displayed Turkish character and also can not be use some property of css. For example:

style="border-left-style:dotted;"

 I have used following apex code:

global class AccountPDFGenerator
{
    webservice static void generateInvoicePDF(String accountId)
    {
//        Account account = [SELECT Id,Name FROM Account WHERE Id=:accountId];
        
        String accId = accountId;
        
        String pdfContent = '';
        try
        {
            pdfContent = '<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></meta></head><body>';           
            pdfContent = pdfContent + '<p style="color:red">' + 'öçşğüıÖÇŞĞÜİ' + '</p>';
pdfContent +=  '<table>' +                     
                                        '<tr>' +
                                           '<td align="center" style="border-top-style:dotted; border-bottom-style:dotted;">aaaaaaaa</td></tr></table>' + 
            pdfContent = pdfContent + '</body></html>';
        }catch(Exception e)
        {
            pdfContent = pdfContent + '<P>THERE WAS AN ERROR GENERATING PDF: ' + e.getMessage() + '</P>';
        }
 //       pdfContent = 'öçşğüıÖÇŞĞÜİ'; 
        
        Attachment attachmentPDF = new Attachment();
        attachmentPDF.parentId = accId;
        attachmentPDF.Name = 'Invoice.pdf';
//        attachmentPDF.body= Blob.valueOf(pdfContent);
        attachmentPDF.body = Blob.toPDF(pdfContent); //This creates the PDF content
        insert attachmentPDF;
      
    }
 
    
}

 And this is javascript code of custom button:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
sforce.apex.execute("AccountPDFGenerator","generateInvoicePDF", {accountId:"{!Account.Id}"});
window.alert("pdf created" );
document.location.reload(true);
 

 
Created of pdf file after clicking the custom button doesn't contain some character and some html feature as I mentioned. Output of the pdf document is öçüÖÇÜ for following line:

pdfContent = pdfContent + '<p style="color:red">' + 'öçşğüıÖÇŞĞÜİ' + '</p>';

 

 Do you have an any idea, can you help urgently?

 

Locationbox is an external system that services like google maps. I want to deploy it to sf. You can review an example here;

http://www.locationbox.com.tr/web/demo/displaymap.jsp

 

First script tag retrieves javascript code from locationbox service. After working startup(), it sets a dynamic content to <div id='map'...> in document. There are several png images in the dynamic content. The code below works locally as html files but it doesn't work in apex page. (the function x() works as expected.)

 

 I am using the following code in apex page.

 

<script language="Javascript" src="http://www.locationbox.com.tr/locationbox/services?Key=mykey&Cmd=API&Typ=JS"
<script language="JavaScript">
  var mapper  = new IMapper();
 

  window.addEventListener('load', function() {alert('OK1'); x();}, false);

  window.addEventListener('load', function() {alert('OK1'); startup();}, false);

  function startup() {
    mapper.initMap(41.1, 29.1, 7);
    mapper.addNavigationPanel();
    MVGlobalVariables();
    return;
  }
  function x() {
     document.getElementById("map").innerHTML = 2;
  }
 </script>
 <div id="map" style="border: 1px solid black; width:100%; height:100%; z-index: 0; position:relative; -moz-user-select:none;   background-color: lightgrey;" tabindex="0"> 1 </div>

 

 

I am working on some code which sends mail to users who are not logged in the system for a long time. I want to deploy this code to a sf production environment that is including more than 150 users. But I'm getting this error  despite of query returns less than 100 users.  Do you have any idea about this issue?

 

I am using the following code.

 

global class LastLoginReminder implements Database.Batchable<sObject>, Schedulable {

    global Database.QueryLocator start(Database.BatchableContext BC) {
      return !Test.isRunningTest() ? Database.getQueryLocator([SELECT Id, LastLoginDate FROM User
           WHERE IsActive=false AND ((LastLoginDate <:Date.today().addDays(-28) AND LastLoginDate >:Date.today().addDays(-29)) OR
           (LastLoginDate <:Date.today().addDays(-22) AND LastLoginDate >:Date.today().addDays(-23)))]) : Database.getQueryLocator([Select Id,LastLoginDate From User Limit 3]);
    }  
 
   global void execute(Database.BatchableContext BC, list<User> users) {
        Messaging.SingleEmailMessage[] mails = new Messaging.SingleEmailMessage[0];
        for(User u : users) {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setTargetObjectId(u.id);
            mail.setTemplateId(u.LastLoginDate.date().isSameDay(Date.today().addDays(-23)) ? '00Xa0000001Ifne' : '00Xa0000001IfnZ');
            mail.saveAsActivity = false;
            mails.add(mail);
        }
        Messaging.sendEmail(mails);
    }
    global void finish(Database.BatchableContext BC) {
        system.debug('batch job completed.');
    }
    global void execute(SchedulableContext ctx) {
        LastLoginReminder schedulableJob = new LastLoginReminder();
        Database.executebatch(schedulableJob);
    }
    public static testMethod void myTest() {
        Test.StartTest();
        LastLoginReminder schedulableJob = new LastLoginReminder();
        schedulableJob.execute(null);
        Test.stopTest();
    }
}

 

I must make a http request to Shopify in Salesforce. I used following url format as endpoint url for setEndpoint method

HttpRequest req= new HttpRequest(); 
req.setEndpoint('https://apikey:password@hostname/admin/resource.xml'); 
req.setMethod('GET'); 

I get following log:

CALLOUT_RESPONSE|[18]|System.HttpResponse[Status=Unauthorized, StatusCode=401]

And I get return value from body of HttpResponse:

<?xml version="1.0" encoding="UTF-8"?> <hash> <errors>[API] Invalid API key or access token (unrecognized login or wrong password)</errors> </hash>

Also I have tried to following structure but I haven't been succesful.

Blob headerValue = Blob.valueOf(apikey+ ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);

And also following url works properly in any browser

apikey:password@hostname/admin/resource.xml

What should I do for HttpResponse status code be 200.

I need to AJAX toolkit for call apex method.  But disrupt to work updateInput(t) and other all function when I add first two line to vf code. How can I solve this problem?

 

    <apex:includeScript value="/soap/ajax/27.0/connection.js"/>
    <apex:includeScript value="/soap/ajax/27.0/apex.js"/>
    <script>
        function updateInput(t){
            var a = 72;
            for(var i=0;i<10;i++)
                document.getElementById("j_id0:j_id2:j_id30:j_id" + (a + i*25)).value = t.value;
        function setId(id){
            var name = sforce.apex.execute("AddMultipleEvent","getAccountShortName", {projectId:id}); 
            var a = 51;
            for(var i=0;i<10;i++)
                document.getElementById("j_id0:j_id2:j_id30:j_id" + (a + i*25)).value = name;
        }
    </script>

 

l get syntax error following line,
<apex:selectlist value="{!IF({!counter}={!1},{!selectedItem},{!selectedItem2})}" size="1">

 

How to use this formula functions in apex tags?

<apex:variable var="counter" value="{!1}"/>          
                <apex:repeat value="{!events}" var="itr"> 
                    <br/><br/>     
                    
                    <table>            
                        <tr>
                            <td><apex:OutputText value="{!counter}"/></td>        
                            <td><apex:inputfield value="{!itr.Subject}" id="subject"/></td><td>
                            <apex:inputfield value="{!itr.IsAllDayEvent}" id="day"/></td><td>
                            <apex:inputfield value="{!itr.StartDateTime}" id="start"/></td><td>
                            <apex:selectlist value="{!IF({!counter}={!1},{!selectedItem},{!selectedItem2})}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.EndDateTime}" id="end"/></td><td>
                            <apex:selectlist value="{!SelectedItem2}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.Status__c}" id="status" /></td><td>
                            <apex:inputField value="{!itr.Type__c}" id="type"/></td><td>
                            <apex:inputField value="{!itr.Consultancy_Duration__c}" id="duration"/></td><td>
                            <apex:inputField value="{!itr.Project_Phase__c}" id="phase"/></td><td>
                            <apex:inputField value="{!itr.Location}" id="location"/></td><td>
                            <apex:inputField value="{!itr.Description}" id="description"/></td>
                        </tr>    
                    </table>
                    <apex:variable var="counter" value="{!counter+1}"/>                     
               </apex:repeat>

 

I'm working on a job for entering multiple event records. I have used event standard field in my vf page but already exist validation rules haven't worked. Therefore I have created validation rules manually before insert process in save() method. And as a result, I can not create test method for validation rules in save() method.

 

How can I test save() method in following apex code?

<apex:page standardController="Event" extensions="AddMultipleEvent">
    <apex:form >
        <apex:outputPanel id="eventPage">
            <apex:pageMessages />
            <apex:pageBlock mode="edit">
                <apex:pageBlockSection title="SECTION1"/>
                
                <apex:repeat value="{!events2}" var="itr">                   
                    Assign To: <apex:inputField value="{!itr.OwnerId}"/>
                    Related To: <apex:inputField value="{!itr.WhatId}"/>
                    Name: <apex:inputField value="{!itr.WhoId}"/>
                </apex:repeat>

               <apex:pageBlockSection title="SECTION2"/>
                  <p align="center"><apex:commandButton action="{!save}" value=" Save " /></p>
                 
                          
                <apex:repeat value="{!events}" var="itr"> 
                    <br/><br/>     
                    
                    <table>            
                        <tr>        
                            <td><apex:inputfield value="{!itr.Subject}" id="subject"/></td><td>
                            <apex:inputfield value="{!itr.IsAllDayEvent}" id="day"/></td><td>
                            <apex:inputfield value="{!itr.StartDateTime}" id="start"/></td><td>
                            <apex:selectlist value="{!SelectedItem}" size="1">
                                <apex:selectOptions value="{!Items}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.EndDateTime}" id="end"/></td><td>
                            <apex:selectlist value="{!SelectedItem2}" size="1">
                                <apex:selectOptions value="{!Items2}"/>
                            </apex:selectlist></td><td>
                            <apex:inputfield value="{!itr.Status__c}" id="status" /></td><td>
                            <apex:inputField value="{!itr.Type__c}" id="type"/></td><td>
                            <apex:inputField value="{!itr.Consultancy_Duration__c}" id="duration"/></td><td>
                            <apex:inputField value="{!itr.Project_Phase__c}" id="phase"/></td><td>
                            <apex:inputField value="{!itr.Location}" id="location"/></td><td>
                            <apex:inputField value="{!itr.Description}" id="description"/></td>
                        </tr>    
                    </table>
                                         
               </apex:repeat>
                                
                   <br/><br/>
                
                <p align="center"><apex:commandButton action="{!save}" value=" Save " /></p>
            </apex:pageBlock>

        </apex:outputPanel>

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

 

public class AddMultipleEvent{

    public List<Event> events{get; set;}
    
    public List<Event> events2{get; set;}
 
    public AddMultipleEvent(ApexPages.StandardController myController) {
        events2 = new List<Event>();
        events2.add(new Event());
        Integer i = 10;
        
        events = new List<Event>();
        for(Integer j=0; j<i; j+=1){
//            if(Test.isRunningTest()) events.add(new Event(startdatetime = datetime.now(),enddatetime = datetime.now()));
            events.add(new Event());
        }
    
    }
   
    public Datetime sDate(Integer i){
        Integer day = events.get(i).startdatetime.day();
        Integer month = events.get(i).startdatetime.month();
        Integer year = events.get(i).startdatetime.year();
        
        String[] s = getSelectedItem().split(':',2);
        Datetime dt = datetime.newInstance(year, month, day, Integer.valueOf(s[0]), Integer.valueOf(s[1]),0);
        return dt;
    }
    
    public Datetime eDate(Integer i){
        Integer day = events.get(i).enddatetime.day();
        Integer month = events.get(i).enddatetime.month();
        Integer year = events.get(i).enddatetime.year();
        
        String[] s = getSelectedItem2().split(':',22);
        Datetime dt = datetime.newInstance(year, month, day, Integer.valueOf(s[0]), Integer.valueOf(s[1]),0);
        return dt;
    }
     
    public Boolean C1(Datetime d1, Datetime d2){
        if(!(d1==null && d2==null)) return true; 
        return false;
    } 
    
    public PageReference save() {
        Boolean k = false;
        for(Integer i=0; i<events.size(); i+=1){
            if(C1(events.get(i).startdatetime, events.get(i).enddatetime)){
                k = true;
            }
            
        }
        if(!k){
            events.get(0).startdatetime.addError('Please enter a record');
            events.get(0).enddatetime.addError('Please enter a record');
            return null;
        }
        
        for(Integer i=0; i<events.size(); i+=1){
            events.get(i).ownerId = events2.get(0).ownerId;
            events.get(i).whatId= events2.get(0).whatId;
            events.get(i).whoId = events2.get(0).whoId ;
            
            if(events.get(i).startdatetime!=null)
                events.get(i).startdatetime= sDate(i);
            if(events.get(i).enddatetime!=null)
                events.get(i).enddatetime= eDate(i);
            
        }
        Boolean b = false;
        for(Integer i=0; i<events.size(); i+=1){
            if((events.get(i).Type__c+'')=='CB-Client Billable' || (events.get(i).Type__c+'').equals('CN-Client Non-Billable')){
               if(!(events.get(i).whatId+'').subString(0,3).equals('a0S')){
                    events.get(i).whatId.addError((i+1) + '.ROW: You cannot enter a site visit without a Project. Please link your site visit to a Project or contact with your manager.');
                    b = true;
               }
               if(events.get(i).whatId==null){
                    events.get(i).whatId.addError((i+1) + '.ROW: Site Visits should be related with a Project, Contract or Opportunity.');
                    b = true;
               }
            }
            if(events.get(i).subject==null){
                 events.get(i).subject.addError((i+1) + '.ROW: You must enter a value');
                 b = true;
            }
            if(events.get(i).startdatetime==null && events.get(i).enddatetime!=null){
                events.get(i).startdatetime.addError((i+1) + '.ROW: Please enter a start date');              
                return null;
            }
            if(events.get(i).startdatetime!=null && events.get(i).enddatetime==null){
                events.get(i).enddatetime.addError((i+1) + '.ROW: Please enter a end date');
                return null;
            }
        }
        
        if(b) return null;
        
        for(Integer i=0; i<events.size(); i+=1){
            if(events.get(i).startdatetime==null || events.get(i).enddatetime==null){
                events.remove(i);
                i = 0;
            }
        }
                
        insert events;     
        return new PageReference ('/00U/l');
     }
    
                
     String s = '09.00';
     String s2 = '09.00';
     
     public String getSelectedItem(){
          return s;
     }
     public void setSelectedItem(String s){
         this.s = s;
     }
     
     public String getSelectedItem2(){
          return s2;
     }
     public void setSelectedItem2(String s2){
         this.s2 = s2;
     }

     public List<SelectOption> getItems(){
            List<SelectOption> options = new list<SelectOption>();
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;
   
                options.add(new SelectOption(key, key));
            }
            return options; 
                  
     }
     public List<SelectOption> getItems2(){
            List<SelectOption> options = new list<SelectOption>();
            String mins = '30';
            for (Integer i = 0; i < 48; i++) 
            {
                mins        = (mins == '30') ? '00' : '30';
                Integer hrs = ((i*30) / 60);
                String hr   = (string.valueOf(hrs).length() == 1) ? '0' + string.valueOf(hrs) : string.valueOf(hrs);            

                String key = hr + ':' + mins;
   
                options.add(new SelectOption(key, key));
            }
            return options; 
                  
     }
 
     public static testMethod void myTest(){
         AddMultipleEvent a = new AddMultipleEvent(null);
         System.assertEquals(a.save(),null);
         System.assertEquals(a.C1(Datetime.now(),Datetime.now()),true);
       
         System.assertEquals(a.getItems().get(0).getValue(),'00:00');
         System.assertEquals(a.getItems2().get(0).getValue(),'00:00');
         System.assertEquals(a.getSelectedItem(),'09.00');
         System.assertEquals(a.getSelectedItem2(),'09.00');
         a.setSelectedItem('00:00');
         a.setSelectedItem2('00:00');
         System.assertEquals(a.getSelectedItem(),'00:00');
         System.assertEquals(a.getSelectedItem2(),'00:00');
  //       System.assertEquals(a.sDate(Datetime.newInstance(2012,2,2)),'00:00');
         
         Event event = new Event(startdatetime = datetime.now(),enddatetime = datetime.now());
         PageReference pref = Page.addmultipleevent;
         pref.getParameters().put('id',event.id);
         Test.setCurrentPage(pref);
         
         
         ApexPages.StandardController con = new ApexPages.StandardController(event);
         AddMultipleEvent ade = new AddMultipleEvent(con);
         
     
         
    } 
   
    
}

 

Locationbox is an external system that services like google maps. I want to deploy it to sf. You can review an example here;

http://www.locationbox.com.tr/web/demo/displaymap.jsp

 

First script tag retrieves javascript code from locationbox service. After working startup(), it sets a dynamic content to <div id='map'...> in document. There are several png images in the dynamic content. The code below works locally as html files but it doesn't work in apex page. (the function x() works as expected.)

 

 I am using the following code in apex page.

 

<script language="Javascript" src="http://www.locationbox.com.tr/locationbox/services?Key=mykey&Cmd=API&Typ=JS"
<script language="JavaScript">
  var mapper  = new IMapper();
 

  window.addEventListener('load', function() {alert('OK1'); x();}, false);

  window.addEventListener('load', function() {alert('OK1'); startup();}, false);

  function startup() {
    mapper.initMap(41.1, 29.1, 7);
    mapper.addNavigationPanel();
    MVGlobalVariables();
    return;
  }
  function x() {
     document.getElementById("map").innerHTML = 2;
  }
 </script>
 <div id="map" style="border: 1px solid black; width:100%; height:100%; z-index: 0; position:relative; -moz-user-select:none;   background-color: lightgrey;" tabindex="0"> 1 </div>

 

 

I am working on some code which sends mail to users who are not logged in the system for a long time. I want to deploy this code to a sf production environment that is including more than 150 users. But I'm getting this error  despite of query returns less than 100 users.  Do you have any idea about this issue?

 

I am using the following code.

 

global class LastLoginReminder implements Database.Batchable<sObject>, Schedulable {

    global Database.QueryLocator start(Database.BatchableContext BC) {
      return !Test.isRunningTest() ? Database.getQueryLocator([SELECT Id, LastLoginDate FROM User
           WHERE IsActive=false AND ((LastLoginDate <:Date.today().addDays(-28) AND LastLoginDate >:Date.today().addDays(-29)) OR
           (LastLoginDate <:Date.today().addDays(-22) AND LastLoginDate >:Date.today().addDays(-23)))]) : Database.getQueryLocator([Select Id,LastLoginDate From User Limit 3]);
    }  
 
   global void execute(Database.BatchableContext BC, list<User> users) {
        Messaging.SingleEmailMessage[] mails = new Messaging.SingleEmailMessage[0];
        for(User u : users) {
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail.setTargetObjectId(u.id);
            mail.setTemplateId(u.LastLoginDate.date().isSameDay(Date.today().addDays(-23)) ? '00Xa0000001Ifne' : '00Xa0000001IfnZ');
            mail.saveAsActivity = false;
            mails.add(mail);
        }
        Messaging.sendEmail(mails);
    }
    global void finish(Database.BatchableContext BC) {
        system.debug('batch job completed.');
    }
    global void execute(SchedulableContext ctx) {
        LastLoginReminder schedulableJob = new LastLoginReminder();
        Database.executebatch(schedulableJob);
    }
    public static testMethod void myTest() {
        Test.StartTest();
        LastLoginReminder schedulableJob = new LastLoginReminder();
        schedulableJob.execute(null);
        Test.stopTest();
    }
}

 

I have been successful with creating VF pages that are used to override a 'Edit' buttons for a few objects within Salesforce. I would like to do  the same to override the 'New' button. I've used the same code, as a starting point. I find that the standard controller attempts to retrieve a record from the database based on the record Id found in the request, and made it available to the Visualforce page (automatically). And if the retrieval is a success, the page displays as it should. 

 

When using a standard controller and I do not have an Id for the object, as it is when a user clicks 'New', how can I present the same form/layout that one would see with the standard page? Is this possible?

 

Thanks much.

  • March 09, 2012
  • Like
  • 0