• shrayas reddy
  • NEWBIE
  • 20 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 4
    Replies
global class PriceListUpdate implements Database.Batchable<sObject>{
   global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'select id,Name,Global_Product_Manager_SIG__c from product2';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<product2> scopeList){
        List<Price_Record_SIG__c> priceList = new List<Price_Record_SIG__c>();
        Map<Id,Id> listData = new Map<Id,Id>();
        for(product2 p:scopeList){
            listData.put(p.Id,p.Global_Product_Manager_SIG__c);
        }
        List<Price_Record_SIG__c> priceRcd = [Select Id,name,Product_Name_Code_SIG__r.Global_Product_Manager_SIG__c,Product_Name_Code_SIG__c,Product_Manager_SIG__c from Price_Record_SIG__c where Product_Name_Code_SIG__c =: listData.keySet()];
        if(priceRcd.size()>0){
            for(Id ids : listData.keySet()){
            for(Price_Record_SIG__c price:priceRcd){               
                    if(ids == price.Product_Name_Code_SIG__c){
                       // System.debug('Equal==>'+ids == price.Product_Name_Code_SIG__c);
                        System.debug('listData.get(ids)==>'+listData.get(ids));
                        price.Product_Manager_SIG__c = listData.get(ids);
                        System.debug('price.Product_Manager_SIG__c==>'+price.Product_Manager_SIG__c);
                        priceList.add(price);
                    }
                }
            }
        }
        if(priceList.size()>0){
            update priceList;
        }
        
    } 
    global void finish (Database.BatchableContext BC){
        System.debug('Batch job Completed successfully');
    }
    
}



/* In ananymous window I am running below code*/

PriceListUpdate up = new PriceListUpdate();
database.executeBatch(up,200);
// Aura component


<aura:component controller="Testquestions" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="FullName" type="String"/>
    <aura:attribute name="Phone" type="INTEGER"/>
    <aura:attribute name="Email" type="String"/>
    <aura:attribute name="city" type="String"/>
    <aura:attribute name="result" type="object[]"/>
    
    <aura:attribute name="optionA" type="String"/>
    <aura:attribute name="optionB" type="String"/>
    <aura:attribute name="optionC" type="String"/>
    <aura:attribute name="optionD" type="String"/>
    <aura:attribute name="testobj" type="Question__c[]"/>
    <aura:attribute name= "answerselected" type="Map"/>
    <aura:attribute name= "opt" type="List"/>
    <div>
        <br/>
        <h1 style="font-size: 25px; text-align:center"> Test 2022 </h1>
        <br/>
        <br/>
      
        <div class="slds-align_absolute-center">
          <div class="slds-grid_horizontal max-2">
        
        <lightning:input style="margin-right: 20px"  value="{!v.FullName }" label="Enter your full name" />
        <lightning:input style="margin-right: 20px"  value="{!v.Phone }" label="Enter your Phone Number" />
          </div>
        <div class="slds-grid_horizontal max-2">
        <lightning:input  value="{!v.Email}" label="Enter your Email Id" />
        <lightning:input  value="{!v.city }" label="Enter your city" />
        
        </div>
        </div>
        <br/>
        <br/>
        <div class="slds-align_absolute-center">
            
  <lightning:button variant="brand" label="start" title="Base action" onclick="{!c.startexam}"/>
   <lightning:button variant="brand" label="submit" title="Base action" onclick="{!c.submit}" />
        <br/>
    <br/>      
        </div>
        <div class="slds-align_absolute-center">
            <div class="slds-grid_horizontal max-2">
          <aura:iteration items="{!v.testobj}" var="a">
              
             
                <lightning:card  >
        <p><ui:outputText class="result"  value="{!'Q) ' + a.QuestionFull__c}" /></p>
    <br/>
   
   <ui:inputRadio  name="{!a.Id}" text="a" label="{!'A) ' + a.Option_A__c}" change="{!c.onGroup}"/> <br/>
   <ui:inputRadio  name="{!a.Id}" text="b" label="{!'B) ' + a.Option_B__c}" change="{!c.onGroup}"/> <br/>
   <ui:inputRadio  name="{!a.Id}" text="c" label="{!'C) ' + a.Option_C__c}" change="{!c.onGroup}"/> <br/>
   <ui:inputRadio  name="{!a.Id}" text="d" label="{!'D) ' + a.Option_D__c}" change="{!c.onGroup}"/> <br/>
   <br/>
    <br/>
                   </lightning:card>
             
          
        </aura:iteration>
        </div>
            </div>
    </div>
    
   
</aura:component>



// Aura controller

({
    startexam : function(component, event, helper) {
        var action = component.get('c.getQuestions');
       // action.setParams();
              action.setCallback(this, function(response){
            var state = response.getState();

            if(state == 'SUCCESS'){
                console.log('apex call is done!', response.getReturnValue()); 
                component.set('v.testobj', response.getReturnValue());
            }
                   });
        
        $A.enqueueAction(action);
    },
    onGroup : function(component, event, helper) {
        var Answer = event.getSource().get("v.text");
        var name = event.getSource().get("v.name");
        var selected = [{'name':name},{'Answer':Answer}]; 
        //var cmp = component.get('v.result');
        //var newmap = new Map();
        //newmap.set(name, Answer);
        //newMap.forEach((name,Answer)=>cmp.set(name,Answer));
        component.set('v.result',selected);
        console.log(component.get('v.result'));
       
    },
    submit : function(component, event, helper) {
        var action = component.get('c.insertrec');
        var name = component.get('v.FullName');
        var phone = parseInt(component.get('v.Phone'));
        var email = component.get('v.Email');
        var city = component.get('v.city'); 
        var res = [component.get('v.result')];
         
        action.setParams({'name':name},{'phone':phone},{'email':email},{'city':city},{'obj':res});
              action.setCallback(this, function(response){
            var state = response.getState();

            if(state == 'SUCCESS'){
                console.log('apex call is done!', response.getReturnValue()); 
                component.set('v.testobj', response.getReturnValue());
            }
                   });
        
        $A.enqueueAction(action);
    }
})



//Apex controller

public class Testquestions {
     @AuraEnabled
    public static List<Question__c> getQuestions(){
        List<Question__c> que = new List<Question__c>();
        que = [SELECT Id,QuestionFull__c,Option_A__c,Option_B__c,Option_C__c,Option_D__c,Answer__c FROM Question__c];
        
       // system.debug(que);
       // insert stu;
        return que;
    }
    @AuraEnabled
    public static void insertrec(String name, integer phone, string email, string city, List<object> obj){
        test_taker__c stu = new test_taker__c();
        stu.Full_Name__c = name;
        stu.Phone_Number__c = phone;
        stu.Email__c = email;
        stu.City__c = city;
        
        system.debug(obj);
        system.debug(name);
     
    }
}
<table class="slds-table slds-table_cell-buffer slds-table_bordered">
                    <thead>
                      <tr class="slds-line-height_reset">
                        <th  scope="col">
                          <div class="slds-truncate" title="Name">Name</div>
                        </th>
                       
                        <th class="" scope="col">
                          <div class="slds-truncate" title="Phone">Phone</div>
                        </th>
                        <th class="" scope="col">
                            <div class="slds-truncate" title="Email">Email</div>
                          </th>
                          <th class="" scope="col">
                            <div class="slds-truncate" title="Account Name">Account Name</div>
                          </th>
                       
                      </tr>
                    </thead>
                    <tbody>
                <template for:each={conts} for:item="contact" >
                   
                      <tr key={contact.Id}>
                        <th data-label="Name">
                          <div class="slds-truncate" >{contact.Name}</div>
                        </th>
                        <th data-label="Phone">
                          <div class="slds-truncate">{contact.Phone}</div>
                        </th>
                        <th data-label="Email">
                          <div class="slds-truncate">{contact.Email}</div>
                        </th>
                       
                        <th data-label="Account Name">
                          <div class="slds-truncate">{contact.Account.Name}</div>
                        </th>
                       
                      </tr>
                   
                    </template>
                       
                    </tbody>
                  </table>
trigger parentAccounttrigger on Account (before insert) {
parentAccount.parent(trigger.new);
   
}

--***--

public class parentAccount {
    public static void parent(List<account> acc){
        Set<Id> Ids = new Set<Id>();
        List<Account> acct = new List<Account>();
        for(account a:acc){
            if(a.ParentId != null){
           Ids.add(a.ParentId);
        }
        }
        acct = [SELECT Name, Id,ParentId FROM Account WHERE Id=:Ids]; 
        for(Account ac:acct){
            if(ac.ParentId != null){
// the below custom mssage is not being displayed
                ac.addError('There is already a parent for your parent account');
            }
        }
     
    }
}
public class integpost {
      @AuraEnabled
    public static List<string> output(String serviceId, String depositTicker, string withdrawalTicker, integer depositValue ){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.bestrate.org/api/select-service');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        string body = '{"serviceId":"'+serviceId+'","depositTicker" :"' +depositTicker+'" ,"withdrawalTicker":"'+ withdrawalTicker +'","partnerId":null,"depositValue":"'+depositValue+'" }';
             request.setBody(body);
                         
        HttpResponse response = http.send(request);
         string values = response.getBody();
       
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(values);
    
        Map<String, Object> dim = (Map<String, Object>)m.get('result');
        system.debug(dim.get('withdrawalValue'));
       
       List<Object> a = (List<Object>)dim.get('fields');
  
     
        List<string> lsstr= new List<string> ();
       // List<string> lsst= new List<string> ();
        for(Object b:a){
         lsstr.add(String.valueOf(b));
       }
        system.debug(lsstr);
     
  
        return lsstr;

          }
}

output that is returning from method : 
({description=The recipient’s wallet address is the address we send coins bought, once a transaction is finished., name=withdrawalWallet, placeholder=Wallet address, required=true, title=Enter your ETH wallet address}, {defaultValue=user.email, description=Enter your email to start exchange, name=email, placeholder=Email, required=true, title=Enter your email address})no output in aura table


Component:
<aura:component controller="integpost" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="serviceId" type="String" />
    <aura:attribute name="depositTicker" type="String" />
  <aura:attribute name="withdrawalTicker" type="String" />
      <!-- <aura:attribute name="partnerId" type="String" />-->
  <aura:attribute name="depositValue" type="integer" />
    <aura:attribute name="ApiDetail" type="String[]"/>
        <aura:attribute name="Detail" type="List" />
    <lightning:card>
        <lightning:input label="Enter service Id" value="{!v.serviceId}"/><br/>
         <lightning:input label="Enter Deposit ticket" value="{!v.depositTicker}"/><br/>
         <lightning:input label="Enter Withdrawl Ticket" value="{!v.withdrawalTicker}"/><br/>
         <!--<lightning:input label="Enter partnerId" value="{!v.partnerId}"/><br/>-->
         <lightning:input label="Enter deposit Value" value="{!v.depositValue}"/><br/>
         <lightning:button label="getExchange" onclick="{!c.handleApex}" variant="success"/>
     
        <lightning:datatable data="{!v.ApiDetail}"
                         columns="{!v.Detail}"
                         keyField="name"
                         hideCheckboxColumn="false"/>
         

      
        </lightning:card>
</aura:component>

js:

({
    handleApex : function(component, event, helper) {
        var action = component.get('c.output');
        var ion = component.get('v.serviceId');
          var dt = component.get('v.depositTicker');
         var wt = component.get('v.withdrawalTicker');
        // var pid = component.get('v.partnerId');
         var dv = component.get('v.depositValue');
        // var Ad = component.get('v.ApiDetail');
        action.setParams({'serviceId': ion, 'depositTicker':dt, 'withdrawalTicker': wt,
                           'depositValue':dv});
        
         component.set('v.Detail', [
            {label: 'title', fieldName:'title', type: 'text',editable: true},
                {label: 'name', fieldName: 'name', type: 'text'},
                {label: 'placeholder', fieldName: 'placeholder', type: 'text'},
                {label: 'description', fieldName: 'description', type: 'text',editable: true},
                {label: 'required', fieldName: 'required', type: 'boolean',editable: true}
            ]);
        
        action.setCallback(this, function(response){
            var state = response.getState();

            if(state == 'SUCCESS'){
                console.log('apex call is done!', response.getReturnValue()); 
                component.set('v.ApiDetail', response.getReturnValue());
            }
            
        });
        
        $A.enqueueAction(action);
    }
})
public class candidateStatusUpdate implements
Database.Batchable<sObject>,Database.Stateful {
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            ' SELECT Id,Name,status__c,Candidate_Number__c,CreatedDate FROM Job_application__c where CreatedDate = TODAY');
       
        
    }
    public void execute(Database.BatchableContext bc, List<Job_application__c> scope){
        Set<Candidate__c> con = new Set<Candidate__c>();
       
        List<Candidate__c> can = [select Id,name,status__c from Candidate__c];
// there are onth two values in candidate status feild accepted and //rejected.
//there are four values in job application status .
//one candidate can have multiple applications so even one job //application status is accepted then status feild in candidate should //be updated to accepted. if none of his job appliaction are accepted //then his status in candidate should be updated to rejected.
        for(Job_application__c j:scope){
            for(Candidate__c c:can){
                if(j.status__c == 'Accepted'){
                    c.Status__c = 'Accepted';
                    con.add(c);
                }else if((j.status__c == 'Rejected') || (j.status__c == 'New') || (j.status__c == 'On hold')){
                   c.Status__c = 'Rejected' ;
                }
            }
        }
        List<Candidate__c> cond = new List<Candidate__c>();
        cond.addAll(con);
        update cond;
    }
    public void finish(Database.BatchableContext bc){
        
        
    }
}
public class Myclass {
    void writeLog(){
        System.debug('hello world');
    }

}

Myclass c = new Myclass();
c.writeLog();
public class integpost {
      @AuraEnabled
    public static List<string> output(String serviceId, String depositTicker, string withdrawalTicker, integer depositValue ){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.bestrate.org/api/select-service');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        string body = '{"serviceId":"'+serviceId+'","depositTicker" :"' +depositTicker+'" ,"withdrawalTicker":"'+ withdrawalTicker +'","partnerId":null,"depositValue":"'+depositValue+'" }';
             request.setBody(body);
                         
        HttpResponse response = http.send(request);
         string values = response.getBody();
       
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(values);
    
        Map<String, Object> dim = (Map<String, Object>)m.get('result');
        system.debug(dim.get('withdrawalValue'));
       
       List<Object> a = (List<Object>)dim.get('fields');
  
     
        List<string> lsstr= new List<string> ();
       // List<string> lsst= new List<string> ();
        for(Object b:a){
         lsstr.add(String.valueOf(b));
       }
        system.debug(lsstr);
     
  
        return lsstr;

          }
}

output that is returning from method : 
({description=The recipient’s wallet address is the address we send coins bought, once a transaction is finished., name=withdrawalWallet, placeholder=Wallet address, required=true, title=Enter your ETH wallet address}, {defaultValue=user.email, description=Enter your email to start exchange, name=email, placeholder=Email, required=true, title=Enter your email address})no output in aura table


Component:
<aura:component controller="integpost" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="serviceId" type="String" />
    <aura:attribute name="depositTicker" type="String" />
  <aura:attribute name="withdrawalTicker" type="String" />
      <!-- <aura:attribute name="partnerId" type="String" />-->
  <aura:attribute name="depositValue" type="integer" />
    <aura:attribute name="ApiDetail" type="String[]"/>
        <aura:attribute name="Detail" type="List" />
    <lightning:card>
        <lightning:input label="Enter service Id" value="{!v.serviceId}"/><br/>
         <lightning:input label="Enter Deposit ticket" value="{!v.depositTicker}"/><br/>
         <lightning:input label="Enter Withdrawl Ticket" value="{!v.withdrawalTicker}"/><br/>
         <!--<lightning:input label="Enter partnerId" value="{!v.partnerId}"/><br/>-->
         <lightning:input label="Enter deposit Value" value="{!v.depositValue}"/><br/>
         <lightning:button label="getExchange" onclick="{!c.handleApex}" variant="success"/>
     
        <lightning:datatable data="{!v.ApiDetail}"
                         columns="{!v.Detail}"
                         keyField="name"
                         hideCheckboxColumn="false"/>
         

      
        </lightning:card>
</aura:component>

js:

({
    handleApex : function(component, event, helper) {
        var action = component.get('c.output');
        var ion = component.get('v.serviceId');
          var dt = component.get('v.depositTicker');
         var wt = component.get('v.withdrawalTicker');
        // var pid = component.get('v.partnerId');
         var dv = component.get('v.depositValue');
        // var Ad = component.get('v.ApiDetail');
        action.setParams({'serviceId': ion, 'depositTicker':dt, 'withdrawalTicker': wt,
                           'depositValue':dv});
        
         component.set('v.Detail', [
            {label: 'title', fieldName:'title', type: 'text',editable: true},
                {label: 'name', fieldName: 'name', type: 'text'},
                {label: 'placeholder', fieldName: 'placeholder', type: 'text'},
                {label: 'description', fieldName: 'description', type: 'text',editable: true},
                {label: 'required', fieldName: 'required', type: 'boolean',editable: true}
            ]);
        
        action.setCallback(this, function(response){
            var state = response.getState();

            if(state == 'SUCCESS'){
                console.log('apex call is done!', response.getReturnValue()); 
                component.set('v.ApiDetail', response.getReturnValue());
            }
            
        });
        
        $A.enqueueAction(action);
    }
})
global class PriceListUpdate implements Database.Batchable<sObject>{
   global Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query = 'select id,Name,Global_Product_Manager_SIG__c from product2';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<product2> scopeList){
        List<Price_Record_SIG__c> priceList = new List<Price_Record_SIG__c>();
        Map<Id,Id> listData = new Map<Id,Id>();
        for(product2 p:scopeList){
            listData.put(p.Id,p.Global_Product_Manager_SIG__c);
        }
        List<Price_Record_SIG__c> priceRcd = [Select Id,name,Product_Name_Code_SIG__r.Global_Product_Manager_SIG__c,Product_Name_Code_SIG__c,Product_Manager_SIG__c from Price_Record_SIG__c where Product_Name_Code_SIG__c =: listData.keySet()];
        if(priceRcd.size()>0){
            for(Id ids : listData.keySet()){
            for(Price_Record_SIG__c price:priceRcd){               
                    if(ids == price.Product_Name_Code_SIG__c){
                       // System.debug('Equal==>'+ids == price.Product_Name_Code_SIG__c);
                        System.debug('listData.get(ids)==>'+listData.get(ids));
                        price.Product_Manager_SIG__c = listData.get(ids);
                        System.debug('price.Product_Manager_SIG__c==>'+price.Product_Manager_SIG__c);
                        priceList.add(price);
                    }
                }
            }
        }
        if(priceList.size()>0){
            update priceList;
        }
        
    } 
    global void finish (Database.BatchableContext BC){
        System.debug('Batch job Completed successfully');
    }
    
}



/* In ananymous window I am running below code*/

PriceListUpdate up = new PriceListUpdate();
database.executeBatch(up,200);
<table class="slds-table slds-table_cell-buffer slds-table_bordered">
                    <thead>
                      <tr class="slds-line-height_reset">
                        <th  scope="col">
                          <div class="slds-truncate" title="Name">Name</div>
                        </th>
                       
                        <th class="" scope="col">
                          <div class="slds-truncate" title="Phone">Phone</div>
                        </th>
                        <th class="" scope="col">
                            <div class="slds-truncate" title="Email">Email</div>
                          </th>
                          <th class="" scope="col">
                            <div class="slds-truncate" title="Account Name">Account Name</div>
                          </th>
                       
                      </tr>
                    </thead>
                    <tbody>
                <template for:each={conts} for:item="contact" >
                   
                      <tr key={contact.Id}>
                        <th data-label="Name">
                          <div class="slds-truncate" >{contact.Name}</div>
                        </th>
                        <th data-label="Phone">
                          <div class="slds-truncate">{contact.Phone}</div>
                        </th>
                        <th data-label="Email">
                          <div class="slds-truncate">{contact.Email}</div>
                        </th>
                       
                        <th data-label="Account Name">
                          <div class="slds-truncate">{contact.Account.Name}</div>
                        </th>
                       
                      </tr>
                   
                    </template>
                       
                    </tbody>
                  </table>
trigger parentAccounttrigger on Account (before insert) {
parentAccount.parent(trigger.new);
   
}

--***--

public class parentAccount {
    public static void parent(List<account> acc){
        Set<Id> Ids = new Set<Id>();
        List<Account> acct = new List<Account>();
        for(account a:acc){
            if(a.ParentId != null){
           Ids.add(a.ParentId);
        }
        }
        acct = [SELECT Name, Id,ParentId FROM Account WHERE Id=:Ids]; 
        for(Account ac:acct){
            if(ac.ParentId != null){
// the below custom mssage is not being displayed
                ac.addError('There is already a parent for your parent account');
            }
        }
     
    }
}
public class candidateStatusUpdate implements
Database.Batchable<sObject>,Database.Stateful {
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator(
            ' SELECT Id,Name,status__c,Candidate_Number__c,CreatedDate FROM Job_application__c where CreatedDate = TODAY');
       
        
    }
    public void execute(Database.BatchableContext bc, List<Job_application__c> scope){
        Set<Candidate__c> con = new Set<Candidate__c>();
       
        List<Candidate__c> can = [select Id,name,status__c from Candidate__c];
// there are onth two values in candidate status feild accepted and //rejected.
//there are four values in job application status .
//one candidate can have multiple applications so even one job //application status is accepted then status feild in candidate should //be updated to accepted. if none of his job appliaction are accepted //then his status in candidate should be updated to rejected.
        for(Job_application__c j:scope){
            for(Candidate__c c:can){
                if(j.status__c == 'Accepted'){
                    c.Status__c = 'Accepted';
                    con.add(c);
                }else if((j.status__c == 'Rejected') || (j.status__c == 'New') || (j.status__c == 'On hold')){
                   c.Status__c = 'Rejected' ;
                }
            }
        }
        List<Candidate__c> cond = new List<Candidate__c>();
        cond.addAll(con);
        update cond;
    }
    public void finish(Database.BatchableContext bc){
        
        
    }
}