function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Subhranshu MohantySubhranshu Mohanty 

PHP TO SALESFORCE SOAP CALL

Hi All,

My requirement is to create a record for on object & its related attachment in salesforce from php. So for that i created one webservice class & method exposed it .From php side we can able to pass parameters(fields) & record aslo created in salesforce , But How could we pass files which will going to store in the attachment of that record? what should i do to accept that file in my class?
Best Answer chosen by Subhranshu Mohanty
Varun PareekVarun Pareek
Subhranshu - You can pass the base64/ blob content of the file in the web service. As an example, I created a small web service class:
global class WebServiceClass {
    webService static String insertAttachment(String parentId, Blob body, String name) {
        Attachment att = new Attachment();
        att.Name = name;
        att.Body = body;
        insert att;
        return att.Id;
    }
}

The above would generate the WSDL that would contain the blobl paramter as below:
<xsd:element name="body" type="xsd:base64Binary" nillable="true"/>

From PHP, you would then pass the base64 value of the file in the "body" attribute of the XML.

Let me know if this solves your problem. Don't forget to mark it solve to benefit others :)

Regards,
Varun.

All Answers

Varun PareekVarun Pareek
Subhranshu - You can pass the base64/ blob content of the file in the web service. As an example, I created a small web service class:
global class WebServiceClass {
    webService static String insertAttachment(String parentId, Blob body, String name) {
        Attachment att = new Attachment();
        att.Name = name;
        att.Body = body;
        insert att;
        return att.Id;
    }
}

The above would generate the WSDL that would contain the blobl paramter as below:
<xsd:element name="body" type="xsd:base64Binary" nillable="true"/>

From PHP, you would then pass the base64 value of the file in the "body" attribute of the XML.

Let me know if this solves your problem. Don't forget to mark it solve to benefit others :)

Regards,
Varun.
This was selected as the best answer
Subhranshu MohantySubhranshu Mohanty
Thanks Varun for your reply,

Actually i have also created a class to create record for one object , after this whether i need to create another method to insert attachment for same record or in this same method i can manage.

Do you have any idea to implemet this logic in php (means wsdl to use in php files to call & push data)


global class WebServiceClass {

     webService static String insertTestObjcet(String Name, String Phone,Date duedate){
         
       Test__c t=new Test__c();
        t.name=Name;
        t.Phone__c=phone;
        t.DueDate__c=duedat;
        insert t;
        
        return t.id

    }

 }






 
Subhranshu MohantySubhranshu Mohanty
I have managed it by blob type only by passing in method parameter...
Varun PareekVarun Pareek
Hi Subhranshu - I am afraid that I cannot talk from PHP point of view but I believe there should be a way to handle files in PHP just as we have in Salesforce.com. Would recommend posting this query on a PHP forum if you are looking for an answer from PHP pov.

Thanks.