+ Start a Discussion
sathya82sathya82 

Opportunity insertion Problem in soap

while insert the opportunity it throws an error requried field is missing[Name,StageName] but i asign the requried fields are Name,StageName the field my code is

global class OppWr {
    webservice String oName;
    webservice String ocDate;
    webservice String oStage;
}

// some other code which consit of account,contact insert code

List<Opportunity> lstopp = new List<Opportunity>();

{
    OppWr o1 = new OppWr(); 
    Opportunity o = new Opportunity();
    o.Name = o1.oName;
    o.CloseDate = system.today();
    o.StageName = o1.oStage;
    lstopp.add(o);
}
insert lstopp;

GlynAGlynA

@sathya82,

 

I think the problem is that you are initializing the Name and StageName fields from the oName and oStage fields of a new OppWr instance.  You don't show the constructor for the OppWr class, so I will assume it doesn't have one.  That means that the oName and oStage fields are both null when you copy them into the Opportunity.  So, you are not actually setting those fields - it just looks like you are.

 

I don't know what you intend to be doing, so I can't offer a fix; but I hope this points you in the right direction so you can come up with a solution of your own.

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator

sathya82sathya82

@GlynA

 

       Thanq for giving reply i do some modifications in my program it's working properly. here one trouble how can i map my

opportunity to account. my code is

 

  upsert AccountList;  by uisng this statement i am upserting my all account fields.

 

    insert lstopp;  by using this statement i am inserting opportunity fields how can i map ..??

GlynAGlynA

I'm not sure whether you want to map from Opportunity IDs to Account records, or from Account IDs to lists of Opportunities, so here is code for both:

 

    public Map<Id,Account> createMapFromOpportunityIDToAccount( List<Opportunity> list_Opportunities, List<Account> list_Accounts )
    {
        Map<Id,Account> map_Accounts = (new Map<Id,Account>()).putAll( list_Accounts );

        Map<Id,Account> map_OpportunityID_Account = new Map<Id,Account>();

        for ( Opportunity theOpportunity : list_Opportunities )
        {
            map_OpportunityID_Account.put( theOpportunity.Id, map_Accounts.get( theOpportunity.AccountId ) );
        }
        return map_OpportunityID_Account;
    }

    public Map<Id,List<Opportunity>> createMapFromAccountIDToOpportunities( List<Opportunity> list_Opportunities )
    {
        Map<Id,List<Opportunity>> map_AccountID_Opportunities = new Map<Id,List<Opportunity>>();

        for ( Opportunity theOpportunity : list_Opportunities )
        {
            if ( !map_AccountID_Opportunities.containsKey( theOpportunity.AccountId ) )
            {
                map_AccountID_Opportunities.put( theOpportunity.AccountId, new List<Opportunity>() );
            }
            map_AccountID_Opportunities.get( theOpportunity.AccountId ).add( theOpportunity );
        }
        return map_AccountID_Opportunities;
    }

I hope this helps.  In the meantime, since my previous post provided the solution to you problem, could you please mark it as the solution.  Thanks!

 

-Glyn