• N.igu
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies
PermissionSet perm = [SELECT Name FROM PermissionSet WHERE Name = 'AccountAdmin' LIMIT 1];

List<PermissionSetAssignment> assignList = [SELECT AssigneeId FROM PermissionSetAssignment WHERE AssigneeId =: perm.Id];

List<Id> UserIds = new List<Id>();

public Boolean getNewAdd(){
    
      for(PermissionSetAssignment assign : assignList){
        UserIds.add(assign.AssigneeId);
          System.debug('[UserIds] ' + assign.AssigneeId);
      }
      if(UserIds.contains(UserInfo.getUserId()) ){
            return true;
        }else{
            return false;
      }
}
  • August 08, 2019
  • Like
  • 0
public with sharing class AccountListCon {
    static List<String> TARGET_FIELDS = new List<String>{
      'Name'
      ,'ServerName__c'
    };

    public SearchCondition condition{ get;set; }
    public List<AccountList__c> results { get;set; }
    public String sortingField { get;set; }


    public void init(){
        this.condition = new SearchCondition();
        this.results = new List<AccountList__c>();
    }


    public PageReference clear(){
        init();
        return null;
    }

    public PageReference search() {


        if( condition.validate() ){
            return null;
        }


        String soqlQuery = condition.getSoqlQuery();
        System.debug('[soql] ' + soqlQuery);

        try{
            this.results = database.query(soqlQuery);
            System.debug(this.results);
        }catch(DmlException e){
            ApexPages.addMessages(e);
            System.debug('[DmlException]' + e);
        }catch(Exception e){
            ApexPages.addMessages(e);
            System.debug('[Exception]' + e);
        }
        return null;
    }


    public PageReference sort(){

        if(this.sortingField == null ){
            return null;
        }


        if(this.sortingField == this.condition.sortkey){
            this.condition.setOrderReverse();
        }
        else {
            this.condition.sortkey = this.sortingField;
        }
        search();
        return null;
    }

    public String getSortKey(){
        return this.condition.sortkey;
    }

    public String getSortOrder(){
        return this.condition.sortOrderToString();
    }


    public Class SearchCondition {

    private Time JST_AM0 = Time.newInstance(9, 0, 0, 0);

        public AccountList__c obj {get;set;}

        public String sortkey { get;set; }
        public String order { get;set; }

        public SearchCondition() {
            this.obj = new AccountList__c();

            sortkey = 'LastModifiedDate';
            order = 'DESC';
        }


        public boolean validate(){
            boolean isError = false;

            return isError;
        }



        public String getSoqlQuery(){
            List<String> param = new String[]{ getFieldList(), getWhere(), getOrder() };
            return String.format('SELECT {0} FROM AccountList__c {1} {2} LIMIT 500', param);
        }

        private String getFieldList(){
            return String.join(TARGET_FIELDS, ',');
        }

        private String getWhere(){
            List<String> param = new String[]{ };

            if( !String.isBlank(this.obj.ServerName__c) ){
                param.add('ServerName__c LIKE \'%' + obj.ServerName__c + '%\'');
            }


            if(param.isEmpty()){
                return '';
            }
            return 'WHERE ' + String.join(param, ' AND ');
        }

        private String getOrder(){
            List<String> param = new String[]{ sortkey, order };
            return String.format('ORDER BY {0} {1}', param);
        }

        private DateTime adjustJSTtoGMS(DateTime day){
            JST_AM0 = Time.newInstance(15, 0, 0, 0);
            return Datetime.newInstance(day.date(), JST_AM0);
        }



        public String sortOrderToString(){
            if(this.order == 'DESC'){
                return '▼';
            }
            return '▲';
        }

        public void setOrderReverse(){
            if(this.order == 'DESC'){
                this.order = 'ASC';
            }
            else {
                this.order = 'DESC';
            }
        }
    }


}



VF
<apex:page controller="AccountListCon" action="{!init}" sidebar="false" Id="AccountRequestList" >

<script type="text/javascript">
    beenFocused = true;
</script>
<apex:form id="form1">
    <apex:pageBlock title="検索">
        <apex:pageMessages id="messagearea" showDetail="false"/>
        <apex:pageblockSection id="conditionSection" title="検索" columns="1">
            <apex:outputpanel id="searchcondition">
                <ul id="conditionTable">

                <li>
                    <span class="label"><apex:outputLabel value="サーバ名" for="ServerName" styleClass="labelCol" /></span>
                    <span><apex:inputField id="ServerName" value="{!condition.obj.ServerName__c}" /></span>
                </li>

                </ul>
            </apex:outputpanel>
        </apex:pageblockSection>
        <apex:pageBlockButtons id="buttonSection" location="bottom" >
            <apex:commandLink value="検索" action="{!search}" reRender="searchresult,messagearea" />

            <apex:commandLink value="クリア" action="{!clear}"   reRender="searchcondition,searchresult,messagearea"/>

        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>
<apex:outputpanel id="searchresult">
    <apex:pageBlock title="検索結果:" rendered="{!(results.size == 0)}">
         検索条件に該当するデータがありません
    </apex:pageBlock>

    <apex:form id="resultForm">
        <apex:pageBlock id="resultBlock" title="一覧" rendered="{!(results.size > 0)}">
            <apex:outputtext style="width:110px" value="結果 : {!results.size}件"/>

            <apex:pageblockTable id="resultTable" value="{!results}" var="o" frame="box">


                <apex:column style="width:80px">
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="ID{!IF(sortKey == 'Name', sortOrder, ' ')}">
                            <apex:param value="Name" name="String" assignTo="{!sortingField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputlink value="/{!o.Id}"><apex:outputField style="width:80px" value="{!o.Name}"/></apex:outputlink>
                </apex:column>


                <apex:column style="width:80px">
                    <apex:facet name="header">
                        <apex:commandLink action="{!sort}" value="サーバー名{!IF(sortKey == 'ServerName__c', sortOrder, ' ')}">
                            <apex:param value="ServerName__c" name="String" assignTo="{!sortingField}" />
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputField style="width:150px" value="{!o.ServerName__c}"/>
                </apex:column>

            </apex:pageblockTable>

        </apex:pageBlock>
    </apex:form>
</apex:outputpanel>
</apex:page>

It was possible to here.
But how do I get pagination?


 
  • July 23, 2019
  • Like
  • 0
No errors on the apex class screen. An unexpected error occurs when you press the search button.

I got an error when I added the pagination code in the second half.
There was no problem before that.

Why? Thank you.


 
public with sharing class AccountListCon {

    static List<String> TARGET_FIELDS = new List<String>{
      'Name'
    };

    public SearchCondition condition{ get;set; } 
    public List<AccountList__c> results { get;set; } 
    public String sortingField { get;set; }

    public void init(){
        this.condition = new SearchCondition();
        this.results = new List<AccountList__c>();
    }
    public PageReference clear(){
        init();
        return null;
    }
    public PageReference search() {

        if( condition.validate() ){
            return null;
        }

        String soqlQuery = condition.getSoqlQuery();
        System.debug('[soql] ' + soqlQuery);

        try{
            this.results = database.query(soqlQuery);
            System.debug(this.results);
        }catch(DmlException e){
            ApexPages.addMessages(e);
            System.debug('[DmlException]' + e);
        }catch(Exception e){
            ApexPages.addMessages(e);
            System.debug('[Exception]' + e);
        }
        return null;
    }

    public PageReference sort(){

        if(this.sortingField == null ){
            return null;
        }

        if(this.sortingField == this.condition.sortkey){
            this.condition.setOrderReverse();
        }
        else {
            this.condition.sortkey = this.sortingField;
        }

        search();
        return null;
    }


    public Class SearchCondition {

    private Time JST_AM0 = Time.newInstance(9, 0, 0, 0);


        public AccountList__c obj {get;set;}

        public SearchCondition() {
            this.obj = new AccountList__c();
            sortkey = 'LastModifiedDate';
            order = 'DESC';
        }

        public String getSoqlQuery(){
            List<String> param = new String[]{ getFieldList(), getWhere(), getOrder() };
            return String.format('SELECT {0} FROM AccountList__c {1} {2} LIMIT 500', param);
        }

        private String getFieldList(){
            return String.join(TARGET_FIELDS, ',');
        }

        private String getWhere(){
            List<String> param = new String[]{ };

--Omission--

            if(param.isEmpty()){
                return '';
            }
            return 'WHERE ' + String.join(param, ' AND ');
        }

        private String getOrder(){
            List<String> param = new String[]{ sortkey, order };
            return String.format('ORDER BY {0} {1}', param);
        }

        private DateTime adjustJSTtoGMS(DateTime day){
            JST_AM0 = Time.newInstance(15, 0, 0, 0);
            return Datetime.newInstance(day.date(), JST_AM0);
        }

--Omission--


        private static final Integer PAGE_SIZE = 10;
        public Integer currentPage {get; set;}
        public Integer totalPage {get; set;}
        private ApexPages.StandardSetController ssController;

        public Boolean getEnablePrev(){
            return ssController.getHasPrevious();
        }

        public Boolean getEnableNext(){
            return ssController.getHasNext();
        }

        public void PagingCtrl(){
        }


        public PageReference searchinit() {
            ssController = new ApexPages.StandardSetController([SELECT Id, Name FROM Account]);
            currentPage = ssController.getPageNumber();
            ssController.setPageSize(PAGE_SIZE);

            totalPage = (Integer)Math.ceil((Decimal)ssController.getResultSize() / PAGE_SIZE);
            return null;
        }

        public void next() {
            ssController.next();
            currentPage = ssController.getPageNumber();
        }

        public void prev() {
            ssController.previous();
            currentPage = ssController.getPageNumber();
        }

        public List<Account> getAccountList(){
            return (List<Account>)ssController.getRecords();
        }





}


 
  • July 19, 2019
  • Like
  • 0
// WHERE
        private String getWhere(){
            List<String> param = new String[]{ };

            // From
            if(this.obj.IssueDateStart__c <> null){
                Datetime fromDate = adjustJSTtoGMS(obj.IssueDateStart__c);
                param.add('IssueDate__c >= ' + fromDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
            }
            // To
            if(this.obj.IssueDateEnd__c <> null){
                Datetime toDate = adjustJSTtoGMS(obj.IssueDateEnd__c);
                param.add('IssueDate__c <= ' + toDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
            }

            if(param.isEmpty()){
                return '';
            }
            return 'WHERE ' + String.join(param, ' AND ');
        }


        private DateTime adjustJSTtoGMS(DateTime day){
            JST_AM0 = Time.newInstance(15, 0, 0, 0);
            return Datetime.newInstance(day.date(), JST_AM0);
        }
Execution result

value of filter criterion for field 'IssueDate__c' must be of type date and should not be enclosed in quotes



Please tell me the wrong place.




 
  • July 19, 2019
  • Like
  • 0
// WHERE
        private String getWhere(){
            List<String> param = new String[]{ };

            // From
            if(this.obj.IssueDateStart__c <> null){
                Datetime fromDate = adjustJSTtoGMS(obj.IssueDateStart__c);
                param.add('IssueDate__c >= ' + fromDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
            }
            // To
            if(this.obj.IssueDateEnd__c <> null){
                Datetime toDate = adjustJSTtoGMS(obj.IssueDateEnd__c);
                param.add('IssueDate__c <= ' + toDate.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\''));
            }

            if(param.isEmpty()){
                return '';
            }
            return 'WHERE ' + String.join(param, ' AND ');
        }


        private DateTime adjustJSTtoGMS(DateTime day){
            JST_AM0 = Time.newInstance(15, 0, 0, 0);
            return Datetime.newInstance(day.date(), JST_AM0);
        }
Execution result

value of filter criterion for field 'IssueDate__c' must be of type date and should not be enclosed in quotes



Please tell me the wrong place.




 
  • July 19, 2019
  • Like
  • 0