• sfdcfox
  • ALL STAR
  • 25241 Points
  • Member since 2007

  • Chatter
    Feed
  • 898
    Best Answers
  • 7
    Likes Received
  • 2
    Likes Given
  • 32
    Questions
  • 4554
    Replies
I am using $API.Session_Id in script in a VF page. I will be using this page for guest users. This {!$Api.session_id} returns some value. Is it a wrong way to get session id as this page will be used for site Guest users? Is it vulnerable?
<apex:page controller="ABCcntr"><script> var token={!$Api.Session_ID}</script> </apex:page>
Hello, I was wondering if there was a solution to this?  

level1Disabled
level2Disabled
level3Disabled
level4Disabled

If I had variables in aura I could set the value like this........

component.set("v.level" + number + "Disabled", true);

How can I do the same think in a Lightning Web Component?  The values are @track (ed).....

@track level1Disabled;
@track level2Disabled;
@track level3Disabled;
@track level4Disabled;

this.level1Disabled = true;

I want to do something like........

this."level" + number + "Disabled" = true
I'm trying to do a query to return a field with the type reference.  I am assuming that it means the field resides in another object table?

How do you return the value of a reference field in a simple SQL statement?
How to write Test class for std controller and custom controller,wrapper class?
Our production deployments using the (ant) force migration tool have been consistently failing recently, after executing some percentage of our tests, with the error:

System.LimitException: Your runAllTests request is using too many DB resources.

All of our tests are @isTest(seeAllData=false) and we recreate all test data from scratch using factory classes at the beginning of each test method.

We contacted Salesforce support, and after a multiple calls, different people, and a lot of time, they told us that in addition to the per-transaction governor limits, there are undocumented limits that are shared amongst all executed code during the course of a runAllTests request:
  • The DML statement limit is 350,000
  • The SOQL statement limit is 450,000
Salesforce suggested that we use the @testSetup annotation to setup data in our tests (we have not been using that annotation), and this would help us in avoiding hitting the above limits. I wrote a small unit test to verify that this would actually help with limits, but the unit test suggests that the DML statements accrued in a @testSetup annotated method do indeed count in each testmethod.
@isTest(seeAllData=false)
public class TestSalesforceTestSetupDMLCount {

    @testSetup static void setup(){
        // Assert that no DMLs have occurred yet
        system.assertEquals(0, Limits.getDMLStatements());
        
        // Perform 4 DMLs
        for(Integer i=0; i<4; i++){
            insert new Account(Name='Test' + i);
        }
        
        // Assert that 4 DMLs have been performed
        system.assertEquals(4, Limits.getDMLStatements());
    }
    
    public static testmethod void testDmlCount1(){
		// THIS ASSERTION FAILS
        system.assertNotEquals(4, Limits.getDMLStatements());
    }
    
    public static testmethod void testDmlCount2(){
        // THIS ASSERTION FAILS
        system.assertNotEquals(4, Limits.getDMLStatements());
    }
}

The 2 testmethods fail because Limits.getDMLStatements() returns 4. The question is, regarding the runAllTests DML statement limit of 350,000, does the above test contribute 4 DML statements or does it contribute 12 DML statements (4 for setup(), 4 for testDmlCount1(), 4 for testDmlCount2())?

This is obviously something that only Salesforce can answer, but I at least want this issue documented somewhere, and will provide updates as we get answers from Salesforce.
I'm writing a trigger on OpportunityLineItem, but I need to access the Close Date of the OpportunityLineItem's associated Opportunity. Is there a way to do this?
Hi,

  I need to make a callout to a webservice to update the content before it is saved using a trigger. Currently I am using "After insert" to get the id of the object and call an async class which would then update the object based on the response from web service. However I would like to change this behavior to before insert in which case the id of the object is returned as null since the object is not saved yet Is there any way I could do this ?

Thanks,
Anil
Hi there, 
I'm trying to use Analytics API to fetch the results of a report (syncronous) and this report contains a field that might have a JSON inside.

The problem is that the API is returning 

<pre>{
          "value" : "{\n20:{Net:0.0,VAT:0.0,Total:0.0,VAT(%):...",
          "label" : "{\n20:{Net:0.0,VAT:0.0,Total:0.0,VAT(%):..."
        }</pre>

(is cutting out part of the information).

Is there any parameter that I can use or some way to prevent the API from cutting out this information?

Thanks and regards.
I have been struggling to understand why code coverage for a trigger is 100% in sandbox and 0% when attempting to deploy to production.
Hi, we have a requirement to integrate Salesforce with a ThirdParty Vendor using webservices.

We need to send around 300,000 Records from Salesforce to the ThirdParty vendor using their webservice.
We have a custom apex program using which we are able to call the third party web service successfully within a future method in a schedulable program. However, for a volume as high as 300k records, I am not sure how to avoid hitting the governer limits. My understanding is that, I can make 10 calls in an apex class and can call the future method 10 times, making 100 web service calls in total. This is not sufficient for 300k records. Supposing we can include multiple records in one call, we will still hit another problem. Since each call's size is restricted to 3 MB and our one SOAP call's xml size is around 20k, the maximum we can do is 150 records per call giving us the ability to send 150 X 100 = 15k records. Is there any method to avoid hitting governer limits in this scenario.

Please help me as I am new to Sales force development.
Hi

I am trying to display image in visualforce page based on condition. The condition applied is on {$CurrentPage.parameters.startpage} value.

If {$CurrentPage.parameters.startpage} = "xyz" then display image <apex:image  url="xxxxxxx"> else display image <apex:image  url="yyyy">

I click a link and try to get the parameters of that url. Based on those parameter, I have to render different images on VF Page.

www.testurl.com/?value=xyz

www.testurl.com/?value=abc

Please find below the code I am using and let me know whats wrong there

<apex:image value="{If({!$CurrentPage.parameters.startpage}='xyz','/servlet/servlet.ImageServer?id=015D0000002Dkr2&oid=00DD0000000CWRY&lastMod=1388753305000' , '/servlet/servlet.ImageServer?id=015D0000002Dkr2&oid=00DD0000000CWRY&lastMod=1388753305000')}" />
Hi , 

I have created force.com site to login for customer portal users. we are applying session timie out value is 8 hours . is this settings apply for portal users also? 

is there any way to apply session settings different portal users? 

Thanks & Regards
Siva.

Hi all,
      This is my first attempt at using JSON in APEX, seems pretty straight forward.  I have what I think is a very simple question...making a call out to a webservice that is returning a JSON string for new order information.   In my apex class, I have a simple order class:
public class OrderInfo{
     public String CustomerName {get; set;}
     public String CustomerNo {get; set;}
     public String OrderStatus {get; set;}
     public String CustomerPONo{get; set;}
     public String Name {get; set;}
     public String GrossAmount {get; set;}
     public String WantedDeliveryDate {get; set;}

}

I make a call out to my webservice and get back my JSON string...all is well.  Now I need to deserialize it which I'm doing like this:
HTTPResponse res = h.send(req);  //response comes back correctly, data is all formatted as I would expect..
       //deserialize the JSON data returned by the web service into the OrderInfo class defined above
        OrderInfo newOrder = new OrderInfo();
        newOrder = (OrderInfo)JSON.deserialize(res.getBody(), OrderInfo.class);
So here is my problem, when I look at the values of my newOrder object they are all null.  Based on examples I viewed, It looked like the deserialize method with a specified object type would update the values in the object.  Do I need to do something else to save the values into the newOrder object?  
    I really appreciate any assistance, I'm sure it's something very simple!  Thanks in advance!!

Hi, 

I have made my cases object private and have a custom visualforce page and controller to retrieve a list of cases.

On the standard page, a user can only see those cases they have read permissions on.

On the visualforce page, the query also retrieves cases where the case contact is also from the same account. However, the user does not actually have permission to these cases, and gets a permission error when they try to access it. 

Just for my own sanity, when you run a query it should only retrieve those objects which you have at least permission to, correct? It has been working like this for everything else I can remember. 

Is there something weird with case sharing and customer portal licenses?

I am using overage customer portal licenses in a community.  
I have a function that uses a sosl query:

private List<Product2> runSoslToExecute() {
    List<List<Product2>> searchResults = [FIND :query IN ALL FIELDS RETURNING Product2 (Id, Name)];
    List<Product2> results = new List<Product2>();
    for(Product2 p : searchResults[0]) {
        results.add(p);
    }
    return results;
}

If I search for "AB*" then I also get results that include "1AB...". I thought the "*" wildcard only searches in the middle and end of the search and not at the beginning? Is there a way to run the sosl search so it only searches "AB" at the beginning?

Thanks for any help.
Hi,

I have urgent client requirement. Please help me in doing this.
Actually client has send me a php WSDL file which is containing "rpc" style. When I am including this WSDl file in salesforce. I am getting error that "rpc" style doesn't support.

So, How to call wsdl( php SOAP webservice) from salesforce, and in that i have to pass some field values to PHP server.
Please help me in doing this Integration... I tried to do by googling it. But I didn't find out correct solution.

I tried using http callouts as like....

HttpRequest req = new HttpRequest();
req.setEndpoint('http://tfserver.forexwebsolutions.com/tfserver.php?wsdl');
req.setMethod('GET');
Http http = new Http();
HttpResponse response = http.send(req);
System.Debug('STATUS:'+response.getStatusCode());
System.Debug('Body:'+response.getBody());

Here I am getting the XML in respose....
Please help me in passing values to php fields... So that it will be very helpful.
Whether it is possible to add standard account logo image of salesforce in visualforce page and also customizing the text in that logo ?
Hi everybody!

First at all: Happy New Year to you and your family. I wish you all the best in new 2014 year.

And about my case:

I use 'MyPdfRenderingPage.getContent();' method to get Blob PDF-body, create PDF attachment and sent it by mail.

And a code (please see below) works great in  Console's Execute Anonimous Window. It creates a mail with PDF file attached which I can open later.

But if I insert the same piece of code in my Email service (it receives a mail, creates a record and returns new mail with PDF attachment), it doesn't work correctly. I receive the mail, but can't open PDF attachment.

So I checked what does that Blob return content? If to execute 'MyPdfRenderingPage.getContent();' method in Email service, it returns HTML file with JS script inside leads to MyPdfRenderingPage.

In both cases the code runs by the same user, i did check it as well.

I have no idea what is wrong here...

Thanks a lot for your help.

----------
And that code below
______

Messaging.reserveSingleEmailCapacity(5);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

String[] toAddresses = new String[] {'my@mail.com'};

mail.setToAddresses(toAddresses);

mail.setReplyTo('my@mail.com');

mail.setSenderDisplayName('Support');

mail.setSubject('New Record Created : ' + newRecords[0].id);

mail.setBccSender(true);

mail.setUseSignature(false);

mail.setPlainTextBody('Your new record has been created.');

mail.setHtmlBody('Your new record has been created.');


    PageReference pdf = Page.MyPDFpage;
    pdf.getParameters().put('id', (String)newRecords[0].id);
    pdf.getParameters().put('position', '1');
    pdf.setRedirect(true);

    Blob pageContent = pdf.getContent();

    Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
    efa.setFileName('PrintThisPDF.pdf');
    efa.setBody(pageContent);                                                          

mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});                                                         
                                                          
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

See last paragraph for summary...

 

I was trying to create an adaptive loader routine in Apex Code, and I came across an interesting bug. First, let's take a look at what I was attempting to do:

 

sobject record = cache.load( recordId );
set< id > relatedIds = new set< Id >( );

for( SObjectField field: Cache.getFieldTokens( record.getSObjectType( ) ) ) {
   if( record.get( field ) != null && record.get( field ) instanceOf id ) {
       relatedIds.add( Id.valueOf( record.get( field ) );
   }
}
map< id, sobject > related = new map< id, sobject >( Cache.load( relatedIds ) );

Where:

* Cache.load( Id ) returns a single record from a static map, querying the record, if necessary.

* Cache.getFieldTokens( SObjectType ) returns all tokens from a SObjectType.getDescribe().fields.getMap().values(), again loading from a static map if previously defined.

* Cache.load( Set< Id > ) is a batch version of above, returning a list of SObject records in arbitrary order, querying records that are missing from the cache, and capable of returning multiple types of SObjects.

 

When I tried this initially, I got an odd exception: "Invalid ID."; the exception was thrown from my Cache class, so I wondered how it could have gotten there.

 

I fiddled around with the straightforward means of assigning an ID via a string:

 

Id a = '0013000000f3adA'; // OKAY
Id b = 'john doe';        // EXCEPTION

So, it would appear the setter function works fine.

 

Next, I tried casting:

 

String a = '0013000000f3Adf', b = 'john doe';
Id c = ( Id )a; // OKAY
Id d = ( Id )b; // EXCEPTION

So far, so good; it's also using the setter function of ID.

 

Next, I tried using Id.valueOf:

 

Id a = Id.valueOf( '0013000000d3afA' ); // OKAY
Id b = Id.valueOf( 'john doe' );        // OKAY ?!?!

This means that Id.valueOf doesn't use the setter method, but instead internally constructs an ID.

 

The next tidbit came when I tested the Set<T> class against an ID.

 

First, a straight assignment:

 

Set< Id > a = new set< Id >( );
a.add( '00130000003faZs' ); // OKAY
a.add( 'john doe' ); // EXCEPTION

So, it seems that Id's setter is in play here.

 

Next, I tried using the defunct valueOf:

 

Set< Id > a = new Set< Id >( );
a.add( Id.valueOf( 'john doe' ) ); // OKAY ?!?!

So, it seems that a "corrupted" ID value will be accepted into a set of IDs.

 

This led to the next problem:

 

for( Id b: a) {
  // Do something
}

If a is a set of IDs, and a corrupted ID value (via valueOf) is in the set, you will receive an "invalid ID" error here.

 

Finally, this led me back to my source code:

 

if( Id.valueOf( 'john doe' ) instanceOf Id ) {
  System.debug('** Invalid ID was accepted by instanceOf **');
}

So, Set<T>.add(Object) apparently checks the class of the incoming object against the class of its template, and automatically accepts them without question, otherwise attempts a cast (calling the correctly-working setter function).

 

I submitted a case to support, and they told me to go away because I don't have premier support, and all I wanted to do was log a bug with the dev team.

 

Hopefully an admin will see this and it will get logged as a bug. In the interim, the community should note that Id.valueOf is broken, and instanceOf is also broken as a side-effect. Instead, you should always use casting, and try-catch the cast so you can detect incorrect ID values.