• Rakesh M 20
  • NEWBIE
  • 65 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 13
    Replies
Hi Folks,
How can create validation rule for this using Custom External Id 
Please help me
Hi Folks
How do i  get this..?
Please help me with solution/suggestion..


Thanks in Advance
Hi Folks,
Can anyone Please help me to implement search bar for selecting Account records and displaying the records  without button in aura component..




thanks in advance
Hi Folks,
Please help to write SOQL Query for this







Thanks in advance
Hi Folks,
Can Anyone tell me How can achive this Please..

I need to do this "Batch Class" Not in Trigger

My Requirement
--------------------------------------
-> Create new field on Opportunity 
Status (picklist) (Values: New, Closed)

-> This batch class will run on Every 6th day of month
Process only not closed Opportunity.

-> If the Opportunity Type is “New Customer” create new Account and create new Order for the Opportunity 
and create Order Items and update Account reference on Opportunity back
The  Order Items copied from Products that related to  Opportunity 

-> If the Opportunity Type is other than “New Customer” create new Order for the Opportunity and 
create Order Items.Order Items copied from Products that related to  Opportunity

My code
----------------------------------

public class OpportunityToAccountBatchClass implements Database.Batchable<sObject> {
    //Start Method
    public Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query ='select id,AccountId,Name,Type,Pricebook2Id,CloseDate,Status__c from Opportunity where Status__c != \'%Closed%\'';
        return Database.getQueryLocator(query);
    }  
    //Execute Method
    public void execute(Database.BatchableContext BC,List<Opportunity> oppList)
    {
        Map<Opportunity, Account> accountMap = new Map<Opportunity,Account>();
        Map<Opportunity, Order> orderMap = new Map<Opportunity,Order>();
        for(Opportunity opp: oppList){
            if( opp.Type=='New Customer')
            {
                System.debug('Opp Records --> '+oppList);
                //Account Creation
                Account acc = new Account();
                acc.Name = opp.Name;
                accountMap.put(opp,acc);
                //Order Creation
                Order ord = new Order();
                ord.Name=opp.Name;
                ord.OpportunityId=opp.Id;
                ord.Status= 'Draft';
                ord.AccountId=acc.Id;ord.EffectiveDate=opp.CloseDate;
                orderMap.put(opp,ord);
            }
        }
        if(!accountMap.values().isEmpty()){
            insert accountMap.values();
            System.debug('Acount records '+accountMap.values());
        }
        if(!orderMap.values().isEmpty()){
            insert orderMap.values();
        }
        for(Opportunity opp : oppList){
            opp.AccountId = accountMap.get(opp).Id;
        }
        if(!oppList.isEmpty()){
            update oppList;
        }   
    }
    
    //Finish Method
    public void finish(Database.BatchableContext BC)
    {
        
    }    
}


Thanks in Advance
Hi Folks,
Plese help me to do this in " Batch Class " not trigger.
My code :
public class OpportunityToAccountBatchClass implements Database.Batchable<sObject> {
    //Start Method
    public Database.QueryLocator start(Database.BatchableContext BC)
    {
        return Database.getQueryLocator('select id,AccountId,Name,Type from Opportunity where Status__c != \'Closed\'');
    }
    
    //Execute Method
    public void execute(Database.BatchableContext BC,List<Opportunity> oppData)
    {
        Map<Id, List<Opportunity>> mapOppIdToAccOrd = new Map<Id, List<Opportunity>>(); 
        Set<Id> oppId = new Set<Id>(); 
        List<Account> accList = new List<Account>(); 
        List<Order> orderList = new List<Order>();
        List<Opportunity> updateAccRefToOpp = new List<Opportunity>();
        for(Opportunity opp : oppData)
        {
            if(String.isNotBlank(opp.AccountId) && opp.Type=='New Customer') {
                if(!mapOppIdToAccOrd.containsKey(opp.AccountId)) {
                    mapOppIdToAccOrd.put(opp.AccountId, new List<Opportunity>());
                }
                mapOppIdToAccOrd.get(opp.AccountId).add(opp); 
                oppId.add(opp.AccountId);
            }
             if(oppId.size()>0)
            {
              accList.add(New Account(Name=opp.Name+'-'+'Account'));  
            } 
        }
        if(accList.size()>0)
        {
            insert accList;
            for(Account acc : accList)
            {
                for(Opportunity op : oppData)
                {
               if(!mapOppIdToAccOrd.containsKey(op.AccountId) && op.Type=='New Customer')
                  {
                   op.AccountId=acc.Id;
                   updateAccRefToOpp.add(op);
                  }
                  }
            }
            update updateAccRefToOpp;
        } 
    }
    
    //Finish Method
    public void finish(Database.BatchableContext BC)
    {
        
    }    
}




Thanks in Advance
I am Trying to Perform Mathoperations in Calculator but its not working,can anyone help me to fix this issue.
Here's My code
VF Page
<apex:page controller="Caluclator">
   <script type="text/javascript">
 function textFunc() 
 {
 var num1 = document.getElementById('n1').value;
 var num2 = document.getElementById('n2').value;
 
     String op;
 
 Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.Caluclator.showText}', num1,num2,op,
 function(result, event)
 {
     debugger;
 if(event.status) 
 {
 // This is the way to get VF tag id to map result returned from call back function parameter result
 
 document.getElementById("{!$Component.pb.pbs.pbsi.numone}").innerHTML = result
 System.debug('Result--'+result);
 }
{escape: true}
 }); 
 }
 </script>
 Number 1 :<input id="n1" type="Number" />
 Number 2 :<input id="n2" type="Number" />
 <button type="button" onclick="textFunc('add')">Add</button>
 <button type="button" onclick="textFunc('sub')">Sub</button>
 <button type="button" onclick="textFunc('mul')">Mul</button>
 <button type="button" onclick="textFunc('div')">Div</button>
 <button type="button" onclick="textFunc('mod')">Mod</button>
 <button type="button" onclick="textFunc('perc')">Perc</button>
 <apex:pageBlock id="pb">
 <apex:pageBlockSection id="pbs">
 <apex:pageBlockSectionItem id="pbsi">
 <apex:outputText id="numone"/>   
     </apex:pageBlockSectionItem> 
     </apex:pageBlockSection>
 </apex:pageBlock>
</apex:page>

Controller :
public class Caluclator {
    Public Integer num1 {get;set;}
    Public Integer num2 {get;set;}
    Public String fun {get;set;}
    
    @RemoteAction
    public static Integer showText(Integer num1,Integer num2,String fun) 
    {           integer result=0;
          //return num1 + num2;  
          if(fun == 'add')
        {
            result = num1 + num1;
        }
        else if(fun == 'sub')
        {
             result = num1 - num1;
        }
         else if(fun == 'mul')
        {
             result = num1 * num1;
        }
        else if(fun == 'div')
        {
             result = num1 / num1;
        }
         else if(fun == 'mod')
        {
             result =  math.mod(Integer.valueOf(num1) , Integer.valueOf(num2));    
        }
         else if(fun == 'perc')
        {
            result = (num1/num2) * 100;
        }
     
        return result;
    }
}
public class WorkBenchControllerClass {
     public String obj;
    public List<String> objFields {get;set;}
    
    public WorkBenchControllerClass() 
    {    
    }
    public String getobj()
    {
        return obj;
    }
     public void setobj(String obj)
    {
        this.obj = obj;
    } 
    
//Fetching Sobjects
public List<SelectOption> getobjectnames()
{
    Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    System.debug('globaldesc values--> '+schemaMap);
    List<SelectOption> options=new List<SelectOption>();
    options.add(new SelectOption('None','None'));
    for(Schema.SObjectType objType : schemaMap.values())
    {
    options.add(new SelectOption(objType.getDescribe().getName(),objType.getDescribe().getName()));
    }
    return options;
}
 
//Fetching Fields
 public List<SelectOption> fetchFields()
    { 
        List<SelectOption> allfields=new List<SelectOption>();
        List<String> fields = new List<String>();
        Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
        System.debug('Selected Object is ' + obj);
        Schema.sObjectType objType = globalDescription.get(obj); 
        System.debug('Object Type is ' + objType);
        Schema.DescribeSObjectResult r1 = objType.getDescribe(); 
        
        Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();  

        for(Schema.SObjectField field : mapFieldList.values())  
        {  
            Schema.DescribeFieldResult fieldResult = field.getDescribe();  
            
            if(fieldResult.isAccessible())  
            {  
                System.debug('Field Name is ' + fieldResult.getName());
                //fields.add(fieldResult.getName());
                allfields.add(new SelectOption(fieldResult.getName(),fieldResult.getName()));
            }  
        }
        return allfields;
             
    }   
}
I Tried PageReference also but its not working because.it should return list of fields.
Please Help Me to fix this error
Query
Select Id,History_Id__c,Candidate_Id__c,Name,New_Value__c,Old_Value__c,Operation_type__c from Candidates_History__c where New_Value__c != Old_Value__c;
    }
Error :
FATAL_ERROR System.QueryException: expecting a colon, found 'Old_Value__c'
Please Help me to fix this issue
 
Example : this is my map with list of sObject
Map<Id,List<Product_Stock__c>> updateProductStock = new Map<Id,List<Product_Stock__c>>();

Fields required to add a map :
id and available_qty
fileds :
Status
partsorderlines

I can update the status from Draft to Open only if there are parts order lines. If no lines are associated with should get a validation error saying “this action can’t be performed”
@RestResource(urlMapping='/v1/BookDetails/')
global class bookManager 
{
@httpGet
global static Book__c doGetBook()
{
    Book__c book = new Book__c();
    Map<String,String> paramsMap = RestContext.request.params;
    String bookId = paramsMap.get('Id');
    book = [select Id, Name, Price__c from Book__c where Id IN =: bookId]; // getting sytax error in this line
    return book;
}
}
My Requirements
---------------------------------------------
Status change from New -> Working. 
Update Account case Status to In Progress
Note: Check if any other case is still in the new status. Don’t update.

my code
---------------------------------
public static void updatenewtoworking(List<Case> data)
    {
       Set<Id> acid = new Set<Id>();
        List<Account> aclist = new List<Account>();
        Map<Id,List<Case>> maplist = new Map<Id,List<Case>>();
        for(Case c : data)
        {
         if(c.Status=='Working' && c.AccountId !=null)
         {
             if(!maplist.containsKey(c.AccountId))
             {
             maplist.put(c.AccountId, new List<Case>());
             }
            maplist.get(c.AccountId).add(c);
            acid.add(c.AccountId);
             System.debug('acid id-------'+acid);
        }
        }
        if(acid.size()>0)
        {
          aclist = [select id,Case_Status__c from Account where Id IN : acid];
            System.debug('-----queries result'+aclist);
            for(Account acc : aclist)
            {
                if(maplist.containsKey(acc.Id))
                {
                    acc.Case_Status__c ='In Progress';
                }
            }
            if(aclist.size()>0)
            {
            update aclist;
                System.debug('-----------SECOND CONDTION'+aclist);
            }
        }
    }
its working for only one record not for multiple records so can anyone help me to find out the solution.

thanks in advance
Integer Month = Date.Today().Month();
        Integer Year = Date.Today().Year();
        Integer numberDays = date.daysInMonth(Year, Month);
        System.debug('Number of Days In Month--' +numberDays);
        
        Date d = System.today();
        Datetime dt = (DateTime)d;
        String dayOfWeek = dt.format('EEEE');
        Integer numberofdays;
        for(Integer i=0;i<numberofdays;i++)
        {
        if(dayOfWeek=='Saturday' || dayOfWeek=='Sunday')
           {
              numberofdays=numberDays--;
               System.debug('Number of Days After removing Weekends -- '+numberofdays);
           }
        }
Hi Folks,
Can anyone Please help me to implement search bar for selecting Account records and displaying the records  without button in aura component..




thanks in advance
Hi Folks,
Can Anyone tell me How can achive this Please..

I need to do this "Batch Class" Not in Trigger

My Requirement
--------------------------------------
-> Create new field on Opportunity 
Status (picklist) (Values: New, Closed)

-> This batch class will run on Every 6th day of month
Process only not closed Opportunity.

-> If the Opportunity Type is “New Customer” create new Account and create new Order for the Opportunity 
and create Order Items and update Account reference on Opportunity back
The  Order Items copied from Products that related to  Opportunity 

-> If the Opportunity Type is other than “New Customer” create new Order for the Opportunity and 
create Order Items.Order Items copied from Products that related to  Opportunity

My code
----------------------------------

public class OpportunityToAccountBatchClass implements Database.Batchable<sObject> {
    //Start Method
    public Database.QueryLocator start(Database.BatchableContext BC)
    {
        String query ='select id,AccountId,Name,Type,Pricebook2Id,CloseDate,Status__c from Opportunity where Status__c != \'%Closed%\'';
        return Database.getQueryLocator(query);
    }  
    //Execute Method
    public void execute(Database.BatchableContext BC,List<Opportunity> oppList)
    {
        Map<Opportunity, Account> accountMap = new Map<Opportunity,Account>();
        Map<Opportunity, Order> orderMap = new Map<Opportunity,Order>();
        for(Opportunity opp: oppList){
            if( opp.Type=='New Customer')
            {
                System.debug('Opp Records --> '+oppList);
                //Account Creation
                Account acc = new Account();
                acc.Name = opp.Name;
                accountMap.put(opp,acc);
                //Order Creation
                Order ord = new Order();
                ord.Name=opp.Name;
                ord.OpportunityId=opp.Id;
                ord.Status= 'Draft';
                ord.AccountId=acc.Id;ord.EffectiveDate=opp.CloseDate;
                orderMap.put(opp,ord);
            }
        }
        if(!accountMap.values().isEmpty()){
            insert accountMap.values();
            System.debug('Acount records '+accountMap.values());
        }
        if(!orderMap.values().isEmpty()){
            insert orderMap.values();
        }
        for(Opportunity opp : oppList){
            opp.AccountId = accountMap.get(opp).Id;
        }
        if(!oppList.isEmpty()){
            update oppList;
        }   
    }
    
    //Finish Method
    public void finish(Database.BatchableContext BC)
    {
        
    }    
}


Thanks in Advance
Hi Folks,
Plese help me to do this in " Batch Class " not trigger.
My code :
public class OpportunityToAccountBatchClass implements Database.Batchable<sObject> {
    //Start Method
    public Database.QueryLocator start(Database.BatchableContext BC)
    {
        return Database.getQueryLocator('select id,AccountId,Name,Type from Opportunity where Status__c != \'Closed\'');
    }
    
    //Execute Method
    public void execute(Database.BatchableContext BC,List<Opportunity> oppData)
    {
        Map<Id, List<Opportunity>> mapOppIdToAccOrd = new Map<Id, List<Opportunity>>(); 
        Set<Id> oppId = new Set<Id>(); 
        List<Account> accList = new List<Account>(); 
        List<Order> orderList = new List<Order>();
        List<Opportunity> updateAccRefToOpp = new List<Opportunity>();
        for(Opportunity opp : oppData)
        {
            if(String.isNotBlank(opp.AccountId) && opp.Type=='New Customer') {
                if(!mapOppIdToAccOrd.containsKey(opp.AccountId)) {
                    mapOppIdToAccOrd.put(opp.AccountId, new List<Opportunity>());
                }
                mapOppIdToAccOrd.get(opp.AccountId).add(opp); 
                oppId.add(opp.AccountId);
            }
             if(oppId.size()>0)
            {
              accList.add(New Account(Name=opp.Name+'-'+'Account'));  
            } 
        }
        if(accList.size()>0)
        {
            insert accList;
            for(Account acc : accList)
            {
                for(Opportunity op : oppData)
                {
               if(!mapOppIdToAccOrd.containsKey(op.AccountId) && op.Type=='New Customer')
                  {
                   op.AccountId=acc.Id;
                   updateAccRefToOpp.add(op);
                  }
                  }
            }
            update updateAccRefToOpp;
        } 
    }
    
    //Finish Method
    public void finish(Database.BatchableContext BC)
    {
        
    }    
}




Thanks in Advance
I am Trying to Perform Mathoperations in Calculator but its not working,can anyone help me to fix this issue.
Here's My code
VF Page
<apex:page controller="Caluclator">
   <script type="text/javascript">
 function textFunc() 
 {
 var num1 = document.getElementById('n1').value;
 var num2 = document.getElementById('n2').value;
 
     String op;
 
 Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.Caluclator.showText}', num1,num2,op,
 function(result, event)
 {
     debugger;
 if(event.status) 
 {
 // This is the way to get VF tag id to map result returned from call back function parameter result
 
 document.getElementById("{!$Component.pb.pbs.pbsi.numone}").innerHTML = result
 System.debug('Result--'+result);
 }
{escape: true}
 }); 
 }
 </script>
 Number 1 :<input id="n1" type="Number" />
 Number 2 :<input id="n2" type="Number" />
 <button type="button" onclick="textFunc('add')">Add</button>
 <button type="button" onclick="textFunc('sub')">Sub</button>
 <button type="button" onclick="textFunc('mul')">Mul</button>
 <button type="button" onclick="textFunc('div')">Div</button>
 <button type="button" onclick="textFunc('mod')">Mod</button>
 <button type="button" onclick="textFunc('perc')">Perc</button>
 <apex:pageBlock id="pb">
 <apex:pageBlockSection id="pbs">
 <apex:pageBlockSectionItem id="pbsi">
 <apex:outputText id="numone"/>   
     </apex:pageBlockSectionItem> 
     </apex:pageBlockSection>
 </apex:pageBlock>
</apex:page>

Controller :
public class Caluclator {
    Public Integer num1 {get;set;}
    Public Integer num2 {get;set;}
    Public String fun {get;set;}
    
    @RemoteAction
    public static Integer showText(Integer num1,Integer num2,String fun) 
    {           integer result=0;
          //return num1 + num2;  
          if(fun == 'add')
        {
            result = num1 + num1;
        }
        else if(fun == 'sub')
        {
             result = num1 - num1;
        }
         else if(fun == 'mul')
        {
             result = num1 * num1;
        }
        else if(fun == 'div')
        {
             result = num1 / num1;
        }
         else if(fun == 'mod')
        {
             result =  math.mod(Integer.valueOf(num1) , Integer.valueOf(num2));    
        }
         else if(fun == 'perc')
        {
            result = (num1/num2) * 100;
        }
     
        return result;
    }
}
public class WorkBenchControllerClass {
     public String obj;
    public List<String> objFields {get;set;}
    
    public WorkBenchControllerClass() 
    {    
    }
    public String getobj()
    {
        return obj;
    }
     public void setobj(String obj)
    {
        this.obj = obj;
    } 
    
//Fetching Sobjects
public List<SelectOption> getobjectnames()
{
    Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    System.debug('globaldesc values--> '+schemaMap);
    List<SelectOption> options=new List<SelectOption>();
    options.add(new SelectOption('None','None'));
    for(Schema.SObjectType objType : schemaMap.values())
    {
    options.add(new SelectOption(objType.getDescribe().getName(),objType.getDescribe().getName()));
    }
    return options;
}
 
//Fetching Fields
 public List<SelectOption> fetchFields()
    { 
        List<SelectOption> allfields=new List<SelectOption>();
        List<String> fields = new List<String>();
        Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
        System.debug('Selected Object is ' + obj);
        Schema.sObjectType objType = globalDescription.get(obj); 
        System.debug('Object Type is ' + objType);
        Schema.DescribeSObjectResult r1 = objType.getDescribe(); 
        
        Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap();  

        for(Schema.SObjectField field : mapFieldList.values())  
        {  
            Schema.DescribeFieldResult fieldResult = field.getDescribe();  
            
            if(fieldResult.isAccessible())  
            {  
                System.debug('Field Name is ' + fieldResult.getName());
                //fields.add(fieldResult.getName());
                allfields.add(new SelectOption(fieldResult.getName(),fieldResult.getName()));
            }  
        }
        return allfields;
             
    }   
}
I Tried PageReference also but its not working because.it should return list of fields.
Please Help Me to fix this error
Query
Select Id,History_Id__c,Candidate_Id__c,Name,New_Value__c,Old_Value__c,Operation_type__c from Candidates_History__c where New_Value__c != Old_Value__c;
    }
Error :
FATAL_ERROR System.QueryException: expecting a colon, found 'Old_Value__c'
Please Help me to fix this issue
 
Example : this is my map with list of sObject
Map<Id,List<Product_Stock__c>> updateProductStock = new Map<Id,List<Product_Stock__c>>();

Fields required to add a map :
id and available_qty
fileds :
Status
partsorderlines

I can update the status from Draft to Open only if there are parts order lines. If no lines are associated with should get a validation error saying “this action can’t be performed”
@RestResource(urlMapping='/v1/BookDetails/')
global class bookManager 
{
@httpGet
global static Book__c doGetBook()
{
    Book__c book = new Book__c();
    Map<String,String> paramsMap = RestContext.request.params;
    String bookId = paramsMap.get('Id');
    book = [select Id, Name, Price__c from Book__c where Id IN =: bookId]; // getting sytax error in this line
    return book;
}
}
My Requirements
---------------------------------------------
Status change from New -> Working. 
Update Account case Status to In Progress
Note: Check if any other case is still in the new status. Don’t update.

my code
---------------------------------
public static void updatenewtoworking(List<Case> data)
    {
       Set<Id> acid = new Set<Id>();
        List<Account> aclist = new List<Account>();
        Map<Id,List<Case>> maplist = new Map<Id,List<Case>>();
        for(Case c : data)
        {
         if(c.Status=='Working' && c.AccountId !=null)
         {
             if(!maplist.containsKey(c.AccountId))
             {
             maplist.put(c.AccountId, new List<Case>());
             }
            maplist.get(c.AccountId).add(c);
            acid.add(c.AccountId);
             System.debug('acid id-------'+acid);
        }
        }
        if(acid.size()>0)
        {
          aclist = [select id,Case_Status__c from Account where Id IN : acid];
            System.debug('-----queries result'+aclist);
            for(Account acc : aclist)
            {
                if(maplist.containsKey(acc.Id))
                {
                    acc.Case_Status__c ='In Progress';
                }
            }
            if(aclist.size()>0)
            {
            update aclist;
                System.debug('-----------SECOND CONDTION'+aclist);
            }
        }
    }
its working for only one record not for multiple records so can anyone help me to find out the solution.

thanks in advance
Integer Month = Date.Today().Month();
        Integer Year = Date.Today().Year();
        Integer numberDays = date.daysInMonth(Year, Month);
        System.debug('Number of Days In Month--' +numberDays);
        
        Date d = System.today();
        Datetime dt = (DateTime)d;
        String dayOfWeek = dt.format('EEEE');
        Integer numberofdays;
        for(Integer i=0;i<numberofdays;i++)
        {
        if(dayOfWeek=='Saturday' || dayOfWeek=='Sunday')
           {
              numberofdays=numberDays--;
               System.debug('Number of Days After removing Weekends -- '+numberofdays);
           }
        }