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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 9
    Replies
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);
           }
        }
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);
           }
        }