• Longhorn94
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies

Does anyone know if there's a way within Apex to determine which fields are in a pre-defined layout?  I want my Apex class to be able to determine which fields are in one of the layouts defined in [Customize..Accounts..Page Layouts].  Or, is there a way to find out which fields are included in the <apex:detail> Visualforce component for a standard object such as an Account?

 

I would like to create a VisualForce page using a standard controller, that captures and displays the page errors by using <apex:pageMessages />.  Right now, if you call any VisualForce page but encounter an error, for ex calling the page with an invalid identifier, you get a standard Salesforce.com error message:

 

Visualforce Error
Id value 001U0000005W2cu1 is not valid for the Account standard controller

 

I would like for my page to display this error in the styles and configuration I've specified in the page, but instead, my page isn't shown and I get the Salesforce.com error instead.

 

This is possible using a custom controller, where I can trap any errors, add them to the pagemessages collection, then have my VF page check this collection to display the data or the error message using the proper formatting.

 

Appreciate any insight you might have...

 

This VisualForce page shows the account details for an account using an apex:detail object:

 

<apex:page standardController="Account">
          <apex:detail relatedList="false"/>
</apex:page>

 

Does anyone know why this page would show an error when you call it with an invalid account id in the url?  The error is:

 

Insufficient Privileges

You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.

 

The page works properly when you call it with an valid account id in the url.  I gave all roles permissions to view the page in the security definitions for the page, and I'm the admin in this developer account.

 

When other pages with a standard controller are called with an invalid account id, they return the VisualForce error:

 

Visualforce Error
Id value 001U0000005W2cu1 is not valid for the Account standard controller

 

Hello,

 

Does anyone know how to get a session ID for the SOAP API from a SAML token?  I haven't found much documentation beyond the brief mention of it here: https://login.salesforce.com/help/doc/en/remoteaccess_oauth_web_sso_flow.htm

 

I've gotten a valid SAML token from my local ADFS service, my Salesforce.com organization is configured for SSO and I can log in with SSO through the browser.

 

Here's what I have

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://login.salesforce.com/services/oauth2/token?saml=EK03Almz90tebkf_LSfPhrv06c....");
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.Host = "login.salesforce.com";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729)";
request.Accept = "image/jpeg, image/gif, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, */*";

string RequestBody =
    "grant_type=assertion" +
    "&assertion_type=urn%3Aoasis%3Anames%3Atc%3ASAML%3A2.0%3Aprofiles%3ASSO%3Abrowser" +
    "&assertion=PHNhbWxwOlJlc3BvbnNlIElEPS..." +
    "&format=xml";

 When I submit this request, I get the error:

 

Error code: BadRequest  <?xml version="1.0" encoding="UTF-8"?><OAuth><error_uri>https://na14.salesforce.comnull/setup/secur/SAMLValidationPage.apexp</error_uri><error>invalid_grant</error><error_description>invalid assertion</error_description></OAuth>

 

...though I've set the grant_type and assertion fields as called for in the documentation.

 

I appreciate any help on this!

 

Hello,

 

I'm trying to add a batch to an existing job using the Bulk API from C#.  I've created the job and can get info on it, but am running into a problem when attempting to add a batch of data to it.

 

Here's the code.  The problem is that at run time the call to this line never returns:

Stream datastream = request.GetRequestStream();

 

This only happens when the url on the request includes the "batch" at the end (see first line of code).  The JobID parameter is valid, is an open job, and works in a separate call to get info.

 

Does anyone know what the problem might be?

 

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://na12-api.salesforce.com/services/async/23.0/job/" + JobID + "/batch");
            request.Method = WebRequestMethods.Http.Post;
            request.ContentType = "application/xml; charset=UTF-8";
            request.Headers.Add("X-SFDC-Session", _SessionID);
            request.KeepAlive = false;
            request.Host = "na12.salesforce.com";
            request.UserAgent = ".NET Framework Test Client";
            request.Accept = "application/xml";

            string body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> ";
            body += "<sObjects xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">";
            body += "  <sObject>";
            body += "    <description>Created from Bulk API on Wed Jan 4 2012</description>";
            body += "    <name>[Bulk API] Account 0 (batch 0)</name>";
            body += "  </sObject>";
            body += "  <sObject>";
            body += "    <description>Created from Bulk API on Wed Jan 4 2012</description>";
            body += "    <name>[Bulk API] Account 1 (batch 0)</name>";
            body += "  </sObject>";
            body += "</sObjects>";

            //Convert the body of request into a byte array
            byte[] byteArray = Encoding.UTF8.GetBytes(body);

            //Set the length
            request.ContentLength = byteArray.Length;

            //Write the body to the request by using a datastream
            //This line never returns....
            Stream datastream = request.GetRequestStream();
            datastream.Write(byteArray, 0, byteArray.Length);
            datastream.Close();

            //Call the service and get the response as a data stream
            WebResponse response = request.GetResponse();
            datastream = response.GetResponseStream();
            StreamReader reader = new StreamReader(datastream);
            string responseFromServer = reader.ReadToEnd();

            response.Close();

 

 

 

I would like to create a VisualForce page using a standard controller, that captures and displays the page errors by using <apex:pageMessages />.  Right now, if you call any VisualForce page but encounter an error, for ex calling the page with an invalid identifier, you get a standard Salesforce.com error message:

 

Visualforce Error
Id value 001U0000005W2cu1 is not valid for the Account standard controller

 

I would like for my page to display this error in the styles and configuration I've specified in the page, but instead, my page isn't shown and I get the Salesforce.com error instead.

 

This is possible using a custom controller, where I can trap any errors, add them to the pagemessages collection, then have my VF page check this collection to display the data or the error message using the proper formatting.

 

Appreciate any insight you might have...

 

This VisualForce page shows the account details for an account using an apex:detail object:

 

<apex:page standardController="Account">
          <apex:detail relatedList="false"/>
</apex:page>

 

Does anyone know why this page would show an error when you call it with an invalid account id in the url?  The error is:

 

Insufficient Privileges

You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.

 

The page works properly when you call it with an valid account id in the url.  I gave all roles permissions to view the page in the security definitions for the page, and I'm the admin in this developer account.

 

When other pages with a standard controller are called with an invalid account id, they return the VisualForce error:

 

Visualforce Error
Id value 001U0000005W2cu1 is not valid for the Account standard controller

 

Hello,

 

Does anyone know how to get a session ID for the SOAP API from a SAML token?  I haven't found much documentation beyond the brief mention of it here: https://login.salesforce.com/help/doc/en/remoteaccess_oauth_web_sso_flow.htm

 

I've gotten a valid SAML token from my local ADFS service, my Salesforce.com organization is configured for SSO and I can log in with SSO through the browser.

 

Here's what I have

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://login.salesforce.com/services/oauth2/token?saml=EK03Almz90tebkf_LSfPhrv06c....");
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/x-www-form-urlencoded";
request.KeepAlive = true;
request.Host = "login.salesforce.com";
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729)";
request.Accept = "image/jpeg, image/gif, application/x-ms-application, application/xaml+xml, application/x-ms-xbap, */*";

string RequestBody =
    "grant_type=assertion" +
    "&assertion_type=urn%3Aoasis%3Anames%3Atc%3ASAML%3A2.0%3Aprofiles%3ASSO%3Abrowser" +
    "&assertion=PHNhbWxwOlJlc3BvbnNlIElEPS..." +
    "&format=xml";

 When I submit this request, I get the error:

 

Error code: BadRequest  <?xml version="1.0" encoding="UTF-8"?><OAuth><error_uri>https://na14.salesforce.comnull/setup/secur/SAMLValidationPage.apexp</error_uri><error>invalid_grant</error><error_description>invalid assertion</error_description></OAuth>

 

...though I've set the grant_type and assertion fields as called for in the documentation.

 

I appreciate any help on this!

 

Hello,

 

I'm trying to add a batch to an existing job using the Bulk API from C#.  I've created the job and can get info on it, but am running into a problem when attempting to add a batch of data to it.

 

Here's the code.  The problem is that at run time the call to this line never returns:

Stream datastream = request.GetRequestStream();

 

This only happens when the url on the request includes the "batch" at the end (see first line of code).  The JobID parameter is valid, is an open job, and works in a separate call to get info.

 

Does anyone know what the problem might be?

 

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://na12-api.salesforce.com/services/async/23.0/job/" + JobID + "/batch");
            request.Method = WebRequestMethods.Http.Post;
            request.ContentType = "application/xml; charset=UTF-8";
            request.Headers.Add("X-SFDC-Session", _SessionID);
            request.KeepAlive = false;
            request.Host = "na12.salesforce.com";
            request.UserAgent = ".NET Framework Test Client";
            request.Accept = "application/xml";

            string body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> ";
            body += "<sObjects xmlns=\"http://www.force.com/2009/06/asyncapi/dataload\">";
            body += "  <sObject>";
            body += "    <description>Created from Bulk API on Wed Jan 4 2012</description>";
            body += "    <name>[Bulk API] Account 0 (batch 0)</name>";
            body += "  </sObject>";
            body += "  <sObject>";
            body += "    <description>Created from Bulk API on Wed Jan 4 2012</description>";
            body += "    <name>[Bulk API] Account 1 (batch 0)</name>";
            body += "  </sObject>";
            body += "</sObjects>";

            //Convert the body of request into a byte array
            byte[] byteArray = Encoding.UTF8.GetBytes(body);

            //Set the length
            request.ContentLength = byteArray.Length;

            //Write the body to the request by using a datastream
            //This line never returns....
            Stream datastream = request.GetRequestStream();
            datastream.Write(byteArray, 0, byteArray.Length);
            datastream.Close();

            //Call the service and get the response as a data stream
            WebResponse response = request.GetResponse();
            datastream = response.GetResponseStream();
            StreamReader reader = new StreamReader(datastream);
            string responseFromServer = reader.ReadToEnd();

            response.Close();

 

 

 

Does anyone know how to use Bulk API in C#?

the Web Service API can only update max 200 records at once.

Bulk API can update 10,000 records at once.

I only find sample code using Java.

Thanks.

 

  • October 27, 2010
  • Like
  • 0