• Chad Joubert
  • NEWBIE
  • 0 Points
  • Member since 2015
  • Software Engineer
  • U.S. Venture, Inc.


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
I am looking to get several fields from the ContentDocuments object given an entity Id for the ContentDocuemntLink.  The SOQLthat I am trying is: Select Title, ContentModifiedDate, ContentSize from ContentDocument 
where Id IN (SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '00655000007PiSd') but I get the error:

(SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId
                                                        ^
ERROR at Row:2:Column:44
Entity 'ContentDocumentLink' is not supported for semi join inner selects

I need this in SOQL because the call is coming from a .Net program.  I can accomplish this will a second call but would like to be able to get the list in one call.
 
I have been able to update fields and add documents to SalesForce but I am having trouble adding an attachment to an object such as an opportunity.  If anyone can see what I am missing that would be a great help.  
 
protected async Task LoadDocument(string parentObjectID)
        {
          
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

            var auth = new AuthenticationClient();
            var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                ? "https://test.salesforce.com/services/oauth2/token"
                : "https://login.salesforce.com/services/oauth2/token";

            await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);

            string boundary = "----" + DateTime.Now.Ticks.ToString("x");

            var uri = auth.InstanceUrl + "/services/data/v37.0/sobjects/attachment/";
            //var uri = auth.InstanceUrl + "/services/data/v37.0/sobjects/Document/";

            var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
            req.Headers.Add("Authorization: OAuth " + auth.AccessToken);
            req.ContentType = "multipart/form-data; boundary=" + boundary;
            req.Method = "POST";
            var os = req.GetRequestStream();

            // Add header for JSON part
            string body = "";
            body += "\r\n--" + boundary + "\r\n";
            //body += "Content-Disposition: form-data; name='attachment'\r\n";
            body += "Content-Disposition: form-data; name='entity_content'\r\n";
            body += "Content-Type: application/json\r\n\r\n";

            var doc = new SFAttachment();
            doc.Name = "test";
            doc.ParentId = parentObjectID;  //result.records[0].Id;

            // Add document object data in JSON
            var ser = new JavaScriptSerializer();
            body += ser.Serialize(doc);

            // Add header for binary part             
            body += "\r\n--" + boundary + "\r\n"; 
            body += "Content-Disposition: form-data; name='body'; filename='test.txt'\r\n";
            body += "Content-Type: binary/octet-stream\r\n\r\n";

            // Add header data to request
            byte[] data = System.Text.Encoding.ASCII.GetBytes(body);
            os.Write(data, 0, data.Length);

            // Add file to reqeust
            //FileStream fileStream = new FileStream(fileBrowser.FileName, FileMode.Open, FileAccess.Read);
            FileStream fileStream = new FileStream(@"C:\test.txt", FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
            {
                os.Write(buffer, 0, bytesRead);
            }
            fileStream.Close();

            // Add trailer
            byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
            os.Write(trailer, 0, trailer.Length);
            os.Close();

            // Do the post and get the response.
            WebResponse resp;

            try
            {
                resp = req.GetResponse();
            }
            catch (WebException ex)
            {
                resp = ex.Response;
            }

            var sr = new System.IO.StreamReader(resp.GetResponseStream());

        }


    public class SFAttachment
    {
        public string Id { get; set; }
        public string BodyLength { get; set; }
        public DateTime? LastModifiedDate { get; set; }
        public string Name { get; set; }
        public string Body { get; set; }
        public string ParentId { get; set; }
    }

 
I have been able to update fields and add documents to SalesForce but I am having trouble adding an attachment to an object such as an opportunity.  If anyone can see what I am missing that would be a great help.  
 
protected async Task LoadDocument(string parentObjectID)
        {
          
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

            var auth = new AuthenticationClient();
            var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                ? "https://test.salesforce.com/services/oauth2/token"
                : "https://login.salesforce.com/services/oauth2/token";

            await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);

            string boundary = "----" + DateTime.Now.Ticks.ToString("x");

            var uri = auth.InstanceUrl + "/services/data/v37.0/sobjects/attachment/";
            //var uri = auth.InstanceUrl + "/services/data/v37.0/sobjects/Document/";

            var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
            req.Headers.Add("Authorization: OAuth " + auth.AccessToken);
            req.ContentType = "multipart/form-data; boundary=" + boundary;
            req.Method = "POST";
            var os = req.GetRequestStream();

            // Add header for JSON part
            string body = "";
            body += "\r\n--" + boundary + "\r\n";
            //body += "Content-Disposition: form-data; name='attachment'\r\n";
            body += "Content-Disposition: form-data; name='entity_content'\r\n";
            body += "Content-Type: application/json\r\n\r\n";

            var doc = new SFAttachment();
            doc.Name = "test";
            doc.ParentId = parentObjectID;  //result.records[0].Id;

            // Add document object data in JSON
            var ser = new JavaScriptSerializer();
            body += ser.Serialize(doc);

            // Add header for binary part             
            body += "\r\n--" + boundary + "\r\n"; 
            body += "Content-Disposition: form-data; name='body'; filename='test.txt'\r\n";
            body += "Content-Type: binary/octet-stream\r\n\r\n";

            // Add header data to request
            byte[] data = System.Text.Encoding.ASCII.GetBytes(body);
            os.Write(data, 0, data.Length);

            // Add file to reqeust
            //FileStream fileStream = new FileStream(fileBrowser.FileName, FileMode.Open, FileAccess.Read);
            FileStream fileStream = new FileStream(@"C:\test.txt", FileMode.Open, FileAccess.Read);
            byte[] buffer = new byte[4096];
            int bytesRead = 0;
            while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
            {
                os.Write(buffer, 0, bytesRead);
            }
            fileStream.Close();

            // Add trailer
            byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
            os.Write(trailer, 0, trailer.Length);
            os.Close();

            // Do the post and get the response.
            WebResponse resp;

            try
            {
                resp = req.GetResponse();
            }
            catch (WebException ex)
            {
                resp = ex.Response;
            }

            var sr = new System.IO.StreamReader(resp.GetResponseStream());

        }


    public class SFAttachment
    {
        public string Id { get; set; }
        public string BodyLength { get; set; }
        public DateTime? LastModifiedDate { get; set; }
        public string Name { get; set; }
        public string Body { get; set; }
        public string ParentId { get; set; }
    }

 
Greetings...

I have had great success in using .net and the associated API Enterprise generated WSDL and Web Reference for about a year.  I've also used the API in the Sandbox.  I hadn't made a change to the Sandbox or the Production for a couple of months.  Today I did the following in Firefox (I have had more success generating and downloading the WSDL in Firefox)

- Went to Settings/Develop/API/Generate Enterprise WSDL and clicked the GENERATE button to the right of "Generate Enterprise WSDL"
- The result in Firefox was not the normal formatted XML that I had seen in the past (perhaps the update to Firefox did this) What appeared was what looked like one big paragraph of sentences (no xml tags)
-  I right clicked in the white area of the page and "saved as"  test.wsdl
- When I opened test.wsdl, it looked like it alwas does...properly formed XML

Next in VS, I changed the Web Reference property to the Test.wsdl file name and Updated my Web Reference

======================================
Now the issue (finaly)
======================================

When I try to create an instance of SforceService like the code below:

                    SforceService sfService = new SforceService();

I get the following exception:

2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.Name InvalidOperationException
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.Message Unable to generate a temporary class (result=1).
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.Message error CS0030: Cannot convert type 'Mozenda.Business.Salesforce.ListViewRecordColumn[]' to 'Mozenda.Business.Salesforce.ListViewRecordColumn'
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.Message error CS0030: Cannot convert type 'Mozenda.Business.Salesforce.ListViewRecordColumn[]' to 'Mozenda.Business.Salesforce.ListViewRecordColumn'
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.Message error CS0029: Cannot implicitly convert type 'Mozenda.Business.Salesforce.ListViewRecordColumn' to 'Mozenda.Business.Salesforce.ListViewRecordColumn[]'
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.Message error CS0029: Cannot implicitly convert type 'Mozenda.Business.Salesforce.ListViewRecordColumn' to 'Mozenda.Business.Salesforce.ListViewRecordColumn[]'
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.Source System.Xml
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at Mozenda.Business.Salesforce.SforceService..ctor()
2014-09-11 16:35:30.000  Warning SalesforceClient.Connect Exception.Exception.StackTrace    at Mozenda.Business.SalesforceClient.SalesForceClient.Connect()


There is alot if information about "Unable to generate a temporary class (result=1)" doing a Google search, but nothing seems to apply.

- Has Salesforce changed how the Enterprise WSDL is created?

Thanks in advance!!

Russ