• Lightning Warrior
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I am calling tooling api from my Queueable apex to get information of flow object from my org and scheduling it on daily basis. Now my problem is when I run my code from anonymous window with Authorization header set to 'Bearer '+Userinfo.sessionId(), It works fine. But when i schedule it, it returns error saying :"Session expired or invalid","errorCode":"INVALID_SESSION_ID". I think the reason is scheduler runs in system context and in that case Userinfo.sessionId() is returned as null. So is there any way to make tooling api callouts from scheduler or Queueable? Here is my code-
String endpoint = 'https://lightningwarrior-dev-ed.my.salesforce.com/services/data/v37.0/tooling/query?q=Select+Id,processtype,Description,LastModifiedDate,MasterLabel,Status,LastModifiedById,VersionNumber+From+Flow';

HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('GET'); 
req.setHeader('Content-Type', 'application/json');
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());

Http httpreq = new Http();
HttpResponse res = httpreq.send(req);
String reqresponse = res.getBody();
system.debug('dt'+reqresponse);
jsonHelperClass jsonres =  new jsonHelperClass();
jsonres = (jsonHelperClass)JSON.deserialize(reqresponse ,     jsonHelperClass.Class);
public List<RecordWrapper> ListrecordsWrap=new List<RecordWrapper>();
ListrecordsWrap=jsonres.records;
system.debug('jsonres'+ListrecordsWrap[0].MasterLabel);
public class jsonHelperClass
{
    public List<RecordWrapper> records;
    public jsonHelperClass()
    {

    }
}
public class RecordWrapper
{
    Public String Id;
    Public String ProcessType;
    Public String Description;
    Public String MasterLabel;
    Public String Status;
    Public Integer VersionNumber;
    public Id LastModifiedById;
    public Datetime LastModifiedDate;
    public RecordWrapper()
    {
    }
}
Thanks.
 
I have formula field on contact object. Now I don't want that field on contact, instead i am pulling same information from user and want to store it in same field. As i have used that formula field in various places like vf pages, apex classes, workflows etc. Is there any way we can change field type of that formula field? Any other solution for my problem?
Thanks.
I have formula field on contact object. Now I don't want that field on contact, instead i am pulling same information from user and want to store it in same field. As i have used that formula field in various places like vf pages, apex classes, workflows etc. Is there any way we can change field type of that formula field? Any other solution for my problem?
Thanks.