• cl0s3r
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 17
    Questions
  • 42
    Replies

I have a conundrum. I want to run a query using the Like Comparison on multiple elements, but not having much luck.  When I attempt to us "Or" logic within a "Like" comparison no records are returned.  Can someone assist?

 

SELECT Academic_Plan_Returned__c, Campus_Name__c, CreatedById, CreatedDate, Quarter__c, Student__r.Name,  Student__r.Student_Id__c FROM At_Risk__c  where Student__r.Student_Id__c != '9999' and Academic_Plan_Returned__c = true and CreatedDate > 2013-04-05T00:00:00Z and CreatedDate < 2013-05-19T00:00:00Z and Campus_Name__c like '%new port,tampa%'

  • August 16, 2013
  • Like
  • 0

This is killing me, I am trying to bulkify this trigger so I dont get the dreaded SQL queries:101 msg.  I am not having any success thus far, any help would be greatly appreciated.

trigger AcscSecLvlPickup on Case (before update) {
	
	for(Case c: Trigger.new){
		System.debug('Alerting on --------> Starting the AcscSecLvlPickup Trigger');
		Task[] tsk = new Task[]{};
		
		for(Task t:[Select id from Task where whatid = :c.id and Status not in ('Canceled', 'Deferred', 'Completed')]){
			tsk.add(t);
		}
		System.debug('Alerting on --------> task '+tsk);
		//List<Task> tas = [Select id from Task where whatid = :c.id and Status not in ('Canceled', 'Deferred', 'Completed')];
		//List<Case> cas = new Case[]{};
		if(trigger.isUpdate){
			if(c.Create_Task__c == true && c.Status == 'Closed' && c.RecordTypeId == '012300000000PhJAAU'){
				if(tsk.size() > 0){
					for(integer i = 0; i<tsk.size();i++){
						tsk[i].Status = 'Completed';
						
					}
				}
				update tsk;
				c.Create_Task__c = false;
		 }
		}else{
		//System.debug('Alerting on --------> Starting the AcscSecLvlPickup Trigger');
		Case oldCase = Trigger.oldMap.get(c.ID);
		System.debug('Alerting on AcscSecLvlPickup Trigger --------------> '+'Stepping into the Entering If');
		if(c.SecLvlVal__c != true && c.OwnerId != oldCase.OwnerId && oldCase.ACSC_Second_Level_Picked_Up_Date__c == null && oldCase.Type == 'ACSC2ndLevel'){
		  c.ACSC_Second_Level_Picked_Up__c = true;
		  c.SecLvlVal__c = true;
			//c.SecLvlVal__c = true; 
			System.debug('Alerting on AcscSecLvlPickup Trigger  --------------> '+c.ACSC_Second_Level_Picked_Up__c);
		}
		}

	}
}

 

  • March 20, 2013
  • Like
  • 0

I need a fresh set of eyes on this trigger. Can some one take am moment  and perhaps point me in the right direction?

 

Trigger:

trigger Opportunity on Opportunity (before insert, before update) {
	System.debug('Alerting on Opportunity Trigger --------------------> Starting ');
	for(Opportunity o:trigger.new){

		Boolean boolStage;
		Boolean booRec;
		Boolean boolClose;

			if(trigger.isUpdate){
				Opportunity oldOpp = Trigger.oldMap.get(o.id);
				if(oldOpp.StageName != o.StageName){
					boolStage = true;
				}
				if(oldOpp.CloseDate != o.CloseDate){
					boolClose = true;
				}
			}
			
//			for(integer i=0;i<rec.size();i++){
				if(boolStage == true ){
			//StageName = 1-Qualification Complete/Research, 0-Prospecting	
				if(o.StageName == '0-Prospecting' || o.StageName == '1-Qualification Complete/Research'){
					o.Forecast_Identifier__c = 'Lead';
			//StageName = 2-Assessment, 3-Justification, 4-Internal Estimate
				}else if(o.StageName == '2-Assessment' || o.stageName == '3-Justification' || o.StageName == '4-Internal Estimate'){
					o.Forecast_Identifier__c = 'Open';
			//StageName = 5-Final Proposal
				}else if(o.StageName == '5-Final Proposal'){
					o.Forecast_Identifier__c = 'Upside';
			//StageName = 6-Vendor Selection, 7-Contract
				}else if(o.StageName == '6-Vendor Selection' || o.StageName == '7-Contract'){
					o.Forecast_Identifier__c = 'Committed';
			//StageName = 8-Closed
				}else if(o.StageName == '8-Closed'){
					o.Forecast_Identifier__c = 'Won';
		 		 }
				}else if(!trigger.isUpdate){
			//StageName = 1-Qualification Complete/Research, 0-Prospecting	
				if(o.StageName == '0-Prospecting' || o.StageName == '1-Qualification Complete/Research'){
					o.Forecast_Identifier__c = 'Lead';
			//StageName = 2-Assessment, 3-Justification, 4-Internal Estimate
				}else if(o.StageName == '2-Assessment' || o.stageName == '3-Justification' || o.StageName == '4-Internal Estimate'){
					o.Forecast_Identifier__c = 'Open';
			//StageName = 5-Final Proposal
				}else if(o.StageName == '5-Final Proposal'){
					o.Forecast_Identifier__c = 'Upside';
			//StageName = 6-Vendor Selection, 7-Contract
				}else if(o.StageName == '6-Vendor Selection' || o.StageName == '7-Contract'){
					o.Forecast_Identifier__c = 'Committed';
			//StageName = 8-Closed
				}else if(o.StageName == '8-Closed'){
					o.Forecast_Identifier__c = 'Won';
		 		 }
				}
				
				if(boolClose == true){
					o.Target_Complete_Date__c = o.closeDate+90;
					o.General_Availability_Date__c = o.closeDate+90;
				}
//			}
		

		} 

	}

 TestCase:

@isTest(seeAlldata=true)
private class TestOpportunityTrigger {

    static testMethod void myUnitTest() {
    	System.debug('Alerting on TestOpportunityTrigger --------------------> Starting');
    List<RecordType> rec = [Select id, name from RecordType where sobjecttype = 'Opportunity' and name = 'Business Development'];    

	Account acc = new Account();
	acc.Name = 'Test';
	acc.ShippingStreet = '123 Est Street';
	acc.ShippingCity = 'Home';
	acc.ShippingState = 'AL';
	acc.ShippingPostalCode = '36105';
	insert acc;
	System.debug('Alerting on --------------------> acc Details'+acc);
	
	List<String> stName = new List<String>{'0-Prospecting','1-Qualification Complete/Research','2-Assessment','3-Justifiction','4-Internal Estimate','5-Final Proposal','6-Vendor Selection','8-Closed'};
	for(integer p=0;p<200;p++){
		for(Integer i=0;i<stName.size();i++){
		Opportunity opp = new Opportunity();
		opp.RecordTypeId = rec[0].id;
		opp.StageName = stName[i];
		opp.AccountId = acc.id; 
		opp.Name = 'TestOpp';
		opp.Type = 'Availity Connect';
		opp.CloseDate = date.today();
		opp.Opportunity_States__c = 'AL';
		opp.Description = 'Testing';
		System.debug('Alerting on --------------------> opp Details'+opp);
		try{
			insert opp;
		}catch (Dmlexception e){
			System.debug('Insert Failed '+e);
		}

			opp.StageName = '0-Prospecting';
			opp.CloseDate = opp.CloseDate+4;
			try{
			update opp;	
			}catch (DmlException e) {
				System.debug('Update Failed '+e);
			}

		}
	}
	
	
    }
}

 

 

  • March 01, 2013
  • Like
  • 0

What is the best way to override the clone button of the Opp.  I have a custom checkbox field on the Opp Line Item that I need set to false when cloned?

I want to compare two date fields to a third and if they are >= update another field. The formula I am attempting to use is below, IK have no syntax issues but for some reason it doesnt update the field. I am out of ideas, has anyone else had this type of issue?

 

IF(AND(AvStatusChange__c != NULL,OR( BAA_Modification_Date__c  >=  AvStatusChange__c , OAA_Modification_Date__c >=  AvStatusChange__c) ), true, false)

  • January 04, 2012
  • Like
  • 0

Does anyone know where I can find the details of Account search page? I would like to create a custom controller and vf page to add more details and need a starting point.

 

  • November 16, 2011
  • Like
  • 0

I have a spreadsheet with 15k rows that I would like to bounce the data against Salesforce to get the Salesforce ID, what is the best way to accomplish this?  I know I can break it down into 1k rows and feed it into force.com explorer but I am looking for an easier to manage process. How is everyone else accomplishing this?

  • August 15, 2011
  • Like
  • 0

How can I cover the following code via test data?

 

 

ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM, 'The case status is not in a valid state');
ApexPages.addMessage(myMsg);
return ApexPages.currentPage();

 

I am writing code to create an asset when a case is closed as well as a Date field is equal to Today().  At the moment I am getting , "Non-void method might not return a value or might have statement after a return statement". I have gone over the code and I thought I have the returns taken case of.  Anyone would like to look it over I would appreciate it.

public class CaseAsset {
	private final Case c;
	
	
	public CaseAsset(ApexPages.StandardController stdController) {
		this.c = (Case)stdController.getRecord();
	}
	//For testability
	//public CaseAsset(Asset a) {
	//	this.a = a;
	//}
	
//capture the case id from the button
		public PageReference caseDetails(){
			String theID = ApexPages.currentPage().getParameters().get('id');
			if (theID == null){
				return null;
			}
			return caseDetails(theID);
		}
		
		public PageReference caseDetails(String theID){
		 //private void PageReference caseDetails(String theID){
		 
			

//Build Oportunity Line Item List object with results from the matching records of the query
 			list<Case> cas = [Select id, Status, X30_Day_Warranty_Start_Date__c,AccountId, Related_Products__c, ContactId  from Case where id =:theId];
 			list<Product2> prod = [Select Name from Product2 where Id = :cas[0].Related_Products__c];
 			System.debug('<---Alerting Product2-----> '+prod);
 			

//Build 
			//list<Asset> ToInsert = new list<Asset>();
 				for(Integer I = 0; I < cas.size(); I++){
 					list<Asset> ToInsert = new list<Asset>();
 						if(cas[I].Status.equals('Production-Ready')){
 							if(cas[I].X30_Day_Warranty_Start_Date__c == date.today()){
 	
 								//create the case object 
 								Asset asset = new Asset();
 								asset.AccountId = cas[i].AccountId;
 								asset.Product2Id = cas[i].Related_Products__c;
 								asset.Status = 'Active';
 								//asset.Name = cas[i].Related_Products__c;
 								asset.Name = prod[0].Name;
 								//asset.Effective_Date__c = System.today();
 								System.debug('<---Alerting on the asset creation----->'+ asset);

	

								//Insert the cas object into the ToInsert list.    
    							ToInsert.add(asset);
      							insert ToInsert;
      
    							PageReference pageRef = new PageReference('/' + theId);
								pageRef.setRedirect(true);
								return pageRef;
      
 							}else{
 								return null;
 							}
 			 			}

// Inserts all the objects within the ToInsert list 
  //insert ToInsert;
  //update cas;
  
  	//PageReference pageRef = new PageReference('/' + theId);
	//pageRef.setRedirect(true);
	//return pageRef;
				}
		}
}

 

The trigger and testclass work fine in the sandbox with 100% code coverage.  Has anyone else ran up against this type of issue?

trigger AccountOrgUpdate on Account (before insert) {
		//Organization Type
		//TrackerOrgType
		Account ac = trigger.new[0];
		//if (ac.TrackerOrgType__c != null){
			String acc = ac.Organization_Type__c;
			String[] s = ac.Organization_Type__c.split(';');
			System.debug('Alerting on ----> Organization Type '+acc);
			System.debug('Alerting on ----> String Array '+ s);
			for(Integer i=0;i<s.size();i++){
				if(!s[i].contains(ac.TrackerOrgType__c)){
					ac.Organization_Type__c = acc +';'+ac.TrackerOrgType__c;
					Boolean boo = true;
					System.debug('<----Alerting on Boo----> '+boo);
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class TestAccountOrgUpdate {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        
//        Profile p = [Select id from Profile where name = 'Standard user'];
//        User u = new User(alias = 'Test123', email='test123@noemail.com', profileid = p.Id, country='United States',username='test123@noemail.com');
//        insert u;
        
        Account a = new Account(
        Name = 'Test Account',
//        OwnerId = u.Id,
        Organization_Type__c=('Ambulatory Surgical Center;Ancillary System Vendor'),
        TrackerOrgType__c ='Killer' );
        insert a;
    }
}

 

System.debug('<----Alerting on Organization Type----> '+ ac.Organization_Type__c);
//				if(s[i] != ac.TrackerOrgType__c){
//			System.debug('Alerting on ----> Tracker Organization Type '+ac.TrackerOrgType__c);
//			ac.Organization_Type__c = acc +';'+ac.TrackerOrgType__c;
//				}
				}
			 //ac.Organization_Type__c = ac.TrackerOrgType__c;
			
 }
}

 

I have a class that I have 69% tes coverage.  The lines that are refernced as not tested are some of the if statements or Apexpage references.  How has anyone else resolved this testing?

public class ProdCase {
        //private final Opportunity o;
        private Opportunity o;
        
        
        public ProdCase(ApexPages.StandardController stdController) {
                this.o = (Opportunity)stdController.getRecord();
                this.o = [Select Implementation_Contac__c from Opportunity where id =: this.o.id];
        }
        //For testability
        public ProdCase(Opportunity o) {
                this.o = o;
        }
        
//capture the opportunity id from the button
                public PageReference prodDetails(){
                        String theID = ApexPages.currentPage().getParameters().get('id');
                        if (theID == null){
                                return null;
                        }
                        return prodDetails(theID);
                }
                
                 public PageReference prodDetails(String theID){
                 
                        

//Build Oportunity Line Item List object with results from the matching records of the query
                        List<OpportunityLineItem> lin = [Select 
                        o.UnitPrice,
                        o.TotalPrice,
                        o.ListPrice,
                        o.Id,
                        o.Opportunity.Pricebook2Id,
                        o.PricebookEntryId,
                        o.ServiceDate,
                        o.Quantity,
                        o.Description,
                    	o.Transmission_Mode__c,
                        o.Opportunity.Name,
                        o.Opportunity.StageName,
                        o.Opportunity.Type,
                        o.Opportunity.Estimated_Implementation_Date__c,
                        o.Opportunity.Opportunity_States__c,
                        o.Opportunity.Implementation_Contac__c, 
                        o.Opportunity.Implementation_Program__c
                        From OpportunityLineItem o where o.OpportunityId =:theID and o.Implementation_Validation__c != true];   
                          //List<OpportunityLineItem> lin = [Select(Select UnitPrice, TotalPrice, 
                          //Quantity, ListPrice, Id From OpportunityLineItem WHERE Implementation_Validation__c != true)o.Name from Opportunity o where o.id =:theID] ;
                          
                          if (o.Implementation_Contac__c == null){
                                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.CONFIRM, 'The Implementation Contact has not been assigned, please correct and resubmit!');
                                ApexPages.addMessage(myMsg);
                                return ApexPages.currentPage(); 
                         }


//Build 
                        list<Case> ToInsert = new list<Case>();
                                for(Integer I = 0; I < lin.size(); I++){
        
                                        //create the case object 
                                        Case cas = new Case();

/*
Determine if the Opportuntiy is a Submitter, Vendor, or Receiver Opportuntiy and create the
correct case record type.
*/ 
        String oliID = lin[I].PricebookEntryId;
        List<PriceBookEntry> prd = [Select p.Product2Id from PricebookEntry p where Id =:oliID ];
        
        for(Integer ic = 0; ic < prd.size(); ic++){
                cas.Related_Products__c=prd[ic].Product2Id;
        
    }
        
        if(lin[I].Opportunity.Type == ('Submitter')){           
                 cas.RecordTypeId='012600000004vNEAAY';
                //Owner equals Ann Shelton
                cas.OwnerId='00560000000lh2zAAA';       
        }else if(lin[I].Opportunity.Type ==('Vendor')){ 
                cas.RecordTypeId='012600000004vacAAA';
                //Owner equals Ann Shelton
                cas.OwnerId='00560000000lh2zAAA';       
        }else { 
                cas.RecordTypeId='012600000004vN9AAI';
                //Owner equals Cyn Criss
                cas.OwnerId='00560000000lfXlAAI';               
        }
 
    	cas.Implementation_Name__c=lin[I].Opportunity.Name;
   		cas.Status='Business Development';
   		cas.Projected_Transactions__c=lin[I].Quantity;
   		cas.States__c=lin[I].Opportunity.Opportunity_States__c;
    	cas.ContactId=lin[I].Opportunity.Implementation_Contac__c;
        cas.Description=lin[I].Description;
        cas.Subject=lin[I].Opportunity.Name;
        cas.Implementation_Program__c=lin[I].Opportunity.Implementation_Program__c;
        
        //Sandbox
        //cas.Opportunity_Link__c='tapp0.salesforce.com/'+lin[I].OpportunityId;
        
        //Prd
        cas.Opportunity_Link__c='na4.salesforce.com/'+lin[I].OpportunityId;
        cas.Estimated_Implementation_Date__c=lin[I].Opportunity.Estimated_Implementation_Date__c;
        cas.Estimated_Live_Date__c=lin[I].ServiceDate;
//      cas.Related_Products__c=prd[ic].Product2Id;
        

//Sets the validation field true so that you can not submit a line item case more than once.                                    
    lin[I].Implementation_Validation__c = true;
    
//Insert the cas object into the ToInsert list.    
    ToInsert.add(cas);
    
  }
// Inserts all the objects within the ToInsert list 
  insert ToInsert;
  update lin;
  
        PageReference pageRef = new PageReference('/' + theId);
        pageRef.setRedirect(true);
        return pageRef;
        }
}

 

/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class TestProdCase {

    static testMethod void myUnitTest() {
  	test.startTest();
	
	/**
	creating a list to iterate through both states of an Opportunity Case (Submitter, Vendor)
	**/
	List<Integer> run = new List<Integer>();
	run.add(1);
	run.add(2);
	run.add(3);
//	for(Integer it=0;it <run.size(); it++){
	
	System.debug('Alerting on ----> run List '+run);
// 	List<RecordType> rec = [Select id from RecordType where name in ('Implementation Vendor','Implementation Submitter')];
// 	for(Integer it = 0;it<rec.size();it++){

    	

    /**
    Create Account Record
    **/	
 
    	Account a = new Account(Name='TestAccount');
    	insert a;
   	
   	/**
    Create Contact Record
    **/		
	  String acId = null;
      List<Account> ac = [Select id from Account where name = 'TestAccount'];
	  Contact c = new Contact(FirstName='Johnny', LastName='Tester', AccountId=ac[0].Id);
	  acId = ac[0].id;
	  insert c;
	  System.debug('Alerting on ----> Contact List'+c);

	
    
    /**
    Create Opportunity Record
    **/	
    System.debug('Alerting on ----> '+'Going into the Opportuntiy creation');
    Opportunity o = new Opportunity();
//    for(Integer it=0;it <run.size(); it++){
    //Opportunity o = new Opportunity();
    list<Contact> co = [Select Id from Contact where firstName='Johnny' and lastName = 'Tester'];
   
   		//Integer ct = co.size();
   		//System.debug('Alerting on ----> '+ct);
		o.Name='TestOpportunity';
		o.CloseDate=Date.today();
		o.StageName='Prospecting';
		o.Opportunity_States__c='AL';
		o.Status__c='Business Development';
		o.AccountId=a.Id;
		o.Name='TestOpportunity';
		o.CloseDate=Date.today();
		system.debug('Alerting on ----> Contact List'+co);
		o.Implementation_Contac__c=co[0].Id;
		o.Type='Submitter';
		//Sets the Opportunity type to vendor or submitter
//		if(it == 1){
//			o.Type='Submitter';
//		}else if (it == 2){
//			o.Type='Vendor';
//		}else{
//		o.Type='Receiver';
//		}

		

//		insert o;	
//		System.debug('Alerting on ----> Opportuntiy List '+ o);	
//    }
    	insert o;	
		System.debug('Alerting on ----> Opportuntiy List '+ o);	
	/*
	Set the Product
	*/
	List<PricebookEntry> numb = [Select Id, Pricebook2Id from PricebookEntry where isActive = TRUE LIMIT 5];
	//OpportunityLineItem opl = new OpportunityLineItem(OpportunityId=o.Id);
	for(Integer i = 0;i<numb.size(); i++){
		OpportunityLineItem opl = new OpportunityLineItem(OpportunityId=o.Id);
//		opl.PricebookEntryId=numb[i].Id;
		opl.PricebookEntryId=numb[i].Id;
		opl.Quantity=25;
		opl.ServiceDate=Date.today();
		opl.UnitPrice=125.50;
		insert opl;
		System.debug('Alerting on ----> Opportunity Line Item '+ opl);
	}
	String opp = o.Id;
	
	/*
	Pass in the Opportunity Object
	*/
	ProdCase testing = new ProdCase(o);

	/*
	Pass  in the Opportunity ID
	*/
	testing.prodDetails(opp);
//	System.debug('Alerting on ----> Iteration '+it);
	test.stopTest();
		}
//		test.stopTest();
//    }
}

 

While updating a test method I received the error mentioned in this subject. I am not sure where the offendor lies so can anyone assist, I have attached the code to give a better picture.

/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class TestProdCase {

    static testMethod void myUnitTest() {
  	test.startTest();
	
	/**
	creating a list to iterate through both states of an Opportunity Case (Submitter, Vendor)
	**/
	List<Integer> run = new List<Integer>();
	run.add(1);
	run.add(2);
	run.add(3);
	for(Integer it=0;it <run.size(); it++){
	
	System.debug('Alerting on ----> '+run);
// 	List<RecordType> rec = [Select id from RecordType where name in ('Implementation Vendor','Implementation Submitter')];
// 	for(Integer it = 0;it<rec.size();it++){

    	

    /**
    Create Account Record
    **/	
 
    	Account a = new Account(Name='TestAccount');
    	insert a;
   	
   	/**
    Create Contact Record
    **/		
	  String acId = null;
      List<Account> ac = [Select id from Account where name = 'TestAccount'];
	  Contact c = new Contact(FirstName='Johnny', LastName='Tester', AccountId=ac[0].Id);
	  acId = ac[0].id;
	  insert c;
	  System.debug('Alerting on ----> '+c);

	
    
    /**
    Create Opportunity Record
    **/	
    System.debug('Alerting on ----> '+'Going into the Opportuntiy creation');
    Opportunity o = new Opportunity();
    list<Contact> co = [Select Id from Contact where firstName='Johnny' and lastName = 'Tester'];
   
   		Integer ct = co.size();
   		System.debug('Alerting on ----> '+ct);
		o.Name='TestOpportunity';
		o.CloseDate=Date.today();
		o.StageName='Prospecting';
		o.Opportunity_States__c='AL';
		o.Status__c='Business Development';
		o.AccountId=a.Id;
		o.Name='TestOpportunity';
		o.CloseDate=Date.today();
		system.debug('Alerting on ----> '+co);
		o.Implementation_Contac__c=co[0].Id;
		
		//Sets the Opportunity type to vendor or submitter
		if(it == 1){
			o.Type='Submitter';
		}else if (it == 2){
			o.Type='Vendor';
		}else{
		o.Type='Receiver';
		}

		

		insert o;	
		System.debug('Opportunity Object '+ o);	
	/*
	Set the Product
	*/
	List<PricebookEntry> numb = [Select Id, Pricebook2Id from PricebookEntry where isActive = TRUE LIMIT 5];
	//OpportunityLineItem opl = new OpportunityLineItem(OpportunityId=o.Id);
	for(Integer i = 0;i<numb.size(); i++){
		OpportunityLineItem opl = new OpportunityLineItem(OpportunityId=o.Id);
//		opl.PricebookEntryId=numb[i].Id;
		opl.PricebookEntryId=numb[i].Id;
		opl.Quantity=25;
		opl.ServiceDate=Date.today();
		opl.UnitPrice=125.50;
		insert opl;
	}
	String opp = o.Id;
	
	/*
	Pass in the Opportunity Object
	*/
	ProdCase testing = new ProdCase(o);

	/*
	Pass  in the Opportunity ID
	*/
	testing.prodDetails(opp);
	//test.stopTest();
		}
		test.stopTest();
    }
}

 

I have a custom VF Button on my Opportunties. How can I validate if the custom button has been clicked within a Trigger? If the button is clicked I would like to verify if a custom field is null or not.

I am missing a processing step regarding Apex Triggers.  I am attempting to create a trigger for the Account object. The logic is validating that the text field TrackerOrgType__c is not null then append the string to the multi select field Organization_Type__c field. Currently the error ,"Apex trigger AccountOrgUpdate caused an unexpected exception, contact your administrator: AccountOrgUpdate: execution of AfterUpdate caused by: System.ListException: List index out of bounds: 1: Trigger.AccountOrgUpdate: line 4, column 28".  I am not sure why the list is out of bounds when I am only working with 1 record. Would anyone like to shed some light on this?

 

trigger AccountOrgUpdate on Account (after insert, after update) {
		//Organization Type
		//TrackerOrgType
		Account ac = trigger.new[1];
		if (ac.TrackerOrgType__c != null){
			ac.Organization_Type__c = ';'+ac.TrackerOrgType__c;
			
		}
}

 

 

 

I need some help understanding how to capture related data.  I have a list that contains all the line items of an opportunity. I would like to create a case for every line item.  I dont understand how to assign the elements of the list to the case fields.  I would like the cas.Implementation_Name__c field to equal the Opportunity.Name field but since the Opportunity is a lookup via the Opportunity.Id field I dont understand. I have attached the code to better describe what I am attempting to accomplish.

 

Thanks for the help!

 

Carlos

 

 

public with sharing class ProdCase {
//capture the opportunity id from the button
	public static void prodDetails(String oppId){

//Create the list of lineitems owned by the Opportuntity 
		List<OpportunityLineItem> lin = [Select o.UnitPrice, o.TotalPrice, 
				o.Quantity, o.OpportunityId, o.ListPrice, o.Id 
				From OpportunityLineItem o where o.OpportunityId =:oppId];	

//Iterate through the list parsing out the field to the Case object fields until completed.				
			for(Integer I = 0; I < lin.size(); I++){
 			
//For every Line Item create case and populate the fields specified
				Case cas = new Case();
					cas.RecordTypeId='';
					cas.OwnerId='';
					cas.Implementation_Name__c=lin[I].OpportunityId;
					
//Insert Case record into Salesforce					
					Insert cas;
 		}
	}
}

 

 

 

  • January 26, 2011
  • Like
  • 0

I need some assistance making a connection.  I would like to create a custom vf page to create the line items of an Opportunity. I follow the standard process and I see the lineitem.jsp page which I want to replace with a custom page, but don't understand the relationship to perform operation.

  • January 21, 2011
  • Like
  • 0
Just like philosophy, you have to know how to ask the question to get your answer. I would like to create a custom field within a custom object that will look-up all users, active and in-active.  Where should I begin this quest?

class
--------
public class duplicateerrormsg {
    public static void mains(list<account> acc){
        list<string> a = new list<string>();
        set<string> s = new set<string>();
        for(account at: acc){
            a.add(at.name);
        }
        list<account> acs = [select name from account where name in:a];
        for(account a2:acs){
            s.add(a2.name);
        }
        for(account a3:acc){
            a3.name.adderror('this record has implument ');
        }
    }
}
 
Hi,

I was recently asked to create three large formula fields in a custom object we call Loan App.

They would calculate a high value, medium value and low value based on several different variables and would only one of the fields would be populated at any given time.  All the formulas work fine but i have now been asked if i can get the value returned to show in a separate field for reporting. The combined character value is about 9k so there is no way i am able to use a formula field to return a value. 

I have read that triggers can be used to update fields but have only found examples where they are reading one value from another field and not multiples.

If i was going to write it in a formula i would do this:
IF(AND(Payment_Terms__c >=1,Loancalclow__C<> null) , loancalclow__C,
IF(AND(Payment_Terms__c >=1,Loancalclmed__C<> null) , loancalcmed__C,
IF(AND(Payment_Terms__c >=1,Loancalclhigh__C<> null) , loancalchigh__C,
0),0),0)

Can anyone help?

Thanks in advance
Hi Friends,

Display the default value based on Parent record 

how i will do please help me on this 

Thanks
kullayappa
We have a requirement to get the overall test class coverage and individual classes there in salesforce production org. automatically based on time interval. The challenge is how to execute it programmatically and get the latest coverage? 
 Thanks in Advance 
-Lokesh
I have situation where I have user who has mutliple roles in organization but when I try to add two roles for one user its replacing the other one  I have checked with Salesforce Support Team they have mentioned its a limitation.I want to check can we build a custom code to assign multiple roles to one user
  • January 16, 2017
  • Like
  • 0

Hi all,

 

I found this great solution by MichaelForce which overhauls the opportunity product selection screen with VF pages. It's pretty awesome, but was curious if there was a way to do the same thing with the quote line item selection screen on the quote object:

 

http://www.michaelforce.org/recipeView?id=a0G30000006eVxVEAU

 

Does anyone know if this question has been asked and if not, how hard would it be to modify the above to make it happen? Thanks for any advice!!

Hi All,

 

I have created buttons on a case record type to create child cases when pressed with an app called object converter.  I am looking for  way to show that the button has been pressed and only allow each button to be pressed once.  Please let me know if you have a solution for this issue.

 

Thanks,

Hi guys

 

In the APEX Developer's Guide on the topic of "Defining Triggers" you have this:

 

Click Version Settings to specify the version of Apex and the API used with this trigger.

 

However when you look at a trigger and click "Version Settings", you only really see the dropdown (for the Version number) for "Salesforce.com API", no "Apex version".

 

What exactly are the differences between Apex version and API version?  I assume API version means Salesforce API version.  Even then, what are the differences?  For example, for Spring 2013, I would assume they must both be version 27.0, is it not?  I wonder if it has to do with some historical configuration of Salesforce.

 

Thanks

King

Hi,

 

I've requirement that automatically send an email alert to salesrep which contains all the leads assigned to him. How can we achieve this. can anyone help me out from this.

1) When am clicking on "Convert" button in the Lead page. It is opening one standard page with some fields like Opportunity,Account look up and some other details. In that page again it is displaying "Convert" button. when we click on that button it will create one record in "Account" and "Opportunity" object.

 

2) While inserting record into Opportunity Object i want to validate some custom fields values entered or not. If they are not entered want to display error message and allow them to fill those custom fields values.

 

In Opportunity object i have some custom fields like Amount,Marketing type, Marketing information and one more fields while inserting record into opportunity at the time of converting lead to Opportunity want to check these values. And want to allow the values for their fields.

 

3) How can i achiece this functionality? can any provide ideas on this. Thanks in advance.

  • March 20, 2013
  • Like
  • 0

Hi!

 

I have a trigger that converts products in an opportunity to assets in the account when the opportunity moves to the stage Closed Won. This part works good.

However, when a product is converted to an asset for that account it gets marked as Converted (Checkbox). If another opportunity (under the same account) with for example additional users for that same product is closed it does not add anything to the assets for the account today.

 

What I want it to do is: IF Product X is already converted to Asset X on the account - then update the quantity of existing Asset X from the last opportunity Closed Won + quantity from Product X for the newly Closed Won opportunity.

 

Old Asset X (Quantity10) + New Product X (Quantity 5) = Old Asset X (Quantity 15).

 

Help please! :)

 

My Trigger:

trigger CreateAssetonClosedWon on Opportunity (after insert, after update) {
     for(Opportunity o: trigger.new){ 
      if(o.isWon == true && o.HasOpportunityLineItem == true && o.RecordTypeId == '012200000004fxZ'){
         String opptyId = o.Id;
         OpportunityLineItem[] OLI = [Select Total_Price__c, Cost__c, Quantity, Revenue_Type__c, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c  
                                      From OpportunityLineItem 
                                      where OpportunityId = :opptyId and Converted_to_Asset__c = false];
         Asset[] ast = new Asset[]{};
         Asset a = new Asset();
         for(OpportunityLineItem ol: OLI){
            a = new Asset();
            a.AccountId = o.AccountId;
            a.Product2Id = ol.PricebookEntry.Product2Id;
            a.Quantity = ol.Quantity;
            a.Price =  ol.Total_Price__c;
            a.PurchaseDate = o.CloseDate;
            a.Status = 'A6 - Closed Won';
            a.Description = ol.Description;
            a.Name = ol.PricebookEntry.Product2.Name;
            ast.add(a);
            ol.Converted_to_Asset__c = true;
       }
      update OLI; 
      insert ast;
     }
    }
}

 

I can't figure out what I'm doing wrong.

 

I have an instance op of an Opportunity object and the following code:

 

System.debug('@@@@@@@@@@@@ The year is: ' + nYear);
System.debug('@@@@@@@@@@@@ The month is: ' + nMonth);
System.debug('@@@@@@@@@@@@ The day is: ' + nDay);
Date dt = Date.newInstance(nYear, nMonth, nDay);
System.debug('@@@@@@@@@@@@ The complete date is: ' + dt); 
op.CloseDate = dt;

 This appears to work fine and produces the expected spew in the Developer Console:

 

[392]|DEBUG|@@@@@@@@@@@@ The year is: 12
[394]|DEBUG|@@@@@@@@@@@@ The month is: 11
[396]|DEBUG|@@@@@@@@@@@@ The day is: 28
[398]|DEBUG|@@@@@@@@@@@@ The complete date is: 0012-11-28 00:00:00
etc. (same for multiple Opportunity records)

 

But when controller attempts to upsert these Opportunity records a DML error occurs with an error message complaining that value in CloseDate is not a valid date.

 

Close Date: Close Date: invalid date: Mon Nov 28 00:00:00 GMT 12
Close Date: Close Date: invalid date: Sat Nov 05 00:00:00 GMT 12
Close Date: Close Date: invalid date: Tue Nov 01 00:00:00 GMT 12
Close Date: Close Date: invalid date: Sun Nov 06 00:00:00 GMT 12
Close Date: Close Date: invalid date: Wed Nov 09 00:00:00 GMT 12
Close Date: Close Date: invalid date: Thu Nov 10 00:00:00 GMT 12
Close Date: Close Date: invalid date: Fri Nov 11 00:00:00 GMT 12
Close Date: Close Date: invalid date: Sat Nov 12 00:00:00 GMT 12
Close Date: Close Date: invalid date: Sun Nov 13 00:00:00 GMT 12
Close Date: Close Date: invalid date: Mon Nov 14 00:00:00 GMT 12
Close Date: Close Date: invalid date: Mon Nov 21 00:00:00 GMT 12
Close Date: Close Date: invalid date: Wed Nov 23 00:00:00 GMT 12
Close Date: Close Date: invalid date: Sat Nov 26 00:00:00 GMT 12
Close Date: Close Date: invalid date: Sun Nov 27 00:00:00 GMT 12
Close Date: Close Date: invalid date: Wed Nov 30 00:00:00 GMT 12

 

None of the Opportunity records are inserted into the database. All of them fail for this sole reason. I know that the date is the only problem, because the upsert works just fine if I hard code a date with a statement like this:

 

op.CloseDate = Date.parse('12/27/2009');

 

 

I have a button on Cases for Change Management.  When the button is clicked, it calls the following apex code into a Flow, creates a Change record and I want it to come back out of the flow at the edit screen of that Change record.  Right now it gives me a redirect error.  

 

This is what I had, but it was giving me a redirect error.  I'm not familiar with apex, someone else gave me this example and I edited it to fit our objects so I'm not sure what else I need to do or create to get it to work
Apex code:

<apex:page standardController="Case">
        <flow:interview name="Case_to_Change_Flow" finishLocation="/{!Id}">
        <apex:param name="CaseId" value="{!Id}"/>
    </flow:interview>
   
</apex:page>


Button code:
 /apex/Case_to_Change?CaseID={!Case.Id}

If you could tell me exactly what else I need that would be awesome! Thanks in advance!

  • March 01, 2013
  • Like
  • 0

I start by going to the developer console and Choosing "Triggers" within the Setup Entity Type, then below, I choose a Type from the selection list and click the "New" button to the left of the list. After thinking for a few seconds, the platform responds with a window that looks like:

 

--------------------------------------------------------------------------

ENTITY_IS_LOCKED

 

Can not create Apex Trigger on an active organization.

 

OK

--------------------------------------------------------------------------

 

This message is really meaningless to me. Can anyone help decipher it?

 

Hi, new to sales force. We have a requirement in our current lms to let a department of users to take courses using our lms and then update their certification details on salesforce database.

 

1) Is it possible to access user profiles on salesforce using the REST API?

2) How exactly does a typical salesforce database maintain certification details of users?

 

Thanks,

M

I want to compare two date fields to a third and if they are >= update another field. The formula I am attempting to use is below, IK have no syntax issues but for some reason it doesnt update the field. I am out of ideas, has anyone else had this type of issue?

 

IF(AND(AvStatusChange__c != NULL,OR( BAA_Modification_Date__c  >=  AvStatusChange__c , OAA_Modification_Date__c >=  AvStatusChange__c) ), true, false)

  • January 04, 2012
  • Like
  • 0

I have a spreadsheet with 15k rows that I would like to bounce the data against Salesforce to get the Salesforce ID, what is the best way to accomplish this?  I know I can break it down into 1k rows and feed it into force.com explorer but I am looking for an easier to manage process. How is everyone else accomplishing this?

  • August 15, 2011
  • Like
  • 0