• king s 8
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
how can i connect xml file with apex class???

This is my Apex class:::

global class GoogleAppsRegistrationHandler implements Auth.RegistrationHandler
{
        global User createUser(Id portalId, Auth.UserData data)
        {
                         String email = data.email;
                        if (email == null) return null;

                            User u;
                            try {
                        u = [Select Id, FirstName, LastName, Email, Username from User Where Username = :email];
                                }  
                                   catch (Exception e){
                            return null;
                                                        }
                                            return u;
                                            }
global void updateUser(Id userId, Id portalId, Auth.UserData data){

}
}


This is my Xml file:::
 
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>27.0</apiVersion>
</ApexClass>
 
Throwing this Error :"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Product ID: id value of incorrect type: 01s2800000DYoWpAAL: [Product2Id]"
 
@isTest
private class updt_opty_testclsss{
     @isTest static void testCallout() {
      //Opportunity opty=[select id,Name,Amount,Business_UnitId__c,Opty_num__c From Opportunity Limit 1];
      Opportunity opty1=new opportunity();
      opty1.name='testing';
      opty1.CloseDate=system.today()+1;
      opty1.StageName='Closed Won';
      insert opty1;
     OpportunityLineItem optyline=new OpportunityLineItem();
     
     Product2 prod = new Product2(Name = 'Laptop X200', Family = 'Hardware');
insert prod;
     
     Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
     
     PricebookEntry customPrice=new PricebookEntry(unitprice=1,Product2Id=customPB.Id,
                                         isActive=true,UseStandardPrice = false);
 insert customPrice;
     
     optyline.Opportunityid=opty1.id;
     optyline.Quantity=1;
     optyline.Totalprice=10000;
     optyline.PricebookEntryId =customPrice.id;
     insert optyline;
     
     optyline.Opportunityid=opty1.id;
     optyline.Quantity=1;
     optyline.Totalprice=10000;
     optyline.PricebookEntryId =customPrice.id;
     update optyline;
     
     }
}

Please Help me on this

Regards
kullayappa
Hi Friends,
How to Write the Test class for SOAP http request to response in salesforce please Help me on this.

Error:

"Error MessageSystem.AssertException: Assertion Failed"
@isTest
private class CalloutClassTest {
     @isTest static void testCallout() {
       // Set mock callout class
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
  
       // Call method to test.
        // This causes a fake response to be sent from the class that implements HttpCalloutMock.
        HttpResponse res = CalloutClass.getInfoFromExternalService();
        
        String str='<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"><env:Header><wsa:Action>http://xmlns.oracle.com/apps/incentiveCompensation/cn/disputeManagement/disputeService//DisputeService/createDisputeResponse</wsa:Action><wsa:MessageID>urn:uuid:4b38750d-8da3-46c9-adb3-5e27027e5606</wsa:MessageID></env:Header><env:Body><ns0:createDisputeResponse xmlns:ns0="http://xmlns.oracle.com/apps/incentiveCompensation/cn/disputeManagement/disputeService/types/"><ns2:result xmlns:ns2="http://xmlns.oracle.com/apps/incentiveCompensation/cn/disputeManagement/disputeService/types/" xmlns:ns1="http://xmlns.oracle.com/apps/incentiveCompensation/cn/disputeManagement/disputeService/" xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:DisputeP"><ns1:DisputeId>300000040631350</ns1:DisputeId><ns1:ObjectVersionNumber>1</ns1:ObjectVersionNumber><ns1:TaskId>147</ns1:TaskId><ns1:OrgId>300000040409422</ns1:OrgId><ns1:DisputeType>INCORRECT_CREDIT</ns1:DisputeType><ns1:ParticipantId>12001</ns1:ParticipantId><ns1:TransactionType>null</ns1:TransactionType><ns1:SourceTrxNumber>null</ns1:SourceTrxNumber><ns1:SourceEventDate>2016-12-03</ns1:SourceEventDate><ns1:TransactionQuantity xsi:nil="true"/><ns1:CustomerId xsi:nil="true"/><ns1:InventoryItemId xsi:nil="true"/><ns1:CurrencyCode>USD</ns1:CurrencyCode><ns1:ClosedDate xsi:nil="true"/><ns1:DisputeDescription>dddddddddddd</ns1:DisputeDescription><ns1:DisputeName>test23</ns1:DisputeName><ns1:TransactionAmount xsi:nil="true"/><ns1:DisputeJustification>ssssssss</ns1:DisputeJustification><ns1:ExpectedValue>200</ns1:ExpectedValue><ns1:ActualValue>100</ns1:ActualValue><ns1:AttachmentName xsi:nil="true"/><ns1:PeriodId xsi:nil="true"/><ns1:PrimaryParticipantId xsi:nil="true"/><ns1:PlanComponentName xsi:nil="true"/><ns1:RequestorParticipantId xsi:nil="true"/><ns1:PaymentAdjustmentType xsi:nil="true"/><ns1:BusinessUnit xsi:nil="true"/><ns1:DisputeTypeMeaning xsi:nil="true"/><ns1:ParticipantName>kullayappa Adapala</ns1:ParticipantName><ns1:TransactionTypeMeaning xsi:nil="true"/><ns1:PaymentAdjustmentTypeMeaning xsi:nil="true"/><ns1:Customer xsi:nil="true"/><ns1:PrimaryParticipantName xsi:nil="true"/><ns1:Item xsi:nil="true"/><ns1:PeriodName xsi:nil="true"/><ns1:MeasureType>QUANTITY</ns1:MeasureType><ns1:Comment xsi:nil="true"/></ns2:result></ns0:createDisputeResponse></env:Body></env:Envelope>';
  
        // Verify response received contains fake values
         String contentType = res.getHeader('Content-Type');
         System.assert(contentType =='text/xml');
         //System.assertEquals(contentType ,'text/xml');
         String actualResponseBody = res.getBody();
         String expectedResponseBody = str;
         System.assertEquals(actualResponseBody, expectedResponseBody);
        System.assertEquals(200, res.getStatusCode());
    }
}
Thanks
kullayappa
Throwing this Error :"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Product ID: id value of incorrect type: 01s2800000DYoWpAAL: [Product2Id]"
 
@isTest
private class updt_opty_testclsss{
     @isTest static void testCallout() {
      //Opportunity opty=[select id,Name,Amount,Business_UnitId__c,Opty_num__c From Opportunity Limit 1];
      Opportunity opty1=new opportunity();
      opty1.name='testing';
      opty1.CloseDate=system.today()+1;
      opty1.StageName='Closed Won';
      insert opty1;
     OpportunityLineItem optyline=new OpportunityLineItem();
     
     Product2 prod = new Product2(Name = 'Laptop X200', Family = 'Hardware');
insert prod;
     
     Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
     
     PricebookEntry customPrice=new PricebookEntry(unitprice=1,Product2Id=customPB.Id,
                                         isActive=true,UseStandardPrice = false);
 insert customPrice;
     
     optyline.Opportunityid=opty1.id;
     optyline.Quantity=1;
     optyline.Totalprice=10000;
     optyline.PricebookEntryId =customPrice.id;
     insert optyline;
     
     optyline.Opportunityid=opty1.id;
     optyline.Quantity=1;
     optyline.Totalprice=10000;
     optyline.PricebookEntryId =customPrice.id;
     update optyline;
     
     }
}

Please Help me on this

Regards
kullayappa
Hi,
I have following After Update Trigger... I have to write test class for same...
Please some one help me..?

trigger AccountChanged on Asset (after update) {

    List<Opportunity> OppList= new List<Opportunity>();
   
    for (Asset newAsset : Trigger.new) {

                                        // If account of equipment is changed..
        if ( newAsset.AccountId != Trigger.oldMap.get( newAsset.Id ).AccountId ){    
            
                                        //Create new Opportunity for Sales i.e. OEM Record Type...
            Opportunity newOpp1 = new Opportunity();
            
            Id oppRecordTypeId1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('OEM').getRecordTypeId();
            newOpp1.RecordTypeId = oppRecordTypeId1;
            
            
            newOpp1.Asset__c = newAsset.id;
            newOpp1.Name = 'New Sales Opportunity';
            newOpp1.AccountId = newAsset.AccountId;
            newOpp1.StageName = 'Qualification';
            newOpp1.CloseDate = system.today();
            

            OppList.add(newOpp1);
            
          
                                            //Create new Opportunity for Parts i.e. Parts Record Type...
            Opportunity newOpp2 = new Opportunity();
            
            Id oppRecordTypeId2 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Parts').getRecordTypeId();
            newOpp2.RecordTypeId = oppRecordTypeId2;
            
            
            newOpp2.Asset__c = newAsset.id;
            newOpp2.Name = 'New Parts Opportunity';
            newOpp2.AccountId = newAsset.AccountId;
            newOpp2.StageName = 'Qualification';
            newOpp2.CloseDate = system.today();
            

            OppList.add(newOpp2);
            
            If(OppList.Size()>0){
            Insert OppList;
            }
        }

    }
}
how can i connect xml file with apex class???

This is my Apex class:::

global class GoogleAppsRegistrationHandler implements Auth.RegistrationHandler
{
        global User createUser(Id portalId, Auth.UserData data)
        {
                         String email = data.email;
                        if (email == null) return null;

                            User u;
                            try {
                        u = [Select Id, FirstName, LastName, Email, Username from User Where Username = :email];
                                }  
                                   catch (Exception e){
                            return null;
                                                        }
                                            return u;
                                            }
global void updateUser(Id userId, Id portalId, Auth.UserData data){

}
}


This is my Xml file:::
 
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>27.0</apiVersion>
</ApexClass>
 
Example for creating Opportunity :
curl https://na1.salesforce.com/services/data/v20.0/sobjects/Opportunity/0AASSFGSEID -H "Authorization: Bearer token" -H "Content-Type: application/json" -d @newrecord.json -X PATCH
Example request body newrecord.json file :
{ "Name":"FFNEw","CloseDate":"2015/02/04","StageName":"Prospecting","Probability":10 }
My ASP.net code :
 
using (WebClient client = new WebClient())
{
client.Headers.Add("Authorization", "Bearer " + token.access_token); client.Headers.Add("Content-Type", "application/json");
var request = (HttpWebRequest)(HttpWebRequest.Create(token.instance_url + "/services/data/v20.0/sobjects/Opportunity/0AASSFGSEID"));
request.Method = "PATCH";
using (var requestWriter = new StreamWriter(request.GetRequestStream()))
{
  requestWriter.Write(json);
  requestWriter.Flush();
  requestWriter.Close();
}
var response = request.GetResponse();
}
Getting Error 400 Bad Request in "request.GetResponse()".