• Subhasini Bhosal 6
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 4
    Replies
HI ,
I have written written apex class to create a case and return a case by Id using REST API and JSON.I am not sure how to use REST API to update a Case record by passing the the updated value in JSON format. For instance if I want to update the priority of an existing case from High to Low. Can somebody help on this?


-------------------------------------------
@RestResource(urlMapping='/Case/*')

global with sharing class CaseCreater {
 @HttpGet
    global static Case getCaseById() {
        RestRequest req = RestContext.request;        
            String caseId = req.requestURI.substring(
                                      req.requestURI.lastIndexOf('/')+1);
        Case result =
                       [SELECT  Status,Origin from Case where  Id = :caseId];
        return result;
    }
    @HttpPost
    global static String createCase(String priority,String type, String status,
        String origin,String reason, String subject, String description ) {
        Case c = new Case(
         
            Priority=priority,
            Type= type,            
            Status=status,
            Origin=origin,
            Reason=reason,
            Subject=subject,
            Description=description          
                            );
        insert c;
        return c.Id;
    }
}
//SELECT  Status,Origin,priority,Product__c,Type,Reason,
//Subject,Description,account.name,case.contact.name from Case where status='New'

 
Any idea on how to display two tables on a vf page and compare each row of the two tables and display the output as matched or not matched on click of a button ?In the second table there should be a flag column that should be updated with true or false if any of the rows from two table match.

Thanks
Any idea on how to display two tables on a vf page and compare each row of the two tables and display the output as matched or not matched on click of a button ?In the second table there should be a flag column that should be updated with true or false if any of the rows from two table match..
User-added image
here when I input unit price and quantity total price should populate automatically.

Thanks in advance!!
Any idea on how to display two tables on a vf page and compare each row of the two tables and display the output as matched or not matched on click of a button ?In the second table there should be a flag column that should be updated with true or false if any of the rows from two table match..
I have developed a Visualforce page which contains two dropdownsWill show all Objects in my organisation.
​Will show all fields based on selection of objects.​I can multiselect fields from second dropdown, and a SELECT query is generated.
I have fetched all deatil records of those fields but I am not able to display those records on Visualforce Page as the data is Dynamic, every time you choose different object their corresponding fileds I need to display different columns,thier records. 
Please help me to sort this problem.


Visualforce Code:


<apex:page controller="CustomWorkbench">
  <apex:form >
     <apex:pageBlock >
         <apex:outputLabel value="Choose Object : "></apex:outputLabel>
                  <apex:selectList value="{!AllObjectsList}" size="1" onchange="change()">
                      <apex:selectOptions value="{!AllObjects}">
                      </apex:selectOptions>
                  </apex:selectList>
              
                  <apex:actionFunction name="change"  action="{!getAllFields}" reRender="fields1" status="Loading"/><br/>
                  <apex:actionStatus id="Loading" startText="Loading..."></apex:actionStatus>
    
     </apex:pageBlock>
     <apex:pageBlock id="fields1">
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <b><apex:OutputText value="Select {!AllObjectsList} Fields : "></apex:OutputText></b>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <apex:selectList value="{!CorrespondingFields}"  size="5" multiselect="true"> 
             <apex:selectOptions value="{!fieldNames}" >
             </apex:selectOptions>
         </apex:selectList><br/><br/>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        
         <apex:commandButton value="Generate Query" action="{!DisplayRecords}" status="Loading" reRender="showrecords,querytextarea"/><br/>
      
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
         <apex:inputTextarea disabled="true" value="{!query1}" rows="2"  cols="100" id="querytextarea"/>
     </apex:pageBlock>
     <apex:pageBlock id="showrecords" rendered="true">
         
        <!--<apex:pageBlockTable value="{!DisplayRecords}" var="fields">
            
             <apex:repeat value="{!fieldNameToString}" var="dynamicfields">
               <apex:column value="{!fields[dynamicfields]}" />
             </apex:repeat>
         </apex:pageBlockTable>-->
     </apex:pageBlock>
  </apex:form>
</apex:page>

Apex Code:

public with sharing class CustomWorkbench {

    public List<sObject> recordlist { get; set; }
    public String query1 { get; set; }
    public List<String> fieldNameToString { get; set; }
    public List<SelectOption> fieldNames{get; set;}
    public String CorrespondingFields{ get; set; }
    public String AllObjectsList { get; set; }
    
    public class innerWrapperClass{
        List<String> SelectedFieldsName { get; set; }
    }
       
    public PageReference DisplayRecords() {
        if(CorrespondingFields != null){
            integer length = CorrespondingFields.length();
            CorrespondingFields= CorrespondingFields.substring(1,length-1);
            String[] separate = CorrespondingFields.split(',\\s*');
            query1 = 'Select ' + CorrespondingFields + ' from ' + AllObjectsList;
            try{
                recordlist = Database.query(query1);
            }
            catch(Exception es){
                ApexPages.addMessages(es);
            }
            System.debug('recordlist ' + recordlist );
            System.debug('query1 '+query1 );
        }
        return null;
    }
    
    public void getAllFields() {
        System.debug('all AllObjectsList' + AllObjectsList);
        fieldNameToString = new List<String>();
        fieldNames = new List<SelectOption>();
        if(AllObjectsList != null){
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Schema.SObjectType ObjectSchema = schemaMap.get(AllObjectsList);
            Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
            
            for(String fieldName: fieldMap.keySet()) {  
                fieldNames.add(new SelectOption(fieldName,fieldName));
                fieldNameToString.add(fieldName);
                //fieldNameToString = (List<String>)fieldNames;
            }
        }
        System.debug('all fields' + fieldNames);
        System.debug('fieldNameToString' + fieldNameToString);
    }

    public List<SelectOption> getAllObjects() {
        List<Schema.sObjectType> gd = Schema.getGlobalDescribe().Values();
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('','--------Select--------'));
        for(Schema.sObjectType gd1 : gd){
            options.add(new SelectOption(gd1.getDescribe().getName(),gd1.getDescribe().getName()));
        }
        options.sort();
        return options;
    }

    /*public List<sObject> getDisplayRecords() {
        if(CorrespondingFields != null){
            integer length = CorrespondingFields.length();
            CorrespondingFields= CorrespondingFields.substring(1,length-1);
            String[] separate = CorrespondingFields.split(',\\s*');
            System.debug('separate :' + separate[0] );
            query1 = 'Select ' + CorrespondingFields + ' from ' + AllObjectsList;
            recordlist = Database.query(query1);
            System.debug('recordlist ' + recordlist );
            System.debug('query1 '+query1 );
        }
        return recordlist ;
    }*/
}
Hello,
 
I have a method that returns a List<SelectOption> containing a list of months to be used in a menu on a VF page. I'm still new to writing Apex code and I can't figure out what the correct way to write the test method for this is. If I run tests on the following code I get this error:
 
 

System.Exception: Assertion Failed: Expected: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...), Actual: (System.SelectOption[value="01", label="Jan", disabled="false"], System.SelectOption[value="02", label="Feb", disabled="false"], System.SelectOption[value="03", label="Mar", disabled="false"], System.SelectOption[value="04", label="Apr", disabled="false"], System.SelectOption[value="05", label="May", disabled="false"], System.SelectOption[value="06", label="Jun", disabled="false"], System.SelectOption[value="07", label="Jul", disabled="false"], System.SelectOption[value="08", label="Aug", disabled="false"], System.SelectOption[value="09", label="Sep", disabled="false"], System.SelectOption[value="10", label="Oct", disabled="false"], ...)

 

 

public class Months {

public List<SelectOption> getMonthList() {

List<SelectOption> options = new List<SelectOption>();

options.add(new SelectOption('01', 'Jan'));

options.add(new SelectOption('02', 'Feb'));

options.add(new SelectOption('03', 'Mar'));

options.add(new SelectOption('04', 'Apr'));

options.add(new SelectOption('05', 'May'));

options.add(new SelectOption('06', 'Jun'));

options.add(new SelectOption('07', 'Jul'));

options.add(new SelectOption('08', 'Aug'));

options.add(new SelectOption('09', 'Sep'));

options.add(new SelectOption('10', 'Oct'));

options.add(new SelectOption('11', 'Nov'));

options.add(new SelectOption('12', 'Dec'));

return options;

}

 

static testMethod void testMonthList() {

List<SelectOption> test_options = new List<SelectOption>();

test_options.add(new SelectOption('01', 'Jan'));

test_options.add(new SelectOption('02', 'Feb'));

test_options.add(new SelectOption('03', 'Mar'));

test_options.add(new SelectOption('04', 'Apr'));

test_options.add(new SelectOption('05', 'May'));

test_options.add(new SelectOption('06', 'Jun'));

test_options.add(new SelectOption('07', 'Jul'));

test_options.add(new SelectOption('08', 'Aug'));

test_options.add(new SelectOption('09', 'Sep'));

test_options.add(new SelectOption('10', 'Oct'));

test_options.add(new SelectOption('11', 'Nov'));

test_options.add(new SelectOption('12', 'Dec'));

 

Months my_months = new Months();

List<SelectOption> method_options = my_months.getMonthList();

 

system.assertEquals(method_options, test_options);

}

}

 

I copied/pasted the 'expected' and 'actual' responses to a text editor and they look identical to me. Is there another way I should be writing this test?
 
Thanks,
Dan 
 
 
 
 
  • June 30, 2009
  • Like
  • 0