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 

Custom weservice

HI,

 

  I created a customwebservice for account,contac,opportunity insertion
all are inserting good, but here is one problem

when i click on account tab at that time contact,opportunity belongs to that account showing.

 

when i click on contact tab at that time opportunity is not showing in releated list block.

 

but that contact have opportunity may i know what i have to do. i have to do any modifications in my code

digamber.prasaddigamber.prasad

Hi,

 

Can you please share your code snippet?

SSinghSSingh

Insert an OpportunityContactRole record as well along with account,contact, opportunity insertion. Hope this would be helpful

 

SS

sathya82sathya82

@digamberlucky

 

     

i am below code for account,contac,opportunity insertion

 

Account a = new Account();
a.Name = r.accName;
a.AccountNumber =String.valueOf(r.accNumber);
insert a;


Contact c = new Contact();
c.AccountId = a.Id;
c.FirstName = r.fName;
c.LastName = r.lName;
insert c;


Opportunity o = new Opportunity();
o.AccountId = a.Id;
// o.OpportunityContactRoles =c.Id;
o.Name = req.oName;
o.StageName =r.oStage;
insert o;

digamber.prasaddigamber.prasad

Hi,

 

Assuming, you have a contact lookup on Opportunity, you can use below code snippet to have contact-opportunity direct relationship. And you should be able to see desired related list.

 

Opportunity o = new Opportunity();
o.AccountId = a.Id;
o.Contact__c =c.Id;		//assuming there is a contact lookup on opportunity
o.Name = req.oName;
o.StageName =r.oStage;
insert o;

 

Let me know if you have any question.

sathya82sathya82

@digamberlucky

 

   Hi,

 

       As per code i think i can insert single contact at a time, if another system move multiple accounts to sfdc at that time i want to change any code. to insert multiple accounts

digamber.prasaddigamber.prasad

Hi,

 

I guess for that you will receive multiple information regarding account in request. Will you please share the structure for same.

sathya82sathya82

@digamberlucky

 

   HI,

 

    May i know how can i modify my code if i get multiple accounts insertion

 

   global class Integration

     {

 

        global class AllObjects

       {


          webservice string aName;

          webservice string aNum;

 

         webservice string cName

    }

 

     global class Return

    {

        webservice string raName;

   }

 

   webservice static Return Allobjectsmethod(AllObjects a1)

   {

         Account a = new Account();

         a.Name  = a1.aName;

         a.Number = a1.aNum;

         insert a;

     

       Contact c  = new Contact();

        c.Name = a1.cName;

        insert c;

 

      Return r  =  new Return();

      r.raName = a.Name;

      return r;

 

 }

digamber.prasaddigamber.prasad

Hi,

 

First of all AllObjects should return list of account related information. Could you please let me know how it will look like. After that I can suggest modification in your code.

 

global class AllObjects
{ //below account related information needs to be list webservice string aName; webservice string aNum; webservice string cName }

 

 

sathya82sathya82

@digamberlucky

 

 

     My webservice is working for single account,contact insert i am testing by soapUI tool

 

    but from third party system they push multiple accunts for that my webservice have to insert multiple accounts at a time rather than single account insertion based on that how can i modify my webservice.

 

     i can't understand where i have to modify my code could you plz modify my code.and where i have to put list for account, contact, opportunity.

digamber.prasaddigamber.prasad

Hi,

 

Possible code snippet may look like below:-

 

global class Integration
{

	global class AllObjects
	{
	
		webservice string aName1;
		webservice string aNum1;
		webservice string aName2;
		webservice string aNum2;
		webservice string aName3;
		webservice string aNum3;

		webservice string cName
	}

	global class Return
	{
		webservice string raName;
	}
 
	webservice static Return Allobjectsmethod(AllObjects a1)
	{
		List<Account> lstAccount = new List<Account>();
		Account a1 = new Account();
		a1.Name  = a1.aName1;
		a1.Number = a1.aNum1;
		
		Account a2 = new Account();
		a2.Name  = a1.aName2;
		a2.Number = a1.aNum2;
		
		Account a3 = new Account();
		a3.Name  = a1.aName3;
		a3.Number = a1.aNum3;
		
		lstAccount.add(a1);
		lstAccount.add(a2);
		lstAccount.add(a3);
		
		insert lstAccount;

		Contact c  = new Contact();
		c.Name = a1.cName;
		insert c;

		Return r  =  new Return();
		r.raName = a.Name;
		return r;
 
	}
}

 Let me know if you have any specific question.

 

Happy to help you!

 

 

sathya82sathya82

@

 

  Suppose if i have 90 accounts which are pushing from thirdparty at that time 

 

   i hae to create a1,a2,a3......i think this is not a way can you one check it. any modifications ..in code.

digamber.prasaddigamber.prasad

That's why I said you earlier that requested will have all account related information in list.

sathya82sathya82

@

 

       May i know how can i modofied my code for different bulk insert of records.

digamber.prasaddigamber.prasad

Hi,

 

In that case your global class may look like something below:-

 

global class AllObjects
{
	global class Accounts{
		webservice String aName1;
		webservice String aNum1;
	}
	
	WebService List<Accounts> lstAccounts;

	
	webservice string cName
}

 

sathya82sathya82

@digamberlucky

 

  below is my code how can i modified that

 

    

global class Integration {

     global class AllObjects {

         webservice string aName;
         webservice string aNum;

         webservice string cName
     }

     global class Return {
         webservice string raName;
     }

     webservice static Return Allobjectsmethod(AllObjects a1) {
         Account a = new Account();
         a.Name = a1.aName;
         a.Number = a1.aNum;
         insert a;

         Contact c = new Contact();
         c.Name = a1.cName;
         insert c;

         Return r = new Return();
         r.raName = a.Name;
         return r;

     }