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.