• María Jesús Carmona
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
Hi!
I would like to know how to deserialize a JSON response on a list (to use it later on a for).
Im trying to deserialize the response, but the result of the deserialize is always null.

The response I receive contains a list of ServiceNow incidents, on the following format:
{"result":[{"short_description":"text","sys_id":"004fbc4cdb062300d6e781cc0b961989","contact_type":"email","incident_state":"2","impact":"4","description":"text"},{"short_description":"text","sys_id":"0188096ddb45a340d6e781cc0b961971","contact_type":"email","incident_state":"2","impact":"4","description":"text"},{"short_description":"text","sys_id":"02786099db66df40d6e781cc0b96197a","contact_type":"email","incident_state":"2","impact":"4","description":"text"}]}

At the moment my code looks like this:

ServiceNowBatch
//Authentication + request done (req and res)
// (...)
List<Case> casesToUpdate = new List<Case>;
String response = res.getBody();

//Having problems here
CaseWrapper caseWrapperDes = (CaseWrapper)JSON.deserialize(response, CaseWrapper.class);
System.debug('caseWrapper content: '+caseWrapperDes);

// (...)
for (CaseWrapper SNcase : caseWrapperDes) {
	if (response.length() > 0 && response.substring(0, 5) != 'Error') {
		Case c = new Case();
		c.description = SNcase.description;
		c.origin = SNcase.contact_type;
		
		casesToUpdate.add(c);
	}
}
return casesToUpdate;
(...)

CaseWrapper
CaseWrapper
public class CaseWrapper {

    public List<resultSN> results {get; set;}

    public class resultSN {
        public String short_description {get; set;}
        public String sys_id {get; set;}
        public String contact_type {get; set;}
        public String incident_state {get; set;}
        public String impact {get; set;}
        public String description {get; set;}
    }
}

CaseWrapperList
CaseWrapperList
public class CaseWrapperList {
    public List<CaseWrapper> results;
}

I don't know what I'm missing.
Hi,
I have an Apex class that compares on some methods the current and the old value of fields.
My question is, for example, If I have an Opportunity and change its name, how can I get the old name value from the test class to compare it with the new/current one?
Thanks.
Hi,
I would like to know is there is some way to show an informative text showing the user who is watching a case record.
The reason is that I have a button that asigns the case record to the user who clicked it (only if the case is not asigned), but there are times when 2 users open it at the same time and both of them click the button.
I think a solution could be to show if someone is on that record at that time, but I dont know if there's a standard way to do that or how to achieve it.
Any ideas? (The case viewing is a Visualforce btw)
Thanks :)
Hi,
We had our report filtered by "all" (i.e. "all oportunities"), now it appear as "all oportunities under role: X".
I think that this is a change from the latest release, but we need to be able to filter by just "all" like we had before. 
Is there some way to achieve that without creating more roles?
Thanks.
Hi, I wanted to update a field on Case object when that Case's createdByID field refers a user with a profileID "x" or "y" with a static text.
I think that this can be achieved by a trigger that is fired after the Case has been inserted or updated, storing the createdById value on a variable and using it on a query, I tried that but it gives me this error "Illegal assignment from list to set ".
I let my code below:
trigger myTrigger on Case (after insert, after update) {

    Set<Id> IdUser =new Set<Id>();
    Set<Id> IdProfile =new Set<Id>();

    List<Case> caseUpdateList = new List<Case>();

    for(Case obj: Trigger.New){
                IdUser.add(obj.createdById);
                IdProfile=[SELECT Id, ProfileID FROM User WHERE User.Id=:IdUser];

        IF(IdProfile=='x' || IdProfile=='y'){
                //obj.field='created by profile x and y';
        }

        caseUpdateList.add(obj);
    }

    IF(caseUpdateList.size() > 0){
        update caseUpdateList;
    }
}
It will surelly have some code bad written, Im still pretty new to Salesforce and Apex triggers.

Maria J.
 
Hi,
We had our report filtered by "all" (i.e. "all oportunities"), now it appear as "all oportunities under role: X".
I think that this is a change from the latest release, but we need to be able to filter by just "all" like we had before. 
Is there some way to achieve that without creating more roles?
Thanks.