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
Bidun TummalaBidun Tummala 

Performing insert and raising a SOAP Fault

I have scenario where i collect input and insert the record and then raise an SOAP Fault if it is not a valied input.

 

But raising a SOAP Fault is rolling back all the the DML operations.

 

Please find the outline:

 

public class SoapmsgException extends Exception {}

Webservice static string ContactMethod(String lpid,String Req)
{

 

Customobj__c co = new Customobj();

co.lpid__c = lpid;

co.Req__c = req;

insert co;

system.debug('customobj'+co);

 

if(lpid.length() == 0)

throw new SoapmsgException ('Invalid LPID or Customer belongs to outfoot Print State');

 

}

 

I am able to perform only one of the two.

Either Throw the exception or do the insert. of throw the SOAP Fault. 

 

i see that debug log giving me desired results. But im sure that there is a roll back happening as soon as there SOAPExceptionMessage is thrown.

 

 

Please hlp me do both the inser and raise a SOAP Fault.

 

 

Thank you.

Alex.AcostaAlex.Acosta

There are 2 things you'll need to do here. One, you'll need to look at this page which shows you how to insert all records and not have any rollbacks if  one of the records fail if that is what you wish....

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_insert.htm

 

The other is you can add errors to records so they fail on inserts/update. In this case you can just do the following....

 

co.Ipid__c = lpid;

if(null == co.Ipid__c || co.Ipid__c.length() == 0)

co.Ipid.addError('Invalid LPID or Customer belongs to outfoot Print State');

 

For more info, please go here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject.htm

 

On your response you'll see if the inserts where successful or not. You can also pull any errors from records while looping through your results.

Bidun TummalaBidun Tummala

Tried insertion in both the ways:

 

Database.SaveResult MySaveResult = Database.Insert(co, true);

 

(to stop the insert from getting rollback)

 

co.lpid__c.addError('bad'+lpid);

 

(to add an error into co__C without and insert operation.

 

to catch the failed results.. but did not help ..

 

the DML operation is getting rolled back as soon as the exception is rasied.

 

once i comment out the line:

throw new SoapmsgException ('Invalid LPID or Customer belongs to outfoot Print State');

 

everything works as expected. But the service needs to respond back with the SOAP Fault message for invalied inputs.

 

Can you please help.