• Pathikrit
  • NEWBIE
  • 40 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 16
    Replies
Hello,

I am working on refactoring triggers in a certain org. For a given object CustomObject__c there are a few managed as well as unmanaged triggers. When it comes to trigger execution time, I could get the total time taken for a transaction from the debug log. The developer console Execution Overview gives a pretty good idea about which query/method etc. is more time consuming.

But, what I'm looking for is to understand how much time the trigger is taking per event. So, if there is an update on the CustomObject__c , I would like to know how much time is consumed by the Before Update trigger event and how much by the After Update trigger event.

Is there any way to get this? 

Thanks,
Pathikrit
Hello,

I was working on a custom datepicker in a visualforce that can display date in User locale. While going through some articles on the best way of implementing a datepicker with localization support I came across the JQuery Datepicker. I wanted to ensure that the datepicker displays date always in user locale. But while implementing I am unable to set the dateformat accordingly.

Here is my VF page code..
<apex:page controller="TestController" docType="html-5.0" sidebar="false">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript"> 
var userlang = window.navigator.language;
console.log(userlang);
$(function(){
    $("#datepicker").datepicker({
        formatDate:'dd-mm-yyyy',
        changeMonth:true,
        changeYear:true
    });
});

</script>
<apex:form >
<apex:pageBlock id="pgblk">
<input value="{!dateVariable}" type="text" id="datepicker"/>
</apex:pageBlock>
</apex:form>
</apex:page>
The controller doesn't have anything else than the getter & setter methods for the variable dateVariable. As you can see, I am hardcoding the format in the above code to 'dd-mm-yyyy'. But still during execution, I see the format as 'mm/dd/yyyy'. 

Can anyone help on this?

Thanks in advance!
Pathikrit
 
Hi,

I am running into this problem while writing a test class for a service which is intented to add topic to FeedTrackedChange record posted by Salesforce automatically. The idea is to put a topic to any chatter feed posted automatically for a field which is tracked in Chatter. 
List<Custom_Object__feed> listFeed =[select Id,ParentId,CreatedDate from Custom_Object__feed where ParentId in:setIds];
                List<Topic> existingTopic = [select Id, Name from Topic where Name in:mapName.Values()];
        
                for(Topic t:existingTopic){ 
                    topicNames.add(t.Name);
                    mapTopicNameIds.put(t.Name,t.Id);
                }
                
                if(!listFeed.isEmpty()){
                    for(Custom_Object__feed feed:listFeed){
                        if(!topicNames.contains(mapName.get(feed.ParentId))){
                            Topic newTopic = new Topic();
                            newTopic.Name=mapName.get(feed.ParentId);
                            setTopic.add(newTopic);
                        }
                        else{
                            TopicAssignment newAssignment = new TopicAssignment();
                            newAssignment.TopicId=mapTopicNameIds.get(maptName.get(feed.ParentId));
                            newAssignment.EntityId=feed.Id;
                            listTopicAssignment.add(newAssignment);
                        }
                    }
                    listTopic.addAll(setTopic);
        
                    Database.insert(listTopic,false); //Insert Topic
                    for(pse__Proj__feed feed:listProjectFeed){ 
                        for(Topic t:listTopic){
                            if(t.Name==mapName.get(feed.ParentId)){
                                TopicAssignment newAssignment = new TopicAssignment();
                                newAssignment.TopicId=t.Id;
                                newAssignment.EntityId=feed.Id;
                                listTopicAssignment.add(newAssignment);
                            }   
                        }
                    }
                }    
                Database.insert(listTopicAssignment,false); //Insert Assignment
The problem is in the test class, when I update a certain field on the Custom_Object__c it does not automatically post a Custom_Object__feed entry. Here is my test code.
Boolean isChatterEnabled = Schema.SObjectType.User.isFeedEnabled();
system.assert(isChatterEnabled == true,'Feed Tracking is not enabled for the user'); //Assert 1
Boolean isChatterEnabledTask = Schema.SObjectType.Custom_Object__c.isFeedEnabled();
system.assert(isChatterEnabledTask == true,'Feed Tracking is not enabled for Project Task'); //Assert 2

Custom_Object__c c = new Custom_Object__c(Name='test');
insert c;

c.Status__c = 'In progress';
update c;


List<Custom_Object__feed> listTaskFeed = [select Id,parentId from Custom_Object__feed];
system.assert(listTaskFeed[0]!=null,'Feed not created'); //Assert 3
For me, the assertion 1 & 2 is working but the 3rd assertion fails with no records. I had faced a problem in Salesforce.com earlier where the LastModifiedDate on Custom_Object__c record is one second more than the CreatedDate on the Custom_Object__Feed record. Not sure if the same is happening here as well. If any one has a work around, it will be of great help!

Thanks in Advance!

Regards,
Pathikrit

Hello All,

I have a VF page which makes a web service call out on click of a button and passes on some data. The web service call out is to a TIBCO endpoint. In order to bypass firewall we have reverse proxy configured and the call out is made to the same endpoint. This worked fine until I started facing the Read Timed Out issue.
The call out still works and sends a request to the TIBCO. But I get an exception on the page displaying the error that the call out failed. In debug log, the following is displayed.

04:16:05.540 (540751323)|EXCEPTION_THROWN|[23]|System.CalloutException: IO Exception: Read timed out

The service works fine from even SOAP UI and used to work as expected in Salesforce.com as well. Right now though it is failing with the above mentioned exception.

Any idea on how to get around this?

Thanks,

Pathikrit

Hi Guyz,

I am running into a scheduling problem with my apex class. I have a batch apex class named 'MyBatchApex' which I want to schedule to run every 5 minutes. I created a class with implements the Schedulable interface and here goes the code..
 
global class MySchedulerClass{
    global void execute(SchedulableContext sc) {
        ID BatchId = Database.executeBatch(new MyBatchApex(), 50);

    } 
    public static void scheduleThis(){
       String cronString='0 5 * * * ?';
       System.schedule('MyJob', cronString, new MySchedulerClass());
    }
}

To schedule this, I am running the following snipper from Developer Console 
MySchedulerClass.scheduleThis()

The job creates a async job and executes the batch after 5 mins as expected and then stops to run. I want this to execute every 5 minutes like a cron job. Am I doing anything wrong here? How to acheive a frequency of 5 min execution then?
Hi All,

I am getting this error when I try to create a Topic through Apex.

Method does not exist or incorrect signature: ConnectApi.Topic.assignTopicByName

Here is my code:
ConnectApi.Topic.assignTopicByName(null,f.Id,'Test1');
I can't figure out the error here...please help
 
Hi,

Is there any way to control the Feed Tracking entries populated by Chatter?
Allow me to elaborate my problem. At the moment, when we have Feed Tracking in a custom object (say Test__c) for a field (FieldName__c) , when there is a change in the field value, it posts a Feed in Chatter saying 'FieldName changed from X to Y'. I wanted to customize this message if possible. 

While Chatter Triggers on FeedItem would allow me control messages entered by users manually I couldn't find a way to control this feed. 
Is there any way to do this? If not, do you have any workaround for this which might work?

Thanks!
Hi,

I am having an issue with displaying trigger error on a Visualforce page. In my trigger, I'm having the following piece of code to throw the error:

myCustomObjectInstance.addError('You are not allowed to do this...');

Again, on my VF page, I have added the following snippet:
<apex:pagemessages/>
The problem is that when I simulate the error condition, it does not display the error message on the VF page, but the same is visible in debug log as follows:
VF_PAGE_MESSAGE|You are not allowed to do this...


Anyone has any idea about it?

Thanks..
Hi,

I have a requirement to write an apex web service which accepts attachments and creates the same in SFDC. My question is, is it possible to create a webservice which allows the source system to send the attachment data through SOAP header? 

To elaborate my point, please refer to the Apex class below:
global class createAttachment{
webservice static String createAttachment(String parent, List<MultipleAttachments> multiAtt )
    {
        try
        {
            Id parentRecordId=Id.ValueOf(parent);
            List<Attachment> listAtt = new List<Attachment>();
           
            for(MultipleAttachments at : multiAtt)
            {
                Attachment att = new Attachment();
                att.Name=at.title;
                att.Body=EncodingUtil.base64Decode(at.content);//at.content;
                att.ContentType=at.ContentType;
                att.parentId=parentRecordId;
                listAtt.add(att);
            }
           
            insert listAtt; 
        }
        catch(Exception e)
        {
            system.debug('Exception--> '+e.getMessage());
        }
        return 'Yes!!!';
    }
   
    global class MultipleAttachments
    {
        webservice String title {get;set;}
        webservice String contentType {get;set;}
        webservice String content {get;set;}
    }
}

The generated WSDL from this apex class allows to send the attachment data through SOAP body. This works fine when used from SOAP UI. But if I want to send the same through SOAP header, is it possible to implement? Any pointers would be helpful.

Thanks!
Hi,

I have a requirement to develop a visualforce page to load a website in an iFrame. The code is very straightforward 

<apex:page standardController="xxxxxx" >
<apex:form >
    <apex:iframe src="{!$Label.iFrameLink}" scrolling="true" id="theIframe"/>
</apex:form>
</apex:page>

I'm using custom label 'iFrameLink' for the URL. The issue is for some website domain it perfectly loads the iframe. But for some domains it doesn't. The website I have to load in iFrame is in a secured domain. I downloaded the security certificate in browser to make it work. But this created another problem. The page isn't opening in iFrame, rather its redirecting to the mentioned url.

I read in the forum some domains uses the X-Frame-Options: SAMEORIGIN header to block their site displaying in iframes. The X-FRAME-Options header is a security feature to prevent clickjacking attacks. I hope this is not the same problem as in my case the page loads, but instead of loading in iframe it reloads the entire window.

Anyone has any clue about this?

Regards,
Pathikrit
Hi,

I am facing an issue while testing a RestApi service using cURL. I am getting "INVALID_SESSION_ID" error everytime.

Here are the steps I followed:

1. Create a rest apex class.

@RestResource(urlMapping ='/Cases/*')
global class getCases
{
@HttpPost
    global static List<Case> fetchCase(String limits,Date startDate, Date endDate)
    {
        List<Case> lstCase;
        try
        {
           RestRequest req = RestContext.request;
           Integer intLimit = Integer.valueOf(req.params.get('limits'));
           DateTime strtDate = DateTime.valueOfGmt((req.params.get('startDate')).replaceAll('/','-'));
           DateTime enDate = DateTime.valueOfGmt((req.params.get('endDate')).replaceAll('/','-'));
           lstCase = [Select Id,OwnerId,CaseNumber from Case where createdDate>=: strtDate and createdDate<=:enDate limit :intLimit];
           return lstCase;
         }
         catch(Exception e)
         {
             system.debug('Exception'+e);
         }
           return lstCase;
      }
}
2. Create a connected app with Callback URL as "https://ap1.salesforce.com/services/oauth2/token"
3. Call the web service using cURL:
curl --form client_id=XXXXXXX.000XXXXXX --form client_secret=000999999--form grant_type=password --form username=gupta.pathikrit@domain.com --form password=*********** -k https://ap1.salesforce.com/services/oauth2/token
This call gave the access_token which I used to make a HTTP Post call:
curl https://ap1.salesforce.com/services/apexrest/Cases/ -H "Authorization: OAuth 00XXXXXPPP" -H "Content-Type:application/json" -d @C:\input.json -k

This is resulting in the following error:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

Can anyone help me here?

Regards,
Pathikrit
Hi,

I am having an issue with displaying trigger error on a Visualforce page. In my trigger, I'm having the following piece of code to throw the error:

myCustomObjectInstance.addError('You are not allowed to do this...');

Again, on my VF page, I have added the following snippet:
<apex:pagemessages/>
The problem is that when I simulate the error condition, it does not display the error message on the VF page, but the same is visible in debug log as follows:
VF_PAGE_MESSAGE|You are not allowed to do this...


Anyone has any idea about it?

Thanks..
Hello,

I was working on a custom datepicker in a visualforce that can display date in User locale. While going through some articles on the best way of implementing a datepicker with localization support I came across the JQuery Datepicker. I wanted to ensure that the datepicker displays date always in user locale. But while implementing I am unable to set the dateformat accordingly.

Here is my VF page code..
<apex:page controller="TestController" docType="html-5.0" sidebar="false">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"/>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript"> 
var userlang = window.navigator.language;
console.log(userlang);
$(function(){
    $("#datepicker").datepicker({
        formatDate:'dd-mm-yyyy',
        changeMonth:true,
        changeYear:true
    });
});

</script>
<apex:form >
<apex:pageBlock id="pgblk">
<input value="{!dateVariable}" type="text" id="datepicker"/>
</apex:pageBlock>
</apex:form>
</apex:page>
The controller doesn't have anything else than the getter & setter methods for the variable dateVariable. As you can see, I am hardcoding the format in the above code to 'dd-mm-yyyy'. But still during execution, I see the format as 'mm/dd/yyyy'. 

Can anyone help on this?

Thanks in advance!
Pathikrit
 
Hi,

I am running into this problem while writing a test class for a service which is intented to add topic to FeedTrackedChange record posted by Salesforce automatically. The idea is to put a topic to any chatter feed posted automatically for a field which is tracked in Chatter. 
List<Custom_Object__feed> listFeed =[select Id,ParentId,CreatedDate from Custom_Object__feed where ParentId in:setIds];
                List<Topic> existingTopic = [select Id, Name from Topic where Name in:mapName.Values()];
        
                for(Topic t:existingTopic){ 
                    topicNames.add(t.Name);
                    mapTopicNameIds.put(t.Name,t.Id);
                }
                
                if(!listFeed.isEmpty()){
                    for(Custom_Object__feed feed:listFeed){
                        if(!topicNames.contains(mapName.get(feed.ParentId))){
                            Topic newTopic = new Topic();
                            newTopic.Name=mapName.get(feed.ParentId);
                            setTopic.add(newTopic);
                        }
                        else{
                            TopicAssignment newAssignment = new TopicAssignment();
                            newAssignment.TopicId=mapTopicNameIds.get(maptName.get(feed.ParentId));
                            newAssignment.EntityId=feed.Id;
                            listTopicAssignment.add(newAssignment);
                        }
                    }
                    listTopic.addAll(setTopic);
        
                    Database.insert(listTopic,false); //Insert Topic
                    for(pse__Proj__feed feed:listProjectFeed){ 
                        for(Topic t:listTopic){
                            if(t.Name==mapName.get(feed.ParentId)){
                                TopicAssignment newAssignment = new TopicAssignment();
                                newAssignment.TopicId=t.Id;
                                newAssignment.EntityId=feed.Id;
                                listTopicAssignment.add(newAssignment);
                            }   
                        }
                    }
                }    
                Database.insert(listTopicAssignment,false); //Insert Assignment
The problem is in the test class, when I update a certain field on the Custom_Object__c it does not automatically post a Custom_Object__feed entry. Here is my test code.
Boolean isChatterEnabled = Schema.SObjectType.User.isFeedEnabled();
system.assert(isChatterEnabled == true,'Feed Tracking is not enabled for the user'); //Assert 1
Boolean isChatterEnabledTask = Schema.SObjectType.Custom_Object__c.isFeedEnabled();
system.assert(isChatterEnabledTask == true,'Feed Tracking is not enabled for Project Task'); //Assert 2

Custom_Object__c c = new Custom_Object__c(Name='test');
insert c;

c.Status__c = 'In progress';
update c;


List<Custom_Object__feed> listTaskFeed = [select Id,parentId from Custom_Object__feed];
system.assert(listTaskFeed[0]!=null,'Feed not created'); //Assert 3
For me, the assertion 1 & 2 is working but the 3rd assertion fails with no records. I had faced a problem in Salesforce.com earlier where the LastModifiedDate on Custom_Object__c record is one second more than the CreatedDate on the Custom_Object__Feed record. Not sure if the same is happening here as well. If any one has a work around, it will be of great help!

Thanks in Advance!

Regards,
Pathikrit
Hi Guyz,

I am running into a scheduling problem with my apex class. I have a batch apex class named 'MyBatchApex' which I want to schedule to run every 5 minutes. I created a class with implements the Schedulable interface and here goes the code..
 
global class MySchedulerClass{
    global void execute(SchedulableContext sc) {
        ID BatchId = Database.executeBatch(new MyBatchApex(), 50);

    } 
    public static void scheduleThis(){
       String cronString='0 5 * * * ?';
       System.schedule('MyJob', cronString, new MySchedulerClass());
    }
}

To schedule this, I am running the following snipper from Developer Console 
MySchedulerClass.scheduleThis()

The job creates a async job and executes the batch after 5 mins as expected and then stops to run. I want this to execute every 5 minutes like a cron job. Am I doing anything wrong here? How to acheive a frequency of 5 min execution then?
Hi All,

I am getting this error when I try to create a Topic through Apex.

Method does not exist or incorrect signature: ConnectApi.Topic.assignTopicByName

Here is my code:
ConnectApi.Topic.assignTopicByName(null,f.Id,'Test1');
I can't figure out the error here...please help
 
Hi,

Is there any way to control the Feed Tracking entries populated by Chatter?
Allow me to elaborate my problem. At the moment, when we have Feed Tracking in a custom object (say Test__c) for a field (FieldName__c) , when there is a change in the field value, it posts a Feed in Chatter saying 'FieldName changed from X to Y'. I wanted to customize this message if possible. 

While Chatter Triggers on FeedItem would allow me control messages entered by users manually I couldn't find a way to control this feed. 
Is there any way to do this? If not, do you have any workaround for this which might work?

Thanks!
Hi,

I am having an issue with displaying trigger error on a Visualforce page. In my trigger, I'm having the following piece of code to throw the error:

myCustomObjectInstance.addError('You are not allowed to do this...');

Again, on my VF page, I have added the following snippet:
<apex:pagemessages/>
The problem is that when I simulate the error condition, it does not display the error message on the VF page, but the same is visible in debug log as follows:
VF_PAGE_MESSAGE|You are not allowed to do this...


Anyone has any idea about it?

Thanks..
Hi,

I have a requirement to write an apex web service which accepts attachments and creates the same in SFDC. My question is, is it possible to create a webservice which allows the source system to send the attachment data through SOAP header? 

To elaborate my point, please refer to the Apex class below:
global class createAttachment{
webservice static String createAttachment(String parent, List<MultipleAttachments> multiAtt )
    {
        try
        {
            Id parentRecordId=Id.ValueOf(parent);
            List<Attachment> listAtt = new List<Attachment>();
           
            for(MultipleAttachments at : multiAtt)
            {
                Attachment att = new Attachment();
                att.Name=at.title;
                att.Body=EncodingUtil.base64Decode(at.content);//at.content;
                att.ContentType=at.ContentType;
                att.parentId=parentRecordId;
                listAtt.add(att);
            }
           
            insert listAtt; 
        }
        catch(Exception e)
        {
            system.debug('Exception--> '+e.getMessage());
        }
        return 'Yes!!!';
    }
   
    global class MultipleAttachments
    {
        webservice String title {get;set;}
        webservice String contentType {get;set;}
        webservice String content {get;set;}
    }
}

The generated WSDL from this apex class allows to send the attachment data through SOAP body. This works fine when used from SOAP UI. But if I want to send the same through SOAP header, is it possible to implement? Any pointers would be helpful.

Thanks!
Hi,

I have a requirement to develop a visualforce page to load a website in an iFrame. The code is very straightforward 

<apex:page standardController="xxxxxx" >
<apex:form >
    <apex:iframe src="{!$Label.iFrameLink}" scrolling="true" id="theIframe"/>
</apex:form>
</apex:page>

I'm using custom label 'iFrameLink' for the URL. The issue is for some website domain it perfectly loads the iframe. But for some domains it doesn't. The website I have to load in iFrame is in a secured domain. I downloaded the security certificate in browser to make it work. But this created another problem. The page isn't opening in iFrame, rather its redirecting to the mentioned url.

I read in the forum some domains uses the X-Frame-Options: SAMEORIGIN header to block their site displaying in iframes. The X-FRAME-Options header is a security feature to prevent clickjacking attacks. I hope this is not the same problem as in my case the page loads, but instead of loading in iframe it reloads the entire window.

Anyone has any clue about this?

Regards,
Pathikrit
Hi,

I am facing an issue while testing a RestApi service using cURL. I am getting "INVALID_SESSION_ID" error everytime.

Here are the steps I followed:

1. Create a rest apex class.

@RestResource(urlMapping ='/Cases/*')
global class getCases
{
@HttpPost
    global static List<Case> fetchCase(String limits,Date startDate, Date endDate)
    {
        List<Case> lstCase;
        try
        {
           RestRequest req = RestContext.request;
           Integer intLimit = Integer.valueOf(req.params.get('limits'));
           DateTime strtDate = DateTime.valueOfGmt((req.params.get('startDate')).replaceAll('/','-'));
           DateTime enDate = DateTime.valueOfGmt((req.params.get('endDate')).replaceAll('/','-'));
           lstCase = [Select Id,OwnerId,CaseNumber from Case where createdDate>=: strtDate and createdDate<=:enDate limit :intLimit];
           return lstCase;
         }
         catch(Exception e)
         {
             system.debug('Exception'+e);
         }
           return lstCase;
      }
}
2. Create a connected app with Callback URL as "https://ap1.salesforce.com/services/oauth2/token"
3. Call the web service using cURL:
curl --form client_id=XXXXXXX.000XXXXXX --form client_secret=000999999--form grant_type=password --form username=gupta.pathikrit@domain.com --form password=*********** -k https://ap1.salesforce.com/services/oauth2/token
This call gave the access_token which I used to make a HTTP Post call:
curl https://ap1.salesforce.com/services/apexrest/Cases/ -H "Authorization: OAuth 00XXXXXPPP" -H "Content-Type:application/json" -d @C:\input.json -k

This is resulting in the following error:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

Can anyone help me here?

Regards,
Pathikrit