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
Eager-2-LearnEager-2-Learn 

Basic Template approach to write code involving code validation and integration (SOAP)

Hi,

 

I am about to be responsible for an integration project that will entail Web Services (Sending from SFDC to another system).  We do not want force the users to enter all required data that is needed by the other system when they first enter the data into SFDC.  We want a button on the opportunity that will be called 'Submit To...'

 

When the button is clicked we want to have validation done and if it passes build the necessary parameters to feed the API function that sends the data to the other system.

 

Can some help me with the building blocks for such a task.  For example.  do I simply create a class and a function in side that class that does all the nececessary validation on the opportunity and associated data (account, contact roles, etc) and if all is good, build the necessary API call and call it?

 

Is there typically a suggested building block for something like this? If so could you provide a basic outline.

What would the code look like in the button in order to call a class/function if that is the approach?

 

Best Answer chosen by Admin (Salesforce Developers) 
AhmedPotAhmedPot

Hi,

 

You can write validation in custom button javascript method where you can do all validation and call another page which will have all logic to make webservice callout.

eg:

if('{!Opportunity.Product__c}' == 'CL')
window.location.href= "/apex/CL_NewLoanApplication?Id={!Opportunity.Id}";
else
alert('some message');

 

You cannot call a controller method directly. you can redirect to another VF which will have controller and action method to perform all operation when page is getting called. You can provide some custom message in your VF or if you planning to display related information returned from callouts to user.

 

Hope this might help you.

 

Thanks,

Ahmed

All Answers

AhmedPotAhmedPot

Hi,

 

You can write validation in custom button javascript method where you can do all validation and call another page which will have all logic to make webservice callout.

eg:

if('{!Opportunity.Product__c}' == 'CL')
window.location.href= "/apex/CL_NewLoanApplication?Id={!Opportunity.Id}";
else
alert('some message');

 

You cannot call a controller method directly. you can redirect to another VF which will have controller and action method to perform all operation when page is getting called. You can provide some custom message in your VF or if you planning to display related information returned from callouts to user.

 

Hope this might help you.

 

Thanks,

Ahmed

This was selected as the best answer
Eager-2-LearnEager-2-Learn

Thank you!  What you have been so kind to provide is a great start.  If anyone else has feedback more is always better.  :0

 

Since I do not really know Javascript, do you know of any documenation that SFDC has that provides greater detail.  I did do one example I found in the CookBook.  Developing JavaScript at the button does not seem very DEBUG friendly.  In fact the example produced a very unfriendly error message until I allowed popup ups.  I would need to be able to informt the user that they need to allow SFDC site or turn off popups in user friendly message and not a large mislead error message.  Any ideas?