• SANDEEP CHITTINENI
  • NEWBIE
  • 75 Points
  • Member since 2016
  • Salesforce Developer

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 21
    Replies
public class RandomContactFactory {
    public static List<contact> generaterandomcontacts(Integer numberofcontacts,string lastnames){
        List<contact> contacts = new List<contact>();
        for(integer i=0;i<numberofcontacts;i++){
            contact con = new contact(FirstName = 'Test'+i,Lastname = lastnames);
            contacts.add(con);
        }
        return contacts;
    }

}
Please help me guys. I appreciate your help.
@HttpGet
    global static Account getAccountById() {
        RestRequest request = RestContext.request;
        // grab the caseId from the end of the URL
        String accountId = request.requestURI.substring(
            request.requestURI.lastIndexOf('/')+1);
        Account result =  [SELECT Id,Name FROM Account WHERE Id = :accountId];
        return result;
    }      
    @HttpDelete
    global static void deleteAccount() {
        RestRequest request = RestContext.request;
        String accountId = request.requestURI.substring(
            request.requestURI.lastIndexOf('/')+1);
        Account thisAccount = [SELECT Id FROM Account WHERE Id = :accountId];
        delete thisAccount;
    }

Thanks in advance!
Sandeep Chittineni
Hello developers!
How data is importing?
Importing bulk data using loader: using insert operation

How should I build logic in the backend?
Before inserting the record I need to check whether it already exists or not. If yes then I need to update the new data into that existing record and need to skip the insert operation in this case. If it is a new record then this should generally insert the record.

Please help me in doing this.

Thanks
Sandeep.
public void Automate_Approval_Process_NEWSave(){    	
    	User user2 =[SELECT Alias,Id,Name FROM User where alias ='apos' limit 1];
    	Approval.ProcessSubmitRequest req2 = new Approval.ProcessSubmitRequest();
        req2.setComments('Submitting request for approval.');       
        if(newsaveid != null){
		req2.setObjectId(newsaveid);        
		}		
        req2.setSubmitterId(user2.Id); 

        req2.setProcessDefinitionNameOrId('CV_Approval');
        req2.setSkipEntryCriteria(true);

        Approval.ProcessResult result1 = Approval.process(req2); 
}

Thanks in Advance.......!
public void Find(){
    	
        //Filter for Carrier Type Only.
        if((cv.Carrier_Type__c == 'Allegian Choice' || cv.Carrier_Type__c == 'BCBS_MS' || cv.Carrier_Type__c == 'BCBS_MAPD' ||
                 cv.Carrier_Type__c == 'CareMore' || cv.Carrier_Type__c == 'CIGNA_IFP' || cv.Carrier_Type__c == 'Health Choice' || 
                 cv.Carrier_Type__c == 'Humana' || cv.Carrier_Type__c == 'Phoenix Choice' || cv.Carrier_Type__c == 'PHP_VBHP' || 
                 cv.Carrier_Type__c == 'UAHP') && (cv.AgentAgency_Type__c != 'Agent' && cv.AgentAgency_Type__c != 'Agency') &&
                 (cv.Activity__c != 'Active' && cv.Activity__c != 'Inactive')){
            system.debug('Success');
            CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =: cv.Carrier_Type__c and AgentAgency_Type__c =: 'Agent'];                            
                            system.debug('Success' +CarrierAgent);

            CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =: cv.Carrier_Type__c and AgentAgency_Type__c =: 'Agency'];
        }
        //Filter for Carrier Type and Agent/Agency Type Only.       
        else if((cv.Carrier_Type__c == 'Allegian Choice' || cv.Carrier_Type__c == 'BCBS_MS' || cv.Carrier_Type__c == 'BCBS_MAPD' ||
                 cv.Carrier_Type__c == 'CareMore' || cv.Carrier_Type__c == 'CIGNA_IFP' || cv.Carrier_Type__c == 'Health Choice' || 
                 cv.Carrier_Type__c == 'Humana' || cv.Carrier_Type__c == 'Phoenix Choice' || cv.Carrier_Type__c == 'PHP_VBHP' || 
                 cv.Carrier_Type__c == 'UAHP') && (cv.AgentAgency_Type__c == 'Agent' || cv.AgentAgency_Type__c == 'Agency') &&
                 (cv.Activity__c != 'Active' && cv.Activity__c != 'Inactive')){
			CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agent')];
			
			CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agency')];                            

        }
        else if((cv.Carrier_Type__c == 'Allegian Choice' || cv.Carrier_Type__c == 'BCBS_MS' || cv.Carrier_Type__c == 'BCBS_MAPD' ||
                 cv.Carrier_Type__c == 'CareMore' || cv.Carrier_Type__c == 'CIGNA_IFP' || cv.Carrier_Type__c == 'Health Choice' || 
                 cv.Carrier_Type__c == 'Humana' || cv.Carrier_Type__c == 'Phoenix Choice' || cv.Carrier_Type__c == 'PHP_VBHP' || 
                 cv.Carrier_Type__c == 'UAHP') && (cv.AgentAgency_Type__c == 'Agent' || cv.AgentAgency_Type__c == 'Agency') &&
                 (cv.Activity__c == 'Active' || cv.Activity__c == 'Inactive')){
        	CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agent') and (Activity__c =: cv.Activity__c)];

			CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agency') and (Activity__c =:cv.Activity__c)];                                                        
			

        }
        //Filter for Activity Only.
        else if((cv.Carrier_Type__c != 'Allegian Choice' || cv.Carrier_Type__c != 'BCBS_MS' || cv.Carrier_Type__c != 'BCBS_MAPD' ||
                 cv.Carrier_Type__c != 'CareMore' || cv.Carrier_Type__c != 'CIGNA_IFP' || cv.Carrier_Type__c != 'Health Choice' || 
                 cv.Carrier_Type__c != 'Humana' || cv.Carrier_Type__c != 'Phoenix Choice' || cv.Carrier_Type__c != 'PHP_VBHP' || 
                 cv.Carrier_Type__c != 'UAHP') && (cv.AgentAgency_Type__c != 'Agent' && cv.AgentAgency_Type__c != 'Agency') && 
                (cv.Activity__c == 'Active' || cv.Activity__c == 'Inactive')){          
            CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Activity__c =: cv.Activity__c and AgentAgency_Type__c =: 'Agent'];

            CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Activity__c =: cv.Activity__c and AgentAgency_Type__c =: 'Agency'];
        }

Thanks in Advance..........! 
public pageReference View(){        
        String str = ApexPages.currentPage().getParameters().get('agentid');
        String str1 = ApexPages.currentPage().getParameters().get('agencyid');
        Validations = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where id =:str or id =:str1];

        PageReference pg;                   
        system.debug('@@@@@@@@@@@'+Validations +'######' +str);
        if(str != null){
             pg = new pageReference('https://c.cs1.visual.force.com/apex/View_Validations?id='+str);        
        }
        if(str1 != null){          
             pg = new pageReference('https://c.cs1.visual.force.com/apex/View_Validations?id='+str1);       
        }
        pg.setredirect(true);
        return  pg;
    }

Thanks in Advance.....!
public class FieldUpdate {
    public List<Vehicle__c> v;
    public String st;
    
    public void FieldUpdate(){
        v=[select id,Date__c,Status__c from Vehicle__c where (Date__c=:date.today())];
        for(Vehicle__c vh : v)
        {
           if(vh.Date__c==date.today())
            {
                st=vh.Status__c;
                string lt=st.remove('-Future');
                vh.Status__c=lt;                
                update vh;               
            }
           
        }
    }
}



Thank you,
Sandeep
I have custom picklist field with primary and secondary values in contact , for each account there must be one contact with primary selected and rest all  contacts will be secondary ..!!
how can i achieve this..

Thnks in advance  :)
Thnks community ..!!
Hello. I am trying to use the invocableMethod annotation to pass some ids from a flow to the method that will return a list of custom Sobjects.

For some reason the soql is only finding the first record, and I don't see why. Posted here is the class and a debug log. Thanks for any help!!
 
public with sharing class getCampaigns_Flow {
    
    @invocableMethod
    public static list<list<Campaign__c>> getCampaigns(list<string> campaignIds) {
        system.debug('campaignIds: '+campaignIds);
        list<list<Campaign__c>> varCamps = new list<list<Campaign__c>>();
        List<string> varIds = campaignIds[0].split(';');
        system.debug('varIds: '+varIds);
        list<Campaign__c> camps = [select Id,
                                    Target_Audience__c,
                                    Geographic_Targeting__c,
                                    Search_Keywords__c,
                                    Creative_Versions_Per_Flight__c
                                    from Campaign__c
                                    where Id In :varIds];
        varCamps.add(camps);
        system.debug('camps: '+camps);
        system.debug('varCamps: '+varCamps);
        return varCamps;
    }
}
User-added image
 
Please help me guys. I appreciate your help.
@HttpGet
    global static Account getAccountById() {
        RestRequest request = RestContext.request;
        // grab the caseId from the end of the URL
        String accountId = request.requestURI.substring(
            request.requestURI.lastIndexOf('/')+1);
        Account result =  [SELECT Id,Name FROM Account WHERE Id = :accountId];
        return result;
    }      
    @HttpDelete
    global static void deleteAccount() {
        RestRequest request = RestContext.request;
        String accountId = request.requestURI.substring(
            request.requestURI.lastIndexOf('/')+1);
        Account thisAccount = [SELECT Id FROM Account WHERE Id = :accountId];
        delete thisAccount;
    }

Thanks in advance!
Sandeep Chittineni
Hello developers!
How data is importing?
Importing bulk data using loader: using insert operation

How should I build logic in the backend?
Before inserting the record I need to check whether it already exists or not. If yes then I need to update the new data into that existing record and need to skip the insert operation in this case. If it is a new record then this should generally insert the record.

Please help me in doing this.

Thanks
Sandeep.
Hi Every one,

How can i write program checking Duplicate fields in Lead object FirstName,Email,company,phone using trigger concept and also display message if it is Dublicate its not dublicate record will save.
public class RandomContactFactory {
    public static List<contact> generaterandomcontacts(Integer numberofcontacts,string lastnames){
        List<contact> contacts = new List<contact>();
        for(integer i=0;i<numberofcontacts;i++){
            contact con = new contact(FirstName = 'Test'+i,Lastname = lastnames);
            contacts.add(con);
        }
        return contacts;
    }

}
Hi Expert, I am getting "System.SObjectException: Field
@isTest
public class OppNamesTest {
    static testmethod void testclass(){
        
    //insert product
    Product2 prod = new Product2(Name = 'Laptop X200',Family = 'Hardware');
    insert prod;
    
  	 Id pricebookId = Test.getStandardPricebookId();
        
     //create a new Opportunity
	Opportunity opp1 = new  Opportunity();
    opp1.Name = 'Test trigger';
    opp1.CloseDate = Date.today();
    opp1.StageName = 'Sourcing Demand';
    insert opp1;
        
    //create a new Opportunity2
	Opportunity opp2 = new  Opportunity();
    opp2.Name = 'Test trigger1';
    opp2.CloseDate = Date.today();
    opp2.StageName = 'Sourcing Demand';
    insert opp2;
        
    //insert pricebook
    PricebookEntry pbe = new PricebookEntry();
    pbe.Pricebook2Id=pricebookId;
    pbe.Product2Id = prod.Id;
    pbe.isActive=True;
   	pbe.UnitPrice = 0.70;
  	pbe.UseStandardPrice=false;
	 insert pbe;
        

        
        //create OLI
       	OpportunityLineItem opli = new OpportunityLineItem();
    	opli.UnitPrice = 57;
    	opli.Quantity = 1;
    	opli.OpportunityId=opp1.Id;
       // opli.PricebookEntryId= pbe.Id;
    	opli.Product2Id = prod.Id;
       	insert opli;
        
        //create OLI
       	OpportunityLineItem opli1 = new OpportunityLineItem();
    	opli1.UnitPrice = 40;
    	opli1.Quantity = 1;
    	opli1.OpportunityId=opp2.Id;
        opli.PriceBookEntryId=pbe.Id;
    	opli1.Product2Id = prod.Id;
       	insert opli1;	
        
        map<ID,string> MapofNames = new map<ID,string>();
        Product2 prd = new Product2();
        
        MapofNames.put(opli.OpportunityID,opli.Product2Id);
        MapofNames.put(opli1.OpportunityID,opli1.Product2Id);
        
        string namesofOpp1 = [select name from opportunity where Id IN: MapofNames.keySet()].name;
        prd = [select Id,Opportunity_Names__c from Product2 where Id in: MapofNames.values()];
        string allnames=(string) prd.get('Opportunity_Names__c');
        
        prd.Opportunity_Names__c = allnames+';'+namesofOpp1;// concanated the names previous and current
        update prd;
        
        System.assertEquals('Test trigger;Test trigger1', prd.Opportunity_Names__c);
    }
}

is not writeable: "OpportunityLineItem.PricebookEntryId" this error in test class.

The setup:
1. Org contains a custom object called objectX__c
2. A packaged app also contains a custom object called objectX__c but Salesforce automatically added a namespace there i.e. `someapp__.objectX__c`
3. The org has a custom lookup field on the account that looks to objectX__c, i.e. `Account.lookup_objectX__c`
4. The package app tries to run a query as `select id, lookup_objectX__r.some_field__c from Account`
5. This error occurs 

No such column 'some_field__c' on entity 'someapp__objectX__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

This error should not be happening because the lookup field is setup correctly to look at the non-namespaced object, but Salesforce is looking at the namespaced object which then fail.

public void Find(){
    	
        //Filter for Carrier Type Only.
        if((cv.Carrier_Type__c == 'Allegian Choice' || cv.Carrier_Type__c == 'BCBS_MS' || cv.Carrier_Type__c == 'BCBS_MAPD' ||
                 cv.Carrier_Type__c == 'CareMore' || cv.Carrier_Type__c == 'CIGNA_IFP' || cv.Carrier_Type__c == 'Health Choice' || 
                 cv.Carrier_Type__c == 'Humana' || cv.Carrier_Type__c == 'Phoenix Choice' || cv.Carrier_Type__c == 'PHP_VBHP' || 
                 cv.Carrier_Type__c == 'UAHP') && (cv.AgentAgency_Type__c != 'Agent' && cv.AgentAgency_Type__c != 'Agency') &&
                 (cv.Activity__c != 'Active' && cv.Activity__c != 'Inactive')){
            system.debug('Success');
            CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =: cv.Carrier_Type__c and AgentAgency_Type__c =: 'Agent'];                            
                            system.debug('Success' +CarrierAgent);

            CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =: cv.Carrier_Type__c and AgentAgency_Type__c =: 'Agency'];
        }
        //Filter for Carrier Type and Agent/Agency Type Only.       
        else if((cv.Carrier_Type__c == 'Allegian Choice' || cv.Carrier_Type__c == 'BCBS_MS' || cv.Carrier_Type__c == 'BCBS_MAPD' ||
                 cv.Carrier_Type__c == 'CareMore' || cv.Carrier_Type__c == 'CIGNA_IFP' || cv.Carrier_Type__c == 'Health Choice' || 
                 cv.Carrier_Type__c == 'Humana' || cv.Carrier_Type__c == 'Phoenix Choice' || cv.Carrier_Type__c == 'PHP_VBHP' || 
                 cv.Carrier_Type__c == 'UAHP') && (cv.AgentAgency_Type__c == 'Agent' || cv.AgentAgency_Type__c == 'Agency') &&
                 (cv.Activity__c != 'Active' && cv.Activity__c != 'Inactive')){
			CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agent')];
			
			CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agency')];                            

        }
        else if((cv.Carrier_Type__c == 'Allegian Choice' || cv.Carrier_Type__c == 'BCBS_MS' || cv.Carrier_Type__c == 'BCBS_MAPD' ||
                 cv.Carrier_Type__c == 'CareMore' || cv.Carrier_Type__c == 'CIGNA_IFP' || cv.Carrier_Type__c == 'Health Choice' || 
                 cv.Carrier_Type__c == 'Humana' || cv.Carrier_Type__c == 'Phoenix Choice' || cv.Carrier_Type__c == 'PHP_VBHP' || 
                 cv.Carrier_Type__c == 'UAHP') && (cv.AgentAgency_Type__c == 'Agent' || cv.AgentAgency_Type__c == 'Agency') &&
                 (cv.Activity__c == 'Active' || cv.Activity__c == 'Inactive')){
        	CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agent') and (Activity__c =: cv.Activity__c)];

			CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Carrier_Type__c =:cv.Carrier_Type__c and (AgentAgency_Type__c =: cv.AgentAgency_Type__c 
                            and AgentAgency_Type__c =: 'Agency') and (Activity__c =:cv.Activity__c)];                                                        
			

        }
        //Filter for Activity Only.
        else if((cv.Carrier_Type__c != 'Allegian Choice' || cv.Carrier_Type__c != 'BCBS_MS' || cv.Carrier_Type__c != 'BCBS_MAPD' ||
                 cv.Carrier_Type__c != 'CareMore' || cv.Carrier_Type__c != 'CIGNA_IFP' || cv.Carrier_Type__c != 'Health Choice' || 
                 cv.Carrier_Type__c != 'Humana' || cv.Carrier_Type__c != 'Phoenix Choice' || cv.Carrier_Type__c != 'PHP_VBHP' || 
                 cv.Carrier_Type__c != 'UAHP') && (cv.AgentAgency_Type__c != 'Agent' && cv.AgentAgency_Type__c != 'Agency') && 
                (cv.Activity__c == 'Active' || cv.Activity__c == 'Inactive')){          
            CarrierAgent = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Activity__c =: cv.Activity__c and AgentAgency_Type__c =: 'Agent'];

            CarrierAgency = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where Activity__c =: cv.Activity__c and AgentAgency_Type__c =: 'Agency'];
        }

Thanks in Advance..........! 
public pageReference View(){        
        String str = ApexPages.currentPage().getParameters().get('agentid');
        String str1 = ApexPages.currentPage().getParameters().get('agencyid');
        Validations = [select id, Validation_Name__c, Approved_By__c, Activity__c from Carrier_Validation__c
                            where id =:str or id =:str1];

        PageReference pg;                   
        system.debug('@@@@@@@@@@@'+Validations +'######' +str);
        if(str != null){
             pg = new pageReference('https://c.cs1.visual.force.com/apex/View_Validations?id='+str);        
        }
        if(str1 != null){          
             pg = new pageReference('https://c.cs1.visual.force.com/apex/View_Validations?id='+str1);       
        }
        pg.setredirect(true);
        return  pg;
    }

Thanks in Advance.....!
public class FieldUpdate {
    public List<Vehicle__c> v;
    public String st;
    
    public void FieldUpdate(){
        v=[select id,Date__c,Status__c from Vehicle__c where (Date__c=:date.today())];
        for(Vehicle__c vh : v)
        {
           if(vh.Date__c==date.today())
            {
                st=vh.Status__c;
                string lt=st.remove('-Future');
                vh.Status__c=lt;                
                update vh;               
            }
           
        }
    }
}



Thank you,
Sandeep