• I'm from Mars
  • NEWBIE
  • 50 Points
  • Member since 2018

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 16
    Replies
Hi All,

I have attached the code  where I have passed the variable through contructor in Batch Apex class

I have written Batch apex with constructor and execute and written system.debug for checking.
Where it is not seeing the system.debug statement inside Execute method in debug logs.

I need help on execution method in Batch Apex.I am unaware why the execute method is not working on my side.
Apex class:
Extension_Batch  batch = new Extension_Batch(Newprdt,newRecord);
         Database.executeBatch(batch,200);
Batch Apex class:
global class Extension_Batch implements Database.Batchable<sObject>
{
 global List<B__c> Newprdt123;
 global  A__c newRecord123;   
 global Extension_Batch(List<B__c> Newprdt,A__c newRecord)
{
   //this block is working fine

    system.debug('Newprdt_batch'+Newprdt);
    system.debug('newRecord'+newRecord);
   Newprdt123 = Newprdt;
   newRecord123 = newRecord;
    system.debug('Newprdt123'+Newprdt123);
    system.debug('newRecord123'+newRecord123);
}
// Start Method
    global Database.QueryLocator start(Database.BatchableContext bc) 
    {
        system.debug('instart');
     return Database.getQueryLocator('Select id,OwnerId,IsDeleted,RecordTypeId,CreatedDate,CreatedById,LastModifiedDate, LastModifiedById  from A__c');
    }
   // Execute method
    global void execute(Database.BatchableContext BC,List<B__c> Newprdt123) 
    { 
        
       system.debug(' '+Newprdt123);  
       system.debug('newRecord123'+newRecord123); 
        
     for(B__c prdt :Newprdt123)
       {
         for(PricebookEntry pbe2 :[SELECT Id,Name,isactive,PriceBook2Id,Pricebook2.id,Product2.CurrencyIsoCode,
                                     PriceBook2.Name,PriceBook2.isactive,Product2.Name,Product2.ProductCode,
                                         Product2.family,UnitPrice,Product2.Description,product2.isactive FROM PriceBookentry 
                                         where Product2.ProductCode =:prdt.Name and isactive=true
                                         and Pricebook2.id=:newRecord123.PriceList__c])
           {
            if( prdt.List_Price_Per_Unit__c <> pbe2.UnitPrice & pbe2.Product2.ProductCode == prdt.Name)
               {
                  prdt.List_Price_Per_Unit__c = pbe2.UnitPrice;
               }
             update prdt;  
              
           }
          
                
       List<Pricebookentry> pbe3=[SELECT Id,Name,isactive,PriceBook2Id,Product2.ProductCode,PriceBook2.Name,PriceBook2.isactive,Product2.Name,
                                         Product2.family,Product2.Description,Unitprice,product2.isactive FROM PriceBookentry 
                                         where Product2.ProductCode =:prdt.Name and isactive=false and Pricebook2.id=:newRecord123.PriceList__c];
       
           if(pbe3.size() ==1)
           {
          for(Pricebookentry pbe1:pbe3)
          {
                            
       List<B__c> stpr =[Select id,IsDeleted,Product__r.id,Name,CreatedDate,CreatedById,LastModifiedDate,LastModifiedById,SystemModstamp,LastActivityDate From B__c 
                                   where Number1__c=:newRecord123.id and Name=: pbe1.product2.ProductCode];
              
            
              delete stpr;
         
          }
       }
           
       }
    }       
    // Finish Method
    global void finish(Database.BatchableContext BC) 
    {
       system.debug('Batch apex completed');
    }

}
Thanks in advance.
Sumitha P
 
  • September 24, 2019
  • Like
  • 0
I want to display selected checkbox value and dropdown value in PDF form.I'm getting Opportunity Name but unable to get Addresses value.There is no relation between Opportunity and Addresses.When both selected I want to display those values in pdf form.Can anyone help me?User-added image

Hi.I'm working on Lightning.I want a table based on productCode I select and months I enter in Rev Rec in months box.If I enter 9 I will get 9 months and if I enter 30 I will get 30 like M+1,M+2.....
boolean isMultiCurrencyOrganization = userinfo.isMultiCurrencyOrganization();
      string DefaultCurrency = userinfo.getDefaultCurrency();
          System.debug('DefaultCurrency:'+DefaultCurrency);
       if(DefaultCurrency == 'USD')userCurrencySign = '$';
        else if(DefaultCurrency == 'EUR')userCurrencySign = '€';
      else if(DefaultCurrency == 'INR')userCurrencySign = 'INR';
         else if(DefaultCurrency == 'CAD')userCurrencySign = '$';
       map<Id,string> mapcurrency = new map<Id,string>();
      if(isMultiCurrencyOrganization){
     System.debug('isMultiCurrencyOrganization'+isMultiCurrencyOrganization);
                                                                   CurrencyConversion.Initialization();
                                                               }
trigger PopulateStandardPrice2 on Product2 (before insert,before update,after insert,after update) {
    list<Id> Idlist = new list<Id>();
    list<product2> ProdsToUpdate = new list<Product2>();
    for(Product2 pr:trigger.new){
        Idlist.add(pr.Id);
    }
    pricebook2 pb = [select Id from pricebook2 where IsStandard = TRUE][0];
    Id stPrId = pb.Id;
    for(product2 p:[select Product_Price_Unit__c,Id from product2 where Id IN :Idlist]){
        for(pricebookentry pbe:[select Product2Id,UnitPrice from pricebookentry where pricebook2Id = :stPrId and product2Id IN :Idlist]){
            If((pbe.Product2Id == p.Id)&&(p.Product_Price_Unit__c!=pbe.UnitPrice)){
                p.Product_Price_Unit__c = pbe.UnitPrice;
                system.debug('this is it '+pbe.UnitPrice);
                system.debug('this is that '+p.Product_Price_Unit__c);
                ProdsToUpdate.add(p);
            }
        }
    }
    system.debug('ProdsToUpdate>>>'+ProdsToUpdate.size());
    If(ProdsToUpdate.size()>0&&trigger.isafter){
            update ProdsToUpdate;
    }
}
I have a requirement that I have to fetch all the Account Lookup fields.I'm using Schema.DisplayType for fetching Text,Picklistlist fields.But for lookup fields I don't know how to fetch.Can anyone help me?
I have One Object HDS which is self lookup. It has records and 
    if record 1 is checked all the records below of record record 1 is checked automatically , and if record 2 is checked all the records below record 2 is checked automatically.
public string amtStrData(string rstr){
        string strg = rstr;
        if(rstr.contains(' " ')){
            try{
            integer index1= rstr.indexOf('"')+1;
            string p1= rstr.substring(index1);
            integer index2= p1.indexOf('"')+index1;         
            string amount = rowstr.substring(index1,index2);
            amount = amount.replace(',','');
            strg = rstr.substring(0,index1-1)+amount+rstr.substring(index2+1);
            }catch(Exception e){}
        }
 Type__c theRec = Type__c.getInstance(op);  // Custom Setting
            if(theRec != null && theRec .Duration__c == true){
                 map<String,Product__c> mapData = new Map<String,Product__c>();
                 for(Product__c lstRev:Database.query(strFinalQuery)){ 
                   mapData.put( lstRev.Period__c, lstRev);
                }
I used Schema DisplayType but there is no AutoNumer dataTypes.We can't dislplay AutoNumber datatypes using DisplayType Schema
Select Account.Owner.Id,Type__c,Id,Name,Account.Id,Account.Name,Owner.Id from Opportunity where Id<>null  

String strAccount ;
String StrVersant;
String accQuery = 'Select Id,Name from Account where Id =:AccountId and Id IN(Select Account__c from Pd_Mod__c where Plng_session__r.Name=:strVersant) ORDER BY Name LIMIT 15000';
            accountList= Database.query(accQuery);
            if(accountList!=null && accountList.size()>0){
               for(Account accObj:accountList){
                  strAccount = accObj.name;
               }
            }
          String pvd = apexpages.currentpage().getparameters().get('pv');

         Pl_target_c target =[Select Name from Pl_target_c where Id=:Id.valueOf(pvd) LIMIT 1];
 
I have one dropdown with values"text,radio,multiselect,numeric".
My question is when I select text from dropdown  I should get text and when radio selected radio button should appear.How can i achieve this?
Hi Team,
I have created a VF page using standarController as Opportunity but it is not fetching the opportunity records(same is happening with Contact object too), whereas the same code is working fine with all other standar and custom object.

code below
<apex:page standardController="Contact" recordSetVar="cons">
    <apex:form >
    <apex:pageBlock title="Data from SF" >
        <apex:pageBlockSection title="Sub data" columns="1" >
        <apex:pageBlockTable value="{!cons}" var="c">
           <!-- <apex:column headerValue="Id of account along with link">
                <apex:outputLink value="/{!c.Id}">{!c.Id}</apex:outputLink>
            </apex:column> --->
            <apex:column value="{!c.Name}"/>
           
          </apex:pageBlockTable>
        </apex:pageBlockSection>
        <apex:commandButton value="Next" action="{!Next}"/>
         <apex:commandButton value="Previous" action="{!previous}"/>
  
        </apex:pageBlock>
    </apex:form>
</apex:page>
This is my batch class and im getting System.LimitException: Too many SOQL queries: 201  on line 59

global class ShipToCountBatch implements Database.Batchable<sObject>
{
    global Database.QueryLocator start(Database.BatchableContext BC)
    {
        recordtype RECORD_TYPE = [select id from recordtype where SobjectType = 'Account' and name = 'Customer Sold To' limit 1];
       
        String query = 'SELECT Id, Name FROM Account where Active__c != \'X\'AND RecordTypeId ='+'\''+ RECORD_TYPE.Id+'\'' ;
        
        return Database.getQueryLocator(query);
    }  

    global void execute(Database.BatchableContext BC, List<Account> scope)
    {
        List<Account> lAccountsToUpdate = new List<Account>{};
        List<Account> lShiptoAccountsToUpdate = new List<Account>{};
        for ( Account a : scope)
        {
            List<Account> al = new List<Account>{};  
            List<Id> accountIds= new List<Id>();
            al = [SELECT Id, SAP_Account_Id__c FROM Account where ParentId = :a.Id];   
            if( al.size()> 0 ){
                for ( Integer i = 0 ; i < al.size(); i++ )
                {
                    accountIds.add(al[i].Id);                  
                }
                accountIds.add(a.Id);
            } 
           
            Account oAccountToUpdate = new Account();
            oAccountToUpdate = a;
                       
             Sobject so1 = [SELECT COUNT(Id) shipToCount from Account where Id = :accountIds];
            
         
            Sobject so2 = [SELECT SUM(Adjusted_Net_Invoice_Price__c) currInvoicePrice, 
                                  SUM(Customer_Margin_CM1__c) currCM,
                                  SUM(Quantity_Converted__c) currVolume 
                                  from Sales_History__c 
                                  where Sales_Account__r.Sold_To_Account__r.Id = :accountIds  
                                        and Division__c != 'CATALYST'      
                                        and Current_Year_Invoice__c = 'Y'];


            Sobject so3 = [SELECT SUM(Adjusted_Net_Invoice_Price__c) prevInvoicePrice, 
                                  SUM(Customer_Margin_CM1__c) prevCM,
                                  SUM(Quantity_Converted__c) prevVolume 
                                  from Sales_History__c 
                                  where Sales_Account__r.Sold_To_Account__r.Id = :accountIds  
                                        and Division__c != 'CATALYST' 
                                        and Previous_Year_Invoice__c = 'Y'];


            oAccountToUpdate.Ship_To_Accounts__c = (Integer)so1.get('shipToCount');
            if (!String.isBlank(String.valueOf(so2.get('currInvoicePrice')) )) {
                oAccountToUpdate.YTD_LYB_Sales__c = Decimal.valueOf(String.valueOf(so2.get('currInvoicePrice'))).setScale(2);   
            }
            if (!String.isBlank(String.valueOf(so2.get('currCM')) )) {      
                oAccountToUpdate.YTD_LYB_CM1__c = Decimal.valueOf(String.valueOf(so2.get('currCM'))).setScale(2);  
            }
            if (!String.isBlank(String.valueOf(so2.get('currVolume')) )) {        
                oAccountToUpdate.YTD_LYB_Volume__c = Decimal.valueOf(String.valueOf(so2.get('currVolume'))).setScale(2);
            }
            if (!String.isBlank(String.valueOf(so3.get('prevCM')))) {
                oAccountToUpdate.Prior_Year_LYB_CM1__c = Decimal.valueOf(String.valueOf(so3.get('prevCM'))).setScale(2);
            }  
            if (!String.isBlank(String.valueOf(so3.get('prevVolume')) )) {  
                oAccountToUpdate.Prior_Year_LYB_Volume__c = Decimal.valueOf(String.valueOf(so3.get('prevVolume'))).setScale(2);   
            }
            if (!String.isBlank(String.valueOf(so3.get('prevInvoicePrice')) )) { 
                oAccountToUpdate.Prior_Year_LYB_Sales__c = Decimal.valueOf(String.valueOf(so3.get('prevInvoicePrice'))).setScale(2);
            }
            lAccountsToUpdate.add(oAccountToUpdate);
            
            List<Account> shipToAccountList = [SELECT Id,ParentId,Name,Parent.Name,YTD_LYB_CM1__c,YTD_LYB_Vol_KGS__c
                                                       FROM Account 
                                                       WHERE ParentId = :a.Id];
           
            if(shipToAccountList.size()>0){
            for (integer i=0;i<shipToAccountList.size();i++)
            {                
            Account shiptoAccountToUpdate = new Account();
            shiptoAccountToUpdate = shipToAccountList[i];
                
            Sobject so4 = [SELECT SUM(Adjusted_Net_Invoice_Price__c) currInvoicePrice, 
                                  SUM(Customer_Margin_CM1__c) currCM,
                                  SUM(Quantity_Converted__c) currVolume 
                                  from Sales_History__c 
                                  where Ship_To_Account__c = :shipToAccountList[i].Id  
                                        and Division__c != 'CATALYST'      
                                        and Current_Year_Invoice__c = 'Y'];

            List<Sales_History__c> listsh = [SELECT Id from Sales_History__c where Ship_To_Account__c = :accountIds];
            Sobject so5 = [SELECT SUM(Adjusted_Net_Invoice_Price__c) prevInvoicePrice, 
                                  SUM(Customer_Margin_CM1__c) prevCM,
                                  SUM(Quantity_Converted__c) prevVolume 
                                  from Sales_History__c 
                                  where Ship_To_Account__c = :shipToAccountList[i].Id  
                                        and Division__c != 'CATALYST' 
                                        and Previous_Year_Invoice__c = 'Y'];
           
            if (!String.isBlank(String.valueOf(so4.get('currInvoicePrice')) )) {
                shiptoAccountToUpdate.YTD_LYB_Sales__c = Decimal.valueOf(String.valueOf(so4.get('currInvoicePrice'))).setScale(2);   
            }
            if (!String.isBlank(String.valueOf(so4.get('currCM')) )) {      
                shiptoAccountToUpdate.YTD_LYB_CM1__c = Decimal.valueOf(String.valueOf(so4.get('currCM'))).setScale(2);  
            }
            if (!String.isBlank(String.valueOf(so4.get('currVolume')) )) {        
                shiptoAccountToUpdate.YTD_LYB_Volume__c = Decimal.valueOf(String.valueOf(so4.get('currVolume'))).setScale(2);
            }
            if (!String.isBlank(String.valueOf(so5.get('prevCM')))) {
                shiptoAccountToUpdate.Prior_Year_LYB_CM1__c = Decimal.valueOf(String.valueOf(so5.get('prevCM'))).setScale(2);
            }  
            if (!String.isBlank(String.valueOf(so5.get('prevVolume')) )) {  
                shiptoAccountToUpdate.Prior_Year_LYB_Volume__c = Decimal.valueOf(String.valueOf(so5.get('prevVolume'))).setScale(2);   
            }
            if (!String.isBlank(String.valueOf(so5.get('prevInvoicePrice')) )) { 
                shiptoAccountToUpdate.Prior_Year_LYB_Sales__c = Decimal.valueOf(String.valueOf(so5.get('prevInvoicePrice'))).setScale(2);
            }
            lShiptoAccountsToUpdate.add(shiptoAccountToUpdate);
            }
            }

        }
            update lShiptoAccountsToUpdate;
            update lAccountsToUpdate;
    }  

    global void finish(Database.BatchableContext BC)
    {

    }

}
global Class CongaImpl{

     static String version = '/services/Soap/u/39.0/';
     static String partnerUrl = Url.getSalesforceBaseUrl().toExternalForm()+version+UserInfo.getOrganizationId().subString(0,15);  
     static String congaUrl;
     
     Webservice static string leaseAgreementDocument(String recordId) {
    //  string queid='[Borrower]Label.Borrower_details,[Amortization]Label.Amortization_details,[Equipment]Label.Equipment_Details&TemplateId=Label.Hyphecation_agreement';
    //   System.debug('>>##Lease_Agreement_letter#:'+getQerystring('Lease_Agreement_letter'));
       //[Borrowersdetails]a0p5D000000D7Ce Lease_Agreement_letter
     // congaUrl=Label.Conga_URL+userinfo.getsessionId()+'&serverUrl='+partnerUrl+'&QueryId='+getQerystring('Lease_Agreement_letter')+'&DS7=1&OFN='+bName.deleteWhitespace()+'_LA&id='+recordId.subString(0,15);
        congaUrl = Label.Conga_URL+userinfo.getsessionId()+'&serverUrl='+partnerUrl+'&Id='+recordId+'&QueryId=[LA]a8G1k0000004KsR,[EQ]a8G1k0000004KsW&TemplateId=a8O1k0000008dpp&DefaultPDF=1' ;
        
        System.debug('congaUrl'+congaUrl);
        return getCalloutToConga(congaUrl);
     }
     
     public static String getCalloutToConga(String url) {
        system.debug('## URL ::'+url);
        // Instantiate a new http object
        Http h = new Http();

        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod('GET');
        req.setTimeout(60000);
        // Send the request, and return a response
        try{
            HttpResponse res = h.send(req);
            if(res.getStatusCode() != 200){
                system.debug('## status <>200'+res);
                return res.getStatus();
            } else if(!Pattern.matches('[a-zA-Z0-9]{18}',res.getBody())){
                system.debug('## status ==200'+res);
                return res.getBody();
            }

        } catch(System.CalloutException em){
            System.debug('## Callout Error message: '+em.getMessage());
        } 
        return 'Document Created successfully!!';
    }

}
This is the class. I tried to check if any of the methods are being called in any of the test classes but no luck there either. Any help would be appreciated.
 
Hi All,

I have attached the code  where I have passed the variable through contructor in Batch Apex class

I have written Batch apex with constructor and execute and written system.debug for checking.
Where it is not seeing the system.debug statement inside Execute method in debug logs.

I need help on execution method in Batch Apex.I am unaware why the execute method is not working on my side.
Apex class:
Extension_Batch  batch = new Extension_Batch(Newprdt,newRecord);
         Database.executeBatch(batch,200);
Batch Apex class:
global class Extension_Batch implements Database.Batchable<sObject>
{
 global List<B__c> Newprdt123;
 global  A__c newRecord123;   
 global Extension_Batch(List<B__c> Newprdt,A__c newRecord)
{
   //this block is working fine

    system.debug('Newprdt_batch'+Newprdt);
    system.debug('newRecord'+newRecord);
   Newprdt123 = Newprdt;
   newRecord123 = newRecord;
    system.debug('Newprdt123'+Newprdt123);
    system.debug('newRecord123'+newRecord123);
}
// Start Method
    global Database.QueryLocator start(Database.BatchableContext bc) 
    {
        system.debug('instart');
     return Database.getQueryLocator('Select id,OwnerId,IsDeleted,RecordTypeId,CreatedDate,CreatedById,LastModifiedDate, LastModifiedById  from A__c');
    }
   // Execute method
    global void execute(Database.BatchableContext BC,List<B__c> Newprdt123) 
    { 
        
       system.debug(' '+Newprdt123);  
       system.debug('newRecord123'+newRecord123); 
        
     for(B__c prdt :Newprdt123)
       {
         for(PricebookEntry pbe2 :[SELECT Id,Name,isactive,PriceBook2Id,Pricebook2.id,Product2.CurrencyIsoCode,
                                     PriceBook2.Name,PriceBook2.isactive,Product2.Name,Product2.ProductCode,
                                         Product2.family,UnitPrice,Product2.Description,product2.isactive FROM PriceBookentry 
                                         where Product2.ProductCode =:prdt.Name and isactive=true
                                         and Pricebook2.id=:newRecord123.PriceList__c])
           {
            if( prdt.List_Price_Per_Unit__c <> pbe2.UnitPrice & pbe2.Product2.ProductCode == prdt.Name)
               {
                  prdt.List_Price_Per_Unit__c = pbe2.UnitPrice;
               }
             update prdt;  
              
           }
          
                
       List<Pricebookentry> pbe3=[SELECT Id,Name,isactive,PriceBook2Id,Product2.ProductCode,PriceBook2.Name,PriceBook2.isactive,Product2.Name,
                                         Product2.family,Product2.Description,Unitprice,product2.isactive FROM PriceBookentry 
                                         where Product2.ProductCode =:prdt.Name and isactive=false and Pricebook2.id=:newRecord123.PriceList__c];
       
           if(pbe3.size() ==1)
           {
          for(Pricebookentry pbe1:pbe3)
          {
                            
       List<B__c> stpr =[Select id,IsDeleted,Product__r.id,Name,CreatedDate,CreatedById,LastModifiedDate,LastModifiedById,SystemModstamp,LastActivityDate From B__c 
                                   where Number1__c=:newRecord123.id and Name=: pbe1.product2.ProductCode];
              
            
              delete stpr;
         
          }
       }
           
       }
    }       
    // Finish Method
    global void finish(Database.BatchableContext BC) 
    {
       system.debug('Batch apex completed');
    }

}
Thanks in advance.
Sumitha P
 
  • September 24, 2019
  • Like
  • 0
Apex Class:

public class mergeAccount {
    
    public List<wrapAccount> wrapAccountList {get; set;}
    public List<wrapAccount> selectedAccounts{get;set;}
    public Boolean bolvar {get; set;}
    public Boolean bolvar1{get;set;}
    public Boolean bolvar2{get;set;} 
    public Boolean bolvar3{get;set;} 
    public String SelectAccount{get;set;}
    public Account objMasterAccount {get;set;}
    public List<SelectOption> lstSelectOption {get;set;}
    public String AccountId;
    public Account objAccount;
    public string AccountName ;
    public ID AccountID1;
    public List<Account> lstAccount = new List<Account>();
    public List<Account> lstAccount1 = new List<Account>();
    public mergeAccount(ApexPages.StandardController controller) {
        
        system.debug('lstAccount'+lstAccount);
        bolvar1 = true;
        bolvar2 = false;
        //objAccount= (Account)Controller.getRecord().id;
        system.debug('objAccount'+objAccount);
        
        if(wrapAccountList == null) {
            wrapAccountList = new List<wrapAccount>();
            Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap();
            String query='select id';
            for(String s : objectFields.keySet()) {
                if(s != 'Id'){
                    SObjectField test=objectFields.get(s); 
                    //system.debug('test' +test);
                    //if(test.getDescribe().isUpdateable()){ 
                    query += ', ' + s + ' ';
                }
                //}
            }
            
            query +=' FROM Account';
            System.debug(query);
            List<Account> lstAccount = new List<Account>();
            lstAccount = database.query(query);
            //System.debug(lstAccount);
            for(Account a: lstAccount) {
                wrapAccountList.add(new wrapAccount(a,bolvar));
                
                
            }
        }
    }
    
    public void getAccountNames() {
        system.debug('AccountId'+AccountId);
        /*AccountId=Apexpages.currentpage().getParameters().get('id');
        lstAccount1 =[Select id,name from Account where id =:AccountId];
        if(lstAccount1.size()>0)
        {
            AccountName =  lstAccount1[0].Name;
            AccountID1 = lstAccount1[0].id;
            system.debug('AccountName'+AccountName);
        }*/
        
        system.debug('AccountId'+AccountId);
        // selectedAccounts = new List<wrapAccount>();
        lstSelectOption= new List<SelectOption>();
        lstSelectOption.add( new SelectOption('','--Select--'));
        for( wrapAccount wrapacc :  selectedAccounts) {
            lstSelectOption.add( new SelectOption(wrapacc.acc.Id,wrapacc.acc.name));
            
            //lstSelectOption.add(new SelectOption(AccountID1,AccountName));
            system.debug('accOptions'+lstSelectOption);
        }
        
    }
    
    public void nextButton(){
        selectedAccounts = new List<wrapAccount>();
        
        for(wrapAccount wrapAccountObj : wrapAccountList) {
            if(wrapAccountObj.selected == true) {
                selectedAccounts.add(new wrapAccount(wrapAccountObj.acc,wrapAccountObj.selected));
                
            }
        }
        getAccountNames();
        bolvar1 = false;
        bolvar2 = true;
        
    }
    
    public PageReference  Selectedmaster(){
        objMasterAccount = new Account();
        objAccount = new Account();
        SobjectField[] fields =  Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().values();
        System.debug(fields);
        for(wrapAccount wrapacc :selectedAccounts){
            if(wrapacc.acc.id == SelectAccount)
                objMasterAccount = wrapacc.acc;
            //AccountID1 = wrapacc.accId;
            system.debug('objMasterAccount'+objMasterAccount);
        }
        for( wrapAccount wrapacc :selectedAccounts){
            if(wrapacc.acc.id != SelectAccount){
                for(SObjectField field:fields){  
                    if(field.getDescribe().isUpdateable()){   
                        system.debug('masterLead.get(field)'+objMasterAccount.get(field));
                        if(objMasterAccount.get(field)==null && wrapacc.acc.get(field)!=null ){     
                            objMasterAccount.put(field,wrapacc.acc.get(field));
                        }
                    }
                }
            }
        }
        update objMasterAccount;
        bolvar3 = false; 
        PageReference pageRef = new PageReference('/apex/PopUp');
        pageRef.setRedirect(true);
        return pageRef;
    }
    
    public PageReference ok(){
        PageReference pageRef = new PageReference('/001/o');
        pageRef.setRedirect(true);
        return pageRef; 
    }
    
    public class wrapAccount {
        public Account acc {get; set;}
        public Boolean selected {get; set;}
        //public id accId {get;set;}
        public wrapAccount(Account a,Boolean bolvar) {
            acc = a;
            selected = bolvar;
            //accId = aId;
        }
    } 
}



Test Class
@isTest
public class mergeAccountTest {
    
    public static testmethod void AccountMergeTest(){
        Map<string, schema.RecordTypeInfo> rtMap = Schema.SObjectType.Account.getRecordTypeInfosByName();
        Id VV=rtMap.get('VV').getRecordTypeId();
        Id MVS=rtMap.get('MVS - Remind A Pet').getRecordTypeId();
        Id VVR=rtMap.get('VVR').getRecordTypeId();
        Id VVANDVVR=rtMap.get('VV and VVR').getRecordTypeId();
        
        
        Account objAccount = new Account();
        objaccount.Name = 'Test';
        objaccount.RecordTypeId =VV;
        insert objAccount;
        
        PageReference pageRef = Page.PopUp;
        Test.setCurrentPage(pageRef);
        
        
        ApexPages.StandardController sc = new ApexPages.standardController(objAccount);
        mergeAccount controller = new mergeAccount(sc);
        Account objacc = new Account();
        Boolean selected = true; 
        controller.bolvar3 = true;
        controller.SelectAccount ='26551025862uiyty';
        
        mergeAccount.wrapAccount wrrap = new mergeAccount.wrapAccount(objacc,selected);
        
        
        controller.nextButton();
        controller.getAccountNames();
         PageReference objPageRef1 = controller.ok();
          for(mergeAccount.wrapAccount wrp : controller.selectedAccounts )
            {
                wrp.selected = true;
            }            
 
        PageReference objPageRef = controller.Selectedmaster();
       
    }
    
}
List<OpenActivity> openList=  new List<OpenActivity>();
for(OpenActivity oA :OpenActivitieslist){
                                oA.OwnerId=''012200000000MqA';
                                openList.add(oA);
                        } 

    Update openList;

While I am trying to upade it is showing error as "Field is not writeable: OpenActivity.OwnerId"

Any help is highly appreciated:)

Thanks,
Jay
Background : I need access account records in the apex class where name contains %

For example, the query should return below accounts
abcd10%
cdcd40%abcd
10%volume

When i execute below query i am getting results in the workbench
select id,name from Account where Name LIKE '%\%%'


the same query If I execute in Anonymous window/apex execute getting no results

 

need to devlope query on Opportunity for  id,name,stage & Oppounitylineitem for id,name & OpportunityContactRole for phone,email in a single query for this objects and this fields to be inserted in other custom object

i have devlope this query 
select id,name, (select id,name from OpportunityLineItems), (Select id from OpportunityContactRoles) from Opportunity 

but unale to insert records in my custom object:-
my cutstom obejct Name :- myobject__c
fields in that :- Oppid__c,Oppname__c,Productid__c,ProductName__c,Phone__c,Email__c need to insert in this object

can anyone please help me for to achive this requiremnt

I have a requirement that I have to fetch all the Account Lookup fields.I'm using Schema.DisplayType for fetching Text,Picklistlist fields.But for lookup fields I don't know how to fetch.Can anyone help me?
Hi All,
I am trying to identify field access of an object and used SELECT Id, Field, SObjectType, PermissionsRead, PermissionsEdit FROM FieldPermissions where SObjectType='Contact' this SOQL query. But Name field is missing in the result.
Can somebody help me to identify root cause for the above issue?

Thanks,
Sachin
          String pvd = apexpages.currentpage().getparameters().get('pv');

         Pl_target_c target =[Select Name from Pl_target_c where Id=:Id.valueOf(pvd) LIMIT 1];
 
Hi,
I have a scenario where i have a batch class. Once batch job is done I need to send an email to specific email id with excel file. This excel file should contain all the records that got failed in the batch job along with error message. Please suggest.
I have one dropdown with values"text,radio,multiselect,numeric".
My question is when I select text from dropdown  I should get text and when radio selected radio button should appear.How can i achieve this?