Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

개발일지

List 형식의 query문을 담고 리턴으로 List반환(데이터테이블에 목록출력) 본문

Apex

List 형식의 query문을 담고 리턴으로 List반환(데이터테이블에 목록출력)

청일쓰 2021. 7. 9. 09:56

 

 @AuraEnabled
    public static List <Price_Book_Entry__c> fetchProduct1(String entryList,boolean stanChk){//메인
        System.debug('entryList'  + entryList);
        List<Price_Book_Test__c> IstPriEntryCus=new List<Price_Book_Test__c>();
        
        List<Price_Book_Entry__c> entryValueIterater = new List<Price_Book_Entry__c>();
        //pricebook IstPriEntryCus List -> id값에 맞는 제품 필드들을 리스트에 넣엇고 
        //엔트리에 다시넣음 
        List<Price_Book_Test__c> getCheckStan = new  List<Price_Book_Test__c>();
      
        getCheckStan = [SELECT IsStandard__c FROM Price_Book_Test__c where id =: entryList];//해당레코드가 스탠다드체크박스가 true / false 확인하려고
        for(Price_Book_Test__c p : getCheckStan) {
            System.debug('p.IsStandard__c'  + p.IsStandard__c);
            if(p.IsStandard__c == true) { // true
                //System.debug(p.IsStandard__c);
                IstPriEntryCus= [SELECT (select Product__r.id,Product_Code__c,Product__r.Name,Product__r.Product_Code_c__c,UnitPrice__c,IsActive__c,Parent_PriceBookEntry__c,Product__r.custom_url_c__c from Price_Book_Entries__r)
                                 FROM Price_Book_Test__c 
                                 where id =: entryList and IsStandard__c=:p.IsStandard__c];
                System.debug('IstPriEntryCus->>>>>>>>>>>>>>'+IstPriEntryCus.size());
                for(integer i = 0;i<IstPriEntryCus[0].Price_Book_Entries__r.size();i++){
                    entryValueIterater.add(IstPriEntryCus[0].Price_Book_Entries__r[i]);
                    
                }
                System.debug('IstPriEntryCus->>>>>>>>>>>>>>'+IstPriEntryCus);
                
            } else { // false
                System.debug('스탠다드 체크박스 x 일때'+p.IsStandard__c);
                //해당 레코드
                IstPriEntryCus = [SELECT (select Product__r.Name,Product_Code__c,Product__r.Product_Code_c__c,UnitPrice__c,IsActive__c,Parent_PriceBookEntry__c,Product__r.custom_url_c__c from Price_Book_Entries__r) FROM Price_Book_Test__c where  id =: entryList and IsStandard__c =:p.IsStandard__c];
                
                System.debug('IstPriEntryCus->>>>>>>>>>>>>>'+IstPriEntryCus.size()); 
                for(integer i = 0;i<IstPriEntryCus[0].Price_Book_Entries__r.size();i++){
                    entryValueIterater.add(IstPriEntryCus[0].Price_Book_Entries__r[i]);
                }
                System.debug('entryValueIterater->>>>>>>>>>>>>>'+entryValueIterater);
                system.debug ( 'Domain URL is'+ System.Url.getOrgDomainUrl ());
            }
        }    
        
        //IstPriEntryCus= [SELECT (select name,Product2__r.Product_Code__c,UnitPrice__c,IsActive__c from Price_Book_Entries__r) FROM Price_Book_Test__c WHERE id =: entryList];// where id =: entryList and
        //system.debug('fetchProduct1의 결과 값 : '+ IstPriEntryCus[0].Price_Book_Entries__r.size());
        
        
        
        return entryValueIterater;
    }
cs
Apex

.apex


List로 초기화 한 뒤 for문에서 list를 돌린뒤 -> for(Price_Book_Test__c p : getCheckStan) { } 

 

  if(p.IsStandard__c == true) { // true 이면 } 

 for(integer i = 0;i<IstPriEntryCus[0].Price_Book_Entries__r.size();i++){
                    entryValueIterater.add(IstPriEntryCus[0].Price_Book_Entries__r[i]);
                }

 

     entryValueIterater.add(IstPriEntryCus[0].Price_Book_Entries__r[i]); ->

     IstPriEntryCus변수의 서브쿼리로 된 Price_Book_Entries__r을 담은거

    Price_Book_Test__c <-> Price_Book_Entries__r는 Lookup 관계기 때문에 서로 조회가 가능


Price_Book_Entries__r은 원래 API 이름은 Price_Book_Entries__c인데 관계된 애들 안에서 쓸때는 __r을 붙여야 사용가능 __c 사용 불가!

 

getData : function(component) { //메인
        console.log('당황스럽습니다');
        var action = component.get('c.fetchProduct1'); //메인 화면
        var reId = component.get("v.recordId");
        
        component.set( "v.pRecordId" ,reId); 
        console.log(reId+"현재 보고있는 레코드의 아이디");
        
        
        action.setParams({ entryList : reId });
        
        
        
        action.setCallback(this, $A.getCallback(function (response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var myReturnVal = response.getReturnValue();
                console.log('myReturnVal',myReturnVal);
                for(var i = 0;i<myReturnVal.length;i++){
                    var row=myReturnVal[i];
                  
                    if(row.Product__r){
                        row.Product_Code_c = row.Product__r.Product_Code_c__c;
                        row.custom_url_c__c = row.Product__r.custom_url_c__c;
                        //row['hi'] = 'https://dkbmc--qadkbmc.lightning.force.com/lightning/r/product2__c/'+ CASESAFEID(Id)+'/view'
                        row.Name = row.Product__r.Name;
                    }
                    
                }
                //Product2__r.id,Product2__r.Name
                console.log('원본 linkName의 값 : ' + myReturnVal);
                myReturnVal.forEach(function(record){
                    console.log('없을껄? ',record);
                    if(record.Product__r) myReturnVal.Product__Name = '/'+record.Product__r.Id; //엔트리 아이디값 찾아감
                    console.log('수정 후 linkName의 값 : '+ myReturnVal.Name);
                });
                
                console.log(myReturnVal);
                component.set('v.initData', myReturnVal);
                
            } else if (state === "ERROR") {
                console.log("실패 ㅠㅠ");
            }
        }));
        $A.enqueueAction(action);
        
    },
cs

.Helper 

헬퍼에서 apex단의 매게변수를 보내고 apex의 리턴 entryValueIterater을  받을수있다.

setParams 에서 apex단으로 매개변수를 넘길수있음.

reId의 v.recordId는 cmp단에서 force:hasRecordId를 선언했기 때문에 사용할수있다

recordId는 해당 페이지의 ID값을 가져올수있음.

 

js와 apex단의 주고 받고는 다음에


화면 출력 화면 

'Apex' 카테고리의 다른 글

Salesforce APEX Excetion Limit 모음  (0) 2025.01.22
Apex에서 종속 선택 목록 값 가져오기  (0) 2025.01.20
Apex Collection List, Set, Map  (0) 2021.07.09