2016年12月25日日曜日

Java : java.lang.InternalError: name is too long to represent

I faced the exception that I couldn't solve.

java.lang.InternalError: name is too long to represent

I serched this exception, but I knew that I couldn't solve it. I found a note and read it.

This is a bug in the Sun/Oracle JVM

If the size of JSP file is over 65KM, you can enclose this exception. You can't salve, but you can avoid it. This exception will ocuur, when you use debug mode. So you stop to use debug mode, you don't face this exception.

2016年12月6日火曜日

Oracle : SQL : ORA-02260

I encountered an "ORA-02260".

ORA-02260 : 
table can have only one primary key.

How can I solve this problem? I can't add the primary key.
If a table already has a primary key, you can't add primary key. So you have to remove and re-create your primary key.

First, you remove your primary key to execute the query.
ALTER TABLE [Table Name] 
  DROP CONSTRAINT [Primary Key Name]

Second, you re-create your primary key.
ALTER TABLE [Table Name] 
  ADD CONSTRAINT [Primary Key Name] 
  PRIMARY KEY [COLUMN NAMES]

If you want to use multiple columns as primary key, you should separate with comma.
ALTER TABLE [Table Name] 
  ADD CONSTRAINT [Primary Key Name] 
  PRIMARY KEY (col1, col2, col3)

2016年12月2日金曜日

Tomcat : Create self-signed SSL certificates for Tomcat

First, you generate the "keystore".

%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg

Type this command your command line and press return.
You will be questioned something. Almost all of questions, you don't have to answer. Leave empty. But you should beware this question, "What is your first and last name?". This is the domain name, not your name.

Second, you configure your Tomcat.
Activate the "HTTPS-Connector" in your "[Tomcat installation directory path]/conf/server.xml" and adjust "keystoreFile" and "keystorePass". 

<Connector port="8443" protocol="HTTP/1.1"
           maxThreads="150" SSLEnabled="true"
           scheme="https" secure="true"
           clientAuth="false"
           sslProtocol="TLS"
           keystoreFile="[keystore_dir]\.keystore"
           keystorePass="[key_password]" />


Restart Tomcat and you go to "https://localhost:8443". You can find your SSL self-certificates site.

2016年11月5日土曜日

Salesforce : How to set breakpoints in the Developer Console

I didn't konw to be able to set breakpoints in the Developer Console.
So, I'd always used "system.debug" to check the value.


Run this program and check logs.


In this case, I have to write all of variable to check values. It was dissatisfaction for me. I wanted to set breakpoints, but I was convinced that it couldn't. One day, I thoughtlessly clicked the line number of the Developer Console. I could see a red point like that.


I realized to be able to set breakpoints in the Developer Console.
Run the program and click "Checkpoints" tab.


Dobule click the Checkpoints list, we can check the values.


It unlike the breakpoints, such as Eclipse, never pause at a time of checking. It save the values of the time the code is executed.



2016年11月3日木曜日

Salesforce : Apex : I took much time to get Record Type

I developed Visualforce to output a PDF.
I wanted to get Record Type. I thought It would be easy to develop, but I took much time.

Visualforce
<apex:page standardController="Opportunity" 
           extensions="TestController" 
           renderAs="pdf" applyBodyTag="false">
.....
.....
.....
</apex>

Apex
public class TestController {

  public TestController(
            ApexPages.StandardController controller) {

    // I wanted to get Record Type.

  }

}



First, I checked the "Opportunity Fields" and I could find Record Type's API Name is "RecordType".
So I changed my program.

Apex
public class TestController {

  public TestController(
            ApexPages.StandardController controller) {

    Id recordTypeId = controller.
              getRecord().get('RecordType'); // ERROR

  }

}



I ran the program, but I got the Error message. Salesforce didn't have the "RecordType" in Opportunity. I was
confused. I re-checked "Opportunity Fields" and I could find "RecordType" again.

I searched how to get "RecordType".
I found that Salesforce didn't have "RecordType", but have "RecordTypeId". And I had to use SOQL.

Apex
public class TestController {

  public TestController(
            ApexPages.StandardController controller) {

    List<RecordType> recordTypes = 
            [SELECT Name FROM RecordType WHERE Id = 
               :(Id)controller.getRecord().get('RecordTypeId')];

    if ('testType'.equals(recordTypes[0].Name)) {

      ...

      ...

    } else {

      ...

      ...

    }

  }

}



I could get the Record Type and finished to develop.

2016年10月16日日曜日

Bootstrap : Grid system

Grid system of Bootstrap is easy to use and develop the responsive web design.

<!-- 1 -->
<div class="container">
    <!-- 2 -->
    <div class="row">
        <!-- 3 -->
        <div class="col-sm-2">ID</h4></div>
        <div class="col-sm-2"><input type="text"/></div>
        <div class="col-sm-2">Name</div>
        <div class="col-sm-2"><input type="text"/></div>
        <div class="col-sm-2">Mail</div>
        <div class="col-sm-2"><input type="text"/></div>
    </div>
</div>

1. class="container" or class="container-fluid"
2. class="row"
3. class="col-{prefix}-{columns}"
4. {Columns} is specified so that the total value is 12


Bootstrap has 5 types of prefix. By the specified Prefix, the behavior of the grid changes.

1. xl
2. lg
3. md
4. sm
5. xs


"xl", "lg", "md" and "sm" have a breakpoints. If the size of browser is less than the breakpoints, the grid design are changed to horizontal. "xs" don't have breakpoints. So if you specify "xs", the grid design is horizontal all times.

1. xl : 1140px
2. lg : 940px
3. md : 720px
4. sm : 576px
5. xs : None




Change your browser size. You can see the horizontal design.

2016年10月8日土曜日

Salesforce : Force.com IDE For Eclipse Neon

I try to install Force.com IDE to Eclipse Neon.

1. Help > Install New Software

2. Click Add, Name is "Force.com IDE" and Location is "https://developer.salesforce.com/media/force-ide/eclipse45"


3. Check "Force.com IDE" and click Next

4. Click Next

5. Check "I accept the terms of the license agreement" and click Finish

6. Click Yes


After restart Eclipse
7. Window > Perspective > Open Perspective > Other

8. Choose "Force.com" and click OK

2016年10月6日木曜日

Salesforce : Apex : How can I send emails to more than 30 people in apex?

I wanted to send emails to more than 30 people in salesforce. So, I developed the batch apex job to send emails. But it didn't work. I checked log and found an error message.

ERROR : 
Scheduler: failed to execute scheduled job: jobId: 7072800002NeceT, class: common.apex.async.AsyncApexJobObject, reason: SendEmail failed. First exception on row 0; first error: LIMIT_EXCEEDED, Too many bccAddresses addresses.: [bccAddresses, 34]

// I get all of employees addresses
List<Employee__c> employeeList = [SELECT Mail__c FROM Employee__c];
List<String> toList = new List<String>();
for(Employee__c employee: employeeList){
    toList.add(employee.Mail__c);
}

// I want to send emails.
if(!toList.isEmpty()){
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
    message.setBccAddresses(toList);  // ERROR
    message.setInReplyTo('noreply@aaa.co.jp');
    message.setSubject('subject');
    message.setPlainTextBody('message');
    message.setSenderDisplayName('dispname');
    Messaging.sendEmail(new List<Messaging.SingleEmailMessage> { message });
}

The company I belong is employed more than 30 people. But we can't set more than 25 CC/BCC addresses for an single email instance.

I rewrite the apex.
public void send(){
    // I get all of employees address
    List<Employee__c> employeeList = [SELECT Mail__c FROM Employee__c WHERE RetirementFlg__c = FALSE];
    List<String> addresses = new List<String>();
    for(Employee__c employee: employeeList){
        addresses.add(employee.Mail__c);
    }

    // I send emails
    List<String> toList = new List<String>();
    for (String address : addresses) {
        if (toList.size() >= 25) {
            sendEmails(toList);
            toList.clear();
        }
        toList.add(address);
    }
    if (toList.size() > 0) {
        sendEmails(toList);
    }
}

private void sendEmails(List<String> toList) {
    Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
    message.setBccAddresses(toList);
    message.setInReplyTo('noreply@aaa.co.jp');
    message.setSubject('subject');
    message.setPlainTextBody('body');
    message.setSenderDisplayName('dispname');
    Messaging.sendEmail(new List<Messaging.SingleEmailMessage> { message });
}

Isn't there a more efficient way?