Salesforce Certified Application Architect

Friday 18 December 2015

Trigger being called twice when i was hiiting my rest api call through trigger

Here's the class with the static share property:

public with sharing class MyClass {

     public static set<ID> updateMethod = new set<id>();

    }


Then added to the trigger:
trigger MyTrigger on Lead (before update, after update) { 
for(Lead Lee:trigger.old){

if(!MyClass.updateMethod .Contains(Lee.Id) && !Leads1.isempty() && Trigger.isAfter ){
MyClass.updateMethod .Add(Lee.Id);
ClsName.MethodName(Leads1);    // rest Api class and method
}

Else{
    MyClass.updateMethod .Remove(Lee.Id);
}

}

}


Monday 7 December 2015

You have uncommitted work pending. Please commit or rollback before calling out"

 As per apex you can not perform DML before calloing out the web services i.e Third Party .

Note : The Test.startTest statement must appear before the Test.setMock statement. Also, the calls to DML operations must not be part of the Test.startTest/Test.stopTest block.

This workaround splits the transaction into two separate Ajax processes. The first inserts the record and the second performs the callout and is able to update the newly inserted record.

 // TestWsCallout class

public class TestWsCallout{
  
    Account MyLead;
 
    public PageReference InsertRecord() {
        MyLead = new Account(name = 'Test Account');
        insert MyLead;
        // Calling a Web Service here would throw an exception
        return null;
    }
   

----------------------------------------------------------------------------
    public PageReference CallWebService() {
      
        // Execute a call to a Web Service
        HttpRequest req = new HttpRequest();
        req.setEndpoint('http://MyWebService12345678790.com?id=' + MyLead.Id);
        req.setMethod('GET');
        HttpResponse response = new Http().send(req);
      
        // Simulate an update
        MyLead.Name = 'Test Account 2';
        update MyLead;      
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM, 'WebService Called on New Lead: ' + MyLead.Name));
        return null;
    }
}

Thursday 3 December 2015

Methods defined as TestMethod do not support Web service callouts

when i run the testmethod for webservice class i am getting error message "Methods defined as TestMethod do not support Web service callouts, test skipped"

Solution : 

 Its means you are missing Test.setmock() method in test class .
  

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...