+ Start a Discussion
Liam JeongLiam Jeong 
Hey folks,

I would like to create a custom report type for Approval History(ProcessInstanceStep).

My first approach was creating a trigger or record-triggered flow on the ProcessInstanceStep object.
But for some reason, Salesforce doesn't allow me to create a trigger on the object.

Background information,
There are more than 2,000 submitted approvals daily based.
The client wants to maximize declarative tools' usability.(Not Programatical solution)

How should I resolve this issue?

Much obliged, in advance.
Liam
Best Answer chosen by Liam Jeong
Naveen KNNaveen KN
Thanks for the details, Liam.

I was in the assumption that it is for a single object. Then, it will be difficult to handle all the approval processes(multiple objects) from a single place.

I think we have to Go with Batch apex now!

--
Naveen 
 
alxhdezalxhdez 
Class Controller:
public with sharing class controllerquoteVisual {
    
    public String title {get;set;}
    public Quote quote {get;set;}
    public List<quoteLineItem> qliList {get;set;}
    //public List<Product2> products {get; set;}
    
    //Capturar Nombre de familia y lista de productos
    public Map<String,List<ObjectWrapper>> mapFamily {get;set;}
    //public Map<String,List<QuoteLineItem>> mapFamilyqli {get;set;}
    //Captutar Nombre de familia y recuento de Productos que se mostrarán
    public Map<String, Integer> FamilyCountMap{get;set;}
	//Capturar Lista de nombres de familia de productos 
    public List<String> FamilyList {get;set;}
    //ProductList o products ya con los productos que se requieren mostrar
    
    public controllerquoteVisual(){
        
        Id id = ApexPages.currentPage().getParameters().get('id');
        
        //Obtener quote mediante el Id que arroja la visualforce desde quote
        quote = [SELECT Id, Name, TotalPrice, GrandTotal, ExpirationDate, AccountId, Total_Hours__c, OpportunityId, QuoteNumber   
                FROM quote WHERE Id=:id LIMIT 1];
        
        Opportunity opportunity = [SELECT Name FROM Opportunity WHERE Id=:quote.OpportunityId LIMIT 1];
        
        title = opportunity.Name.split('\\|')[0] + opportunity.Name.split('\\|')[1];
        
        Apexpages.currentPage().getHeaders().put('content-disposition', 'inline; filename='+title+ ' - ' +quote.QuoteNumber );
        
        //Obtener lista de quoteLineItems de la actual quote
        qliList = [SELECT Id, Product2Id, Quantity  
                    FROM quoteLineItem WHERE quoteId=:Id];
       
        ///////////////////////////////////////////////
        //Separar productos por tipo de familia 
        mapFamily = new Map<String, List<ObjectWrapper>>(); 
        FamilyCountMap = new Map<String, Integer>();
        FamilyList = new List<String>();
        
        List<quoteLineItem> finalqliList = new List<QuoteLineItem>();
        finalqliList = qliList;
        
        //Agrupar por nombre de familia y preparar los map
        for(QuoteLineItem qq: finalqliList){
            Product2 famObj = [SELECT Id, Name, Family, Description
                   FROM Product2 WHERE Id=:qq.Product2Id];
            if(famObj.Family == null){
                famObj.Family= 'Sin clasificación';
            }
            
            //List<QuoteLineItem> qq = qliList;
            List<ObjectWrapper> proList = new List<ObjectWrapper>();
            //Verificar si el map ya contiene el mismo nombre por familia
            if(mapFamily.containsKey(famObj.Family)){
            	//Recuperar lista de productos existentes
            	proList = mapFamily.get(famObj.Family);
            	//Meter el nuevo producto a la lista
                proList.add(new ObjectWrapper(qq, famObj));
                    
                mapFamily.put(famObj.Family, proList);
                    
                //Almacenar filas por nombre de familia
                FamilyCountMap.put(famObj.Family, proList.size());
            }
            else{
            	//crear nuevo map del nombre de familia //.fammily,name,etc
                //proList.add(famObj);
                proList.add(new ObjectWrapper(qq, famObj));
                mapFamily.put(famObj.Family, proList); 
                    
                //Almacenar filas por nombre de familia
                FamilyCountMap.put(famObj.Family, proList.size());
            }
        	FamilyList = new List<String>(mapFamily.keySet());
    	}
        
    }
    
    public class ObjectWrapper{
        //Campos QuoteLineItems
        //Public Id QliId{get;set;}
        Public Decimal Quantity{get;set;}
        
        //Campos Producto
        Public String Name{get;set;}
        Public String Family{get;set;}
        Public String Description{get;set;}
        
        public ObjectWrapper(QuoteLineItem ql, Product2 pr){
            //this.QliId = ql.Id;
            this.Quantity = ql.Quantity;
            
            this.Name = pr.Name;
            this.Family = pr.Family;
            this.Description = pr.Description;
        }  
    }
}

Test Class (68%, wrapper class is missing)
@isTest
public class TestControllerquoteVisual{
	@isTest
    static void testControllerVFP(){
        
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book', 
                                       Description = 'Price Book Products', IsActive = true );
        insert pb;
        
        Product2 prod = new Product2(Name = 'Test Product', Description = 'Descripción Test', 
                                     Family = 'Salesforce Service Cloud', IsActive = true);
        insert prod;
        
        List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 
                                           where IsStandard = true ];
 
    	List<PricebookEntry> listPriceBook = new List<PricebookEntry>();
     	for(Pricebook2 p : standardPbList ){
      		PricebookEntry pbe = New PricebookEntry ();
      		pbe = new PricebookEntry(Pricebook2Id = p.Id, Product2Id = prod.Id, 
                                     UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
       		listPriceBook.add(pbe);
     	}
        insert listPriceBook;
        
        Opportunity opp = new Opportunity(Name = 'Test Opportunity', 
                                          StageName = 'Discovery', Product_Families__c='Salesforce Service Cloud' ,CloseDate = system.today());
        insert opp;
        
        Quote quttest = new Quote (Name = 'Quote Test' , OpportunityId = opp.id , Pricebook2Id = pb.id );
        insert quttest;
        
        List<QuoteLineItem> listval = new List<QuoteLineItem>();
        for(PricebookEntry pricebook : listPriceBook){
            QuoteLineItem qutlineitemtest = new QuoteLineItem ();
            qutlineitemtest = new QuoteLineItem(QuoteId = quttest.id, Quantity = 3.00,UnitPrice = 12, PricebookEntryId = pricebook.id);
            
            listval.add(qutlineitemtest);
        }
        insert listval;    
            
        QuoteLineItem qlitem = new QuoteLineItem(Quantity = 3.00, UnitPrice = 12 );
        
        
        Test.startTest();
            ApexPages.currentPage().getParameters().put('id', String.valueOf(quttest.Id));
            controllerquoteVisual controllerVfp= new controllerquoteVisual();
            //controllerVfp = new controllerquoteVisual();
        
            controllerquoteVisual.ObjectWrapper wrapper = new controllerquoteVisual.ObjectWrapper(qlitem, prod);
            
            wrapper.Quantity = 3.00;
                
            wrapper.Name = prod.Name;
            wrapper.Description = prod.Description;
            wrapper.Family = prod.Family;
        
        Test.stopTest();
        
    }

}

 
Best Answer chosen by alxhdez
Maharajan CMaharajan C
Hi alxhdez,

Please try the below test class you will get 97%:
 
@isTest
public class TestControllerquoteVisual{
    @isTest
    static void testControllerVFP(){
        
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book', 
                                       Description = 'Price Book Products', IsActive = true );
        insert pb;
        
        Product2 prod = new Product2(Name = 'Test Product', Description = 'Descripción Test', 
                                     Family = 'Salesforce Service Cloud', IsActive = true);
        insert prod;
        
        List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 
                                           where IsStandard = true ];
        
        Id standardPBId = Test.getStandardPricebookId();
        
        PricebookEntry pbe = New PricebookEntry (Pricebook2Id = standardPBId, Product2Id = prod.Id, 
                                                 UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
        insert pbe;
        
        Opportunity opp = new Opportunity(Name = 'Test \\| Opportunity', 
                                          StageName = 'Discovery' ,CloseDate = system.today());
        insert opp;
        
        Quote quttest = new Quote (Name = 'Quote Test' , OpportunityId = opp.id , Pricebook2Id = standardPBId );
        insert quttest;
        
        QuoteLineItem qlitem = new QuoteLineItem(QuoteId = quttest.id, Quantity = 3.00,UnitPrice = 12, PricebookEntryId = pbe.id,Product2Id = prod.Id);
        insert qlitem;
        
        QuoteLineItem qlitem1 = new QuoteLineItem(QuoteId = quttest.id, Quantity = 5.00,UnitPrice = 10, PricebookEntryId = pbe.id,Product2Id = prod.Id);
        insert qlitem1;
        
        Test.startTest();
        ApexPages.currentPage().getParameters().put('id', String.valueOf(quttest.Id));
        controllerquoteVisual controllerVfp= new controllerquoteVisual();
        
        controllerquoteVisual.ObjectWrapper wrapper = new controllerquoteVisual.ObjectWrapper(qlitem, prod);
        
        wrapper.Quantity = 3.00;
        
        wrapper.Name = prod.Name;
        wrapper.Description = prod.Description;
        wrapper.Family = prod.Family;
        
        Test.stopTest();
        
    }
    
}

Thanks,
Maharajan.C
Alex Calder 10Alex Calder 10 
I am struggleing understanding how to write test units for this class. 
 
//@RestResource(urlMapping='/Google/*') is used to tell the class that it is a REST resource used for POST GET etc
@RestResource(urlMapping='/Google/*')
global with sharing class GoogleWebHookListener {
    //HttpPost tells the method that it will be a POST method
    @HttpPost
    global static void handlePost() {
        
        //set up varibles for the Lead
        String name;
        String phone;
        String email;
        String postCode;
        String firstName;
        String lastName;
        
        //try to do the JSON deserialization and Lead Creation
        //******EXAMPLE JSON AT BOTTOM*****
        try
        {
            // This gets the body of the webhook makes the body a string and sets the string to the variable 'jsonString'
            String jsonString = RestContext.request.requestBody.toString();
            //This deserializes the JSON based on the the properties setup in the Class GoogleJsonLeadExample
            GoogleJsonLeadExample g = (GoogleJsonLeadExample)JSON.deserialize(jsonString, GoogleJsonLeadExample.class);
            
            //This tests the JSON to see if it is legit.
            if(g.google_key == ''){
                
                //This loops through the JSON array set up in the Class GoogleJsonLeadExample
                
               for(GoogleJsonLeadExample.userData d : g.user_column_data)
               {
                   if(d.column_name == 'Full Name')
                   {
                       //The JSON has Full Name, this breaks Full Name into First and Last Names
                        name = d.string_value;
                        List<String> names = name.split(' ');
                       	firstName = names[0];
                        lastName = names[1];
                           
                   }
                   if(d.column_name == 'User Phone')
                   {
                        phone = d.string_value;
                   }
                   if(d.column_name == 'User Email')
                   {
                        email = d.string_value;
                   }
                   if(d.column_name == 'Postal Code')
                   {
                       postCode = d.string_value;
                   }
               }
              
                //This creates the Lead                 
            Lead detail = new Lead();
            detail.LastName = lastName;
            detail.FirstName = firstName;
            detail.Phone = phone;
            detail.Company = name;
            detail.Email = email;
            detail.OwnerId = '0051Q00000GrANL'; // This Id is the user Hubspot.
            insert detail;
           
            }
                                        
        }
        catch (DMLException e)
        {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
    }

}

 
Best Answer chosen by Alex Calder 10
Maharajan CMaharajan C
Hi Alex,

Please try the below test class:
 
@isTest
public class GoogleWebHookListenerTest {
    static testmethod void doPostTest(){
        RestRequest request = new RestRequest();
        request.requestUri ='/services/apexrest/Google';
        request.httpMethod = 'POST';
        String str = '{'+ '"lead_id": "TeSter",'+'"user_column_data": ['+'{'+'"column_name": "Full Name",'+'"string_value": "FirstName LastName",'+'"column_id": "FULL_NAME"'+'},'+'{'+'"column_name": "User Phone",'+'"string_value": "+16505550123",'+' "column_id": "PHONE_NUMBER"'+'},'+'{'+'"column_name": "User Email",'+'"string_value": "test@example.com",'+'"column_id": "EMAIL"'+'},'+'{'+'"column_name": "Postal Code",'+'"string_value": "94043",'+'"column_id": "POSTAL_CODE"'+'},'+'{'+'"string_value": "Roofing",'+'"column_id": "SERVICE"'+'}'+'],'+'"api_version": "1.0",'+'"form_id": 18698608977,'+'"campaign_id": 991214827,'+'"google_key": "",'+'"is_test": true,'+'"gcl_id": "CcDdEeFfGgHhIiJjKkLl",'+'"adgroup_id": 20000000000,'+'"creative_id": 30000000000'+'}';
        request.requestBody = Blob.valueof(Str);
        
        RestContext.request = request;
        GoogleWebHookListener.handlePost();
    }
}

Thanks,
Maharajan.C
Best Answer chosen by Deepak Kumar Singh 15
charchit nirayanwalcharchit nirayanwal
use map 
 

public class thecodeclass {
    public static void main(){
        list<integer> listt=new list<integer>{2,3,2,2,4};
        map<integer,integer> amap=new map<integer,integer>();
        for(integer a:listt){
            if(amap.get(a)<>null){
                amap.put(a, amap.get(a)+1);}
            else{
                amap.put(a,1);
            }
        } 
        system.debug(amap);
    }
}
SFDCIronManSFDCIronMan 
Help me Create a Trigger for CheckBox to clone Opportunity and OpportunityLineItem
//This is what i have coded please help resolve this
trigger CloneParentOpportunityTrigger on Opportunity (After insert,After update) 
{
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    Map<Id,Opportunity> OldOppId = new Map<Id,Opportunity>();
    Opportunity newopp = new Opportunity(); 
    if(Trigger.IsAfter)
    {
        if(Trigger.IsInsert || Trigger.IsUpdate)
        {
            if(newopp.Clone_Opportunity__c)
            {
                for(Opportunity opp : Trigger.new)
                { 
                    //opportunity list item
                    newopp.Name = opp.Name;
                    newopp.AccountId = opp.AccountId;
                    newopp.Product_Type__c = opp.Product_Type__c;
                    newopp.CloseDate = opp.CloseDate;
                    newopp.StageName = opp.StageName;
                    newopp.Payment_Frequency__c = opp.Payment_Frequency__c;
                    newopp.Most_Recent_Invoice_Date__c  = opp.Most_Recent_Invoice_Date__c;
                    newopp.Billing_Start_Date__c = opp.Billing_Start_Date__c;
                    newopp.Parent_Opportunity__c = opp.Id;
                    oppsToUpdate.add(newopp);
                    OldOppId.put(opp.id,opp);
                }
                
                insert oppsToUpdate;
                
                Map<Id,Opportunity> NewOppId = new Map<Id,Opportunity>();
                for(Opportunity opp1 : oppsToUpdate)
                {
                    NewOppId.put(opp1.Id, opp1);
                }
                
                List<OpportunityLineItem> oppitemList = new List<OpportunityLineItem>([SELECT Id, Product2Id, Quantity, UnitPrice, OpportunityId FROM OpportunityLineItem Where OpportunityId IN : OldOppId.keyset()]);
                for(OpportunityLineItem oppitem : oppitemList)
                {
                    OpportunityLineItem oli = new OpportunityLineitem();
                    oli.OpportunityId = NewOppId.get(oppitem.OpportunityId).Id;
                    oli.Product2Id = oppitem.Product2Id;
                    oli.Quantity = oppitem.Quantity;
                    oli.UnitPrice = oppitem.UnitPrice;
                    oppitemlist.add(oli);
                }
                insert oppitemList;
            }
        }   
    }
}
Best Answer chosen by SFDCIronMan
Maharajan CMaharajan C
Hi,

Even after you have tried above code and still facing the same error then use below things.

Maximum Trigger Depth Exceeded Error in Salesforce occurs due to recursion in your CloneParentOpportunityTrigger trigger. This recurssion due some opportunity Line Item Trigger or triggers or automation firing your CloneParentOpportunityTrigger trigger again. So it's going unstoppable

Use the below  way to avoid this error:

Add static Boolean in trigger context to handle this recurrsion error - Commonly used trick.

Create New Apex Class:

 
public class RecursiveTriggerHandler{
    public static Boolean isFirstTime = true;
}

And Update your trigger like below with static boolean check :
 
trigger CloneParentOpportunityTrigger on Opportunity (After insert,After update) 
{
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    Map<Id,Opportunity> OldOppId = new Map<Id,Opportunity>();
    Map<Id,List<OpportunityLineItem>> oplitemsMap = new  Map<Id,List<OpportunityLineItem>>();
    List<OpportunityLineItem> oppitemlist = new List<OpportunityLineItem>();
    Set<id> oppIds = new set<Id>();
    if(RecursiveTriggerHandler.isFirstTime)
    {
        RecursiveTriggerHandler.isFirstTime = false;
        if(Trigger.IsAfter)
        {
            if(Trigger.IsInsert)
            {
                for(Opportunity opp : Trigger.new)
                { 
                    if(opp.Clone_Opportunity__c){
                        oppIds.add(opp.Id);
                        Opportunity newopp = new Opportunity(); 
                        newopp.Name = opp.Name;
                        newopp.AccountId = opp.AccountId;
                        //newopp.Product_Type__c = opp.Product_Type__c;
                        newopp.CloseDate = opp.CloseDate;
                        newopp.StageName = opp.StageName;
                        //newopp.Payment_Frequency__c = opp.Payment_Frequency__c;
                        //newopp.Most_Recent_Invoice_Date__c  = opp.Most_Recent_Invoice_Date__c;
                        //newopp.Billing_Start_Date__c = opp.Billing_Start_Date__c;
                        newopp.Parent_Opportunity__c = opp.Id;
                        oppsToUpdate.add(newopp);
                    }
                }
            }
            else if(Trigger.IsUpdate){
                for(Opportunity opp : Trigger.new)
                { 
                    if(Trigger.oldMap.get(opp.Id).Clone_Opportunity__c != opp.Clone_Opportunity__c && opp.Clone_Opportunity__c){
                        oppIds.add(opp.Id);
                        Opportunity newopp = new Opportunity(); 
                        newopp.Name = opp.Name;
                        newopp.AccountId = opp.AccountId;
                        //newopp.Product_Type__c = opp.Product_Type__c;
                        newopp.CloseDate = opp.CloseDate;
                        newopp.StageName = opp.StageName;
                        //newopp.Payment_Frequency__c = opp.Payment_Frequency__c;
                        //newopp.Most_Recent_Invoice_Date__c  = opp.Most_Recent_Invoice_Date__c;
                        //newopp.Billing_Start_Date__c = opp.Billing_Start_Date__c;
                        newopp.Parent_Opportunity__c = opp.Id;
                        oppsToUpdate.add(newopp);
                    }
                }       
            }
        }
        
        for(OpportunityLineitem opl : [SELECT Id, Product2Id, Quantity, UnitPrice,pricebookentryid, OpportunityId FROM OpportunityLineItem Where OpportunityId IN : oppIds]){
            if(!oplitemsMap.containsKey(opl.OpportunityId)){
                oplitemsMap.put(opl.OpportunityId, new List<OpportunityLineitem>{opl});
            }
            else{
                oplitemsMap.get(opl.OpportunityId).add(opl);
            }
        }
        
        if(!oppsToUpdate.IsEmpty()){
            insert oppsToUpdate;
            
            for(Opportunity op : oppsToUpdate){
                system.debug(' Id --> ' + op.Id);
                system.debug(' Parent Id --> ' + op.Parent_Opportunity__c);
                if(oplitemsMap.containsKey(op.Parent_Opportunity__c)){
                    for(OpportunityLineitem ol : oplitemsMap.get(op.Parent_Opportunity__c)){
                        OpportunityLineItem oli = new OpportunityLineitem();
                        oli.OpportunityId = op.Id;
                        oli.Product2Id = ol.Product2Id;
                        oli.Quantity = ol.Quantity;
                        oli.UnitPrice = ol.UnitPrice;
                        oli.pricebookentryid=ol.pricebookentryid;
                        oppitemlist.add(oli);
                    }
                }
            }
            
            if(!oppitemlist.isEmpty()){
                insert oppitemlist;
            }
        }
    }
}


Thanks,
Maharajan.C
Rahul MahaleRahul Mahale 
I need to print in O/P of  Stored values in Keys & Associated values line by line of Map function.

o/p required :

the current key =98
the current value for above key = Robert

What enhancement should i do to achieve o/p?

Code :

//Declare Map Variable & Show key Values, Values & Check if it is empty or not.

Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();

//add some items
VarMapOfEmployeeMobileNum.put(98,'Robert');
VarMapOfEmployeeMobileNum.put(64,'Matthew');
VarMapOfEmployeeMobileNum.put(55,'Harry');

//to see the map
System.debug('The current map ='+VarMapOfEmployeeMobileNum);


//Collect all Keys and Show 1 By 1
set<Integer> VarTempSet = new set<Integer>();
VarTempSet = VarMapOfEmployeeMobileNum.keyset();
for (integer VarMobileSetPrint: VarTempSet)
{
    system.debug('The Current Key ='+VarMobileSetPrint);
}

//Collect all Values and Show 1 By 1
List<String> VarTempList = new List<String>();
VarTempList = VarMapOfEmployeeMobileNum.Values();
for (string VarMobileListPrint: VarTempList)
{
    system.debug('The Current Value for above Key ='+VarMobileListPrint);
}
 
Best Answer chosen by Rahul Mahale
veer soniveer soni
Hi Rahul,
try following code.
Map<integer, String> VarMapOfEmployeeMobileNum= New Map <integer, String>();

//add some items
VarMapOfEmployeeMobileNum.put(98,'Robert');
VarMapOfEmployeeMobileNum.put(64,'Matthew');
VarMapOfEmployeeMobileNum.put(55,'Harry');

//to see the map
System.debug('The current map ='+VarMapOfEmployeeMobileNum);
for (integer key: VarMapOfEmployeeMobileNum.keyset()){
    system.debug('The Current Key ='+key);
    
         system.debug('The Current value ='+ VarMapOfEmployeeMobileNum.get(key));
    }

get value based key.
I hope above info will help you and if it help, let me know to mark it as best answer.
Thank you
Eager-2-LearnEager-2-Learn 

Hi,

 

Is there a way to use REGEX to check a field to make sure it follows a specifi format with a delimiter?

 

The field will have alfa-numeric values but they must be 4 digits long with a comma seperation and no spaces.  There is no specific on how many groups of these alfa-numerics are allowed.  

 

These would be valid:

1xi4,GX19,Nn92

ZZZ1,8939,YXKE,791W

 

These would not be valid:

1x49d,GX1,Nn92

,1xi4,GX19,Nn92

1xi4,GX19,Nn92,

1xi4,GX19, Nn92


Best Answer chosen by Admin (Salesforce Developers) 
Eager-2-LearnEager-2-Learn

I had the comma in the wrong spot!

 

It should be inside the lef pareth:

 

 NOT(REGEX(Facets_Grp_s__c, "[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9](,[a-​zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]){0,10}")​)

 

If anyone has a shorter version I would life to have it.  I tried the \W but Salesforce didn't like it!

ScarScar 

Hi all,

 

I have to change a case owner in a before trigger. The trigger works fine when i use an Administrator profile and the case owner is chnaged to that of a queue, but when i try changing the owner when using a user who's not an admin, i get an error saying that i don't have enough priviledges to perform the action.

 

 

I've put debug logs throughout the code to figure out the error,

The owner id actually is assigned the Queue Id, i think it's during the save operaion that i've missed something or there's an error.

 

can someone please point me in the right direrction and help me figurre out the error?

Best Answer chosen by Admin (Salesforce Developers) 
ScarScar

After lots of time spent searching here and there, i've finally been able to figure the error. 

 

An email is triggered each time a Case or lead owner is changed.  It's because there was en error while firing the email, that i had the insufficient priviledges error and there was not a change in wonership. 

 

To counter the problem , i followed the following  example 

http://help.salesforce.com/apex/HTViewSolution?id=000176854&language=en_US

 

and it worked. :) 

 

Alternately, i could have used WorkFlow rules to change the owner but in my case it would have meant 9 or more  Workflows  depending upon requirements.

 

 

 

BrianHBrianH 

We have an existing class that uses the Test.isRunningTest() method.  Today we tried making changes to that class (completely unrelated to the isRunningTestMethod) and weren't able to save it because of a "method doesn't exist or incorrect signature" error on that method.  Did something change with the Winter 12 release where we can no longer use this in code?  If so, is there something replacing this functionality?  If we should still be able to use it, any thoughts on why we are receiving this error now?


Save error: Method does not exist or incorrect signature: Test.isRunningTest()


Best Answer chosen by Admin (Salesforce Developers) 
spraetzspraetz

Did you add a class to your org named Test?

 

If you add an Apex Class with the same name as a default class in Apex, all calls to that class will look at your class instead of the standard Apex classes.

RJ12RJ12 

I'm doing a REST API call to get the global value set and trying to deserialize the JSON result to get the picklist values in a List<String>.

Here is the JSON:

{
  "size": 1,
  "totalSize": 1,
  "done": true,
  "queryLocator": null,
  "entityTypeName": "GlobalValueSet",
  "records": [
    {
      "attributes": {
        "type": "GlobalValueSet",
        "url": "/services/data/v53.0/tooling/sobjects/GlobalValueSet/0Nt59000000AAAAAAA"
      },
      "Metadata": {
        "customValue": [
          {
            "color": null,
            "default": false,
            "description": null,
            "isActive": null,
            "label": "USA",
            "urls": null,
            "valueName": "USA"
          },
          {
            "color": null,
            "default": false,
            "description": null,
            "isActive": null,
            "label": "Canada",
            "urls": null,
            "valueName": "Canada"
          }
        ],
        "description": null,
        "masterLabel": "US States & Territories",
        "sorted": false,
        "urls": null
      },
      "Id": "0Nt59000000AAAAAAA"
    }
  ]
}
I need help in fixing the error and also how to get valueNames in a List<String>

Error: System.JSONException: Malformed JSON: Expected '{' at the beginning of an object.

Here is what I have tried so far:

Wrapper:
    public class GlobalValueSetWrapper{
        Metadata metadata;

    public class Metadata {
        public List<CustomValue> customValue;
    }
    
    public class CustomValue {
        public String label;  
        public String valueName;
    }
    }


Class:
//calling API to get the JSON result
HttpResponse res = GlobalValueSetAPIHandler.getResponse('Countries');
GlobalValueSetWrapper wrapper = (GlobalValueSetWrapper) JSON.deserialize(res.getBody(), GlobalValueSetWrapper.class);
Best Answer chosen by RJ12
RJ12RJ12

I'm able to fix it.

public class GlobalValueSetWrapper{
    public List<Records> records;

    public class Records {
        public Metadata metadata;
    }
    
    public class Metadata {
        public List<CustomValue> customValue;
    }

    public class CustomValue {
        public String label;
        public String valueName;    
    }

    public static List<String> getPicklistValues(HttpResponse response){
        List<String> picklistValues = new List<String>();
        
        GlobalValueSetWrapper wrapper = (GlobalValueSetWrapper) System.JSON.deserialize(response.getBody(), GlobalValueSetWrapper.class);
        
        for(GlobalValueSetWrapper.customValue value : wrapper.records[0].metadata.customValue){
            picklistValues.add(value.valueName);
        }
        system.debug('Piclist Values: ' + picklistValues);
        
        return picklistValues;
    }
}