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
sathya82sathya82 

Date Insertion Problem

HI,

 

          I am working with custom webservice in soap, when i comparing the fields in opportinity, i get strucked

 May i know how can i insert Closedate, value by using webservice program.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
digamber.prasaddigamber.prasad

Hi,

 

Please see below code snippet, this should help you;-

 

List<Contact> lstContact = [Select Id from Contact where FirstName =: req.FirstName and LastName =: req.LastName and Email =: req.Email];
if(lstContact.size() > 0){
	//throw error
}else{
	Contact cont = new Contact(FirstName=req.FirstName, LastName=req.LastName, Email = req.LastName);
	insert cont;
}

 Let me know if you have any question about above.

 

Happy to help you!

 

 

All Answers

digamber.prasaddigamber.prasad

Hi,

 

It should be shomething like below:-

 

oppty.CloseDate = system.today();  //you can have any date here as per your requirement

 However, if you are getting date in request parameter, most probably it will come as string and you will need to convert that into Date type.

 

Let me know if you have any question about above.

 

Happy to help you!

 

 

sathya82sathya82

Hi,

 

         How can i prevent duplicates in contact object. That if i insert contact first name,contact lastname,email based upon that how can i prevent duplicates.

digamber.prasaddigamber.prasad

Hi,

 

Please see below code snippet, this should help you;-

 

List<Contact> lstContact = [Select Id from Contact where FirstName =: req.FirstName and LastName =: req.LastName and Email =: req.Email];
if(lstContact.size() > 0){
	//throw error
}else{
	Contact cont = new Contact(FirstName=req.FirstName, LastName=req.LastName, Email = req.LastName);
	insert cont;
}

 Let me know if you have any question about above.

 

Happy to help you!

 

 

This was selected as the best answer
sathya82sathya82

HI,

 

        When i use your date code means if i enter tommrow close date means it taking present date.

        As per my req which date is i came from external system i want to insert simply to sfdc.

 

      Do you have any sample webservice code i am working first time with this integration, if it please share the sample code.

digamber.prasaddigamber.prasad

Hi,

 

If you looked at my code snippet above, in comment I have clearly mentioned that you need to modify according to your requirement. Please share code snippet what you are getting from request to be inserted as closedate. In nut shell, you will need to convert that into sfdc Date data type.

sathya82sathya82

HI,

       when i use below code at that time if i give tommrow's close date means but it not taking that date. it taking present date

     that's means today date.

 

   Opportunity oppty = new Opportunity();         
      oppty.Name = req.oppName;         
oppty.CloseDate = system.today();         
oppty.StageName =req.oppStage;           
insert oppty; 
digamber.prasaddigamber.prasad

Hi,

 

This is coming because of below error code:-

 

oppty.CloseDate = system.today();

 

Could you please try below code:-

oppty.CloseDate = system.today().addDays(-1);

 

Just to be clear, above code now will always set close date to yesterday's date. If you want to make it dynamic, I expect you are getting close date in request, please use that.

 

Let me know if you have any question about this.

 

Happy to help you!

sathya82sathya82

HI,

 

         suppose if i give closedate next month means it takes today-1 date

    

      as per my req the date which was enter by thirdy party that same date should be populate in closedate field.

  

    once check it.