• jbroquist
  • SMARTIE
  • 509 Points
  • Member since 2008

  • Chatter
    Feed
  • 18
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 93
    Replies

Hi All,

I have two object in the related list and if Approal Status on both the object changes to "Approved " then the Project_State__c field on the parent object changes to "Closed".

 

I have written the trigger but It's not working...please help me

 

trigger Update_Project_State on Project__c (before update) {

 

for(Project__c Prj:trigger.New){

 List<Quality_of_Delivery__c> Lstqod= new LIST<Quality_of_Delivery__c>();//object-1 MD relation

 List<Root_Cause__c> LstRC= new LIST<Root_Cause__c>();       //object-2 lookup    

 

Lstqod=[Select project__c,Final__c,Approved_Status__c from Quality_of_Delivery__c where project__c=: prj.Id];//Query qod      

 

LstRC=[Select Project_Name__c,Final__c,Approval_Status__c from Root_Cause__c where Project_Name__c=: j.Id];               

List<Project__c> prjupdate= new List<Project__c>();

            if(LstRC!=null){        for(Root_Cause__c r:LstRC){  

            if(r.Approval_Status__c=='Approved' && r.Final__C==True)  

             {                

              if(Lstqod!=null){     

                                  for(Quality_of_Delivery__c q:lstqod)  {    

                                            

                            if(q.Approved_Status__c=='Approved' && q.Final__c==True){

                                                             

                                   if(prj.Project_State__c=='Active'){                         

                                                     prj.Project_State__c='Closed';    

                                                     prjupdate.add(prj);      

                               }                                                                                                      

                           else if(prj.Project_State__c=='In Cancellation')

                                          {                                 

                                  prj.Project_State__c='Cancelled';                             

                                     prjupdate.add(prj);                              

   }                                                                                                                                                                       

   }

}                                                                     

update prjupdate;                                                                                                                                   

        }       

        }                                          

    }       

   }                                                               

}

}

HI 

I am  facing the above error when i am trying to follow the record after saving.

 

Please  clarify.

I am trying to fix my apex class testing code except I do not understand a way around what it is telling me to do. It tells me that in line 17, its expecting a right parenthesis, but only found a ;...however when I attempt to put a right parenthesis in it begins telling me all manor of things. It tells me that it does not expect token 'product' in the next line, that it is now expecting a close right curly bracket in line 17, etc. Please help!

 

This is my code, you will probably recognize it from the force.com workbook spring 13 release. I followed their instructions exactly:

 

@isTest

private

class TestHandleProductPriceChange {

 

  

statictestMethodvoid testPriceChange () {

  

Invoice_Statement__c Invoice = newInvoice_Statement__c(Status__c = 'Negotiating');

  

insert Invoice;

  

  

Merchandise__c[] products = new merchandise__c[]{

  

newMerchandise__c(Name = 'item 1', Description__c =

  

'test product 1', Price__c = 10,Total_Inventory__c = 10),

  

newMerchandise__c(Name = 'item 2', Description__c =

  

'test product 2', Price__c = 11,Total_Inventory__c = 10)

    };

    Insert products;

  

Line_Items__c[] LineItems = newLine_Items__c[] {

  

newLine_Items__c(Invoice_Statement__c = invoice.id,

  

Merchandise__c = products[0].price__c = 20; //raise price

    prodcts[1].price__c = 5;

//lower price

    Test.startTest();

  

update products;

    Test,stopTest();

  

    lineItems =

    [

SELECT id, unit_price__c FROM Line_items__c WHERE id IN :lineItems];

    System.assert(lineItems[0].unit_price__c ==10);

//unchanged

    System.assert(lineItems[1].unit_price__c == 5);

//changed!!

    };

  

insert lineItems;

  

    products[0].price__c = 20;

    Test.startTest();

  

update products;

    Test.stopTest ();

  

    lineItems = [

SELECT id, unit_Price__c FROMLine_Items__cWHERE id IN :lineItems];

  

  

system.assert(lineItems[0].unit_Price__c == 10);

    }

    }

 

 

 

any help would be much appreciated

I have a trigger that is working in the sandbox to insert the Forecast-quota records from my custom budget object.  When I attempted to run in production today, I am getting the above message.  I am running as admin in both environments.  The only difference is the volume of data I am loading.  Any suggestions?

 

 

I am currently creating opportunity teams in a trigger by inserting into OpportunityTeamMember and then OpportunityShare.  Everything is working on the surface...the team members are getting created.  But when I look into the logs, I am seeing errors when inserting into the team member table:

 

12:20:39.283 (283789000)|USER_DEBUG|[236]|DEBUG|.............The DB Insert failed for the following Opportunity Team Member: 00560000000zDeyAAE
12:20:39.286 (286362000)|USER_DEBUG|[237]|DEBUG|.............The DB returned the following error for the above record: Database.Error[getFields=(Opportunity);getMessage=Required fields are missing: [Opportunity];getStatusCode=REQUIRED_FIELD_MISSING;]

From the message,  I am not quite sure which required field is missing. I am inserting the Opportunity ID, the user ID, and the team role into the team member table.  then for each record that was inserted into the team member  table, I am inserting a corresponding opportunityshare record.  The only other field that looks like it may be required in the OpportunityTeamMember table is the OpportunityAccessLevel column, but that field is not writeable (I assume this column is being updated by a backend process once the opportunityshare record is created).

 

If there are suppose to be three users on the team, there will three sets of the above messages in the logs, yet all three members are showing on the opportunity as team members.  So it appears to be working.  Any ideas why I am seeing this in the logs?  Thanks

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);
			}

		}
	}
	
	
    }
}

 

 

i am trying to access the Report objects in apex but getting limited fields my apex source code is

public Class MyController{
public List<Report> getReports(){

List<Report> rep1 = new List<Report>();
rep1=[Select Id,Developername,Description,Name,OwnerId from Report];


return rep1;

}

}

but i want to get the value of the sObject type to which it is related to for example 1.i click on new Report 2.then select Opportunities 3.then click create

how to get this opportunity object and how to get filters applied to reports please explain it.

I'm looking to have a trigger update a checkbox on a contact page whenever an idea is posted to the idea section.  I've written the trigger below but I'm missing something.

 

I think I've been able to query the ID of the user logged in (saved as uid).  I need a way to say update the field for the contact with the same ID (I'm assuming the contact ID will be the same as the user ID?)

 

This is my first attempt at Apex coding.

 

trigger UpdateContact on Idea (after insert, after update){

for (Idea newIdea : Trigger.new){

//Gets the user id who posted the idea
id uid = UserInfo.getUserId();

//Need code to set the PortalUse_IdeaRaised__c field to true (this is a checkbox)

//Something along the lines of Contact.PortalUse_IdeaRaised__c = true;
}

}

 

 

This doesn't work. Any ideas?

 

COb__c c = [select Parent__r.Name fro Cobj__c limit 1];


String parentName = c.get('Parent__r.Name');

 

 

Anyone else having trouble with IDE version 27 not building after save?

 

Tried everything setting I could find but the only way was to "Save to server' after every change.

 

Needless to say that got pretty tedious so I went back to version 26 and all is well. Was it just me?

I am trying to populate Contract_Header_LOOKUP__c (a lookup field) with the id from Contract_Header__c (a text field)... hence, the SOQL query.

 

It compiles, but when I try to get it to work, I am getting this error.

 

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger ContractLine_ContractHeaderLookupUpdate caused an unexpected exception, contact your administrator: ContractLine_ContractHeaderLookupUpdate: execution of BeforeUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.ContractLine_ContractHeaderLookupUpdate: line 7, column 1

 

trigger ContractLine_ContractHeaderLookupUpdate on Contract_Line__c (before update, before insert){

    for (Contract_Line__c cl: Trigger.new)
    {
        if(cl.Contract_Header_LOOKUP__c == Null)
        {
            cl.Contract_Header_LOOKUP__c = [SELECT id FROM Contract_Line__c WHERE Name =: cl.Contract_Header__c].id ;
        }
    }
}

 

This helped me (http://boards.developerforce.com/t5/Apex-Code-Development/Can-t-get-this-trigger-to-work-any-ideas-Populate-Lookup-field/m-p/341141#M60433), but I am stuck at this point...

 

Any help is greatly appreciated!

I'm trying to do a trigger that doesn't let anyone close the case if I have tasks opened in the case.

 

If you try to close the case an error will appear.

 

Code:

 

trigger ChamadoAbertoTarefaAberta on Case (after update) {

    {
        List <Task> statuslist = [SELECT id, Status FROM Task WHERE WhatId IN :trigger.new AND Status statuslist.add(t.WhatId, true)];
        MAP<id,string> statuslist= new LIST<Id,String>(); 
   		for(Task t : trigger.new) 
        }
            
            for(Case c : trigger.new()){
            if(map.get(c.Id) == true){
            c.addError(My error here); 
            }
            else{
            break; 
}
            }
}

 I don't know where I'm going wrong.

 

Thanks for help !

Hi Everyone.

 

When a Sales user from my production is viewing their Events on the calendar, it only links to the Account... is there a way to just have it link to the opportunity?

 

Anil

Hi,

I have two object QOD__c--> child object, Approval_Status__c is a field on this object

Project__c--> Parent Object, Project_State__c is a field on this object.

 

I'm writting a trigger whenevr Approval_Status__c changes and equal to Approved then update the Project__State__c to "Closed"

 

below is the trigger but m getting error on it...

trigger Populate on Quality_of_Delivery__c (after update) {

List<Project__c> Lstprj=new List<Project__c>(); Set<Id> PrjId =new Set<Id>();

Lstprj=[Select Id from Project__c];

for(Project__c proj : lstprj){

PrjId.add(proj.Id);

}

    Map<Id,Project__c> prj = new Map<Id, Project__c>([select Project_State__c,Id from project__c where id in :prjid]);//Getting error here..DML requires SObject or SObject list type: MAP<Id,Project__c> at line 30 column 13 

 

      for(Quality_of_Delivery__c q: Trigger.new)  

{  

 

if(trigger.oldmap.get(q.Id).Approved_Status__c!=trigger.newmap.get(q.Id).Approved_Status__c)  

 

    {  

 

    if(  trigger.newmap.get(q.Id).Approved_Status__c=='Approved'){

                     prj.get(q.Project__c).Project_State__c='Closed';      

                          }      

      }         

    update prj;  

        

                      }

  }

 

please look into this

 Hai every one.....

 

           I am new to sfdc......  I had one visualforce page with the following:-

                                                           ______________

                                        Location  |______________|  

                                                             _____________ 

                               Expected sal      |______________|

 

                                                            ______________

                                      Skill set       |______________|

 

                                                            ______________

                                    Experience   |______________|

 

                                                                             __________
                                                                            |      SEARCH |   

 

                        I had one position object  (custom) . i would like to perform search on  Location(us,uk) and expected sal (less than 2L,3L or >=6L etc) and Skill set(java,.net... etc) Experience(<2yrs,or >3yrs etc....) .

If user enter  any values in visual force page and clicks search button then we need to display the records belonging to his criteria .

But  iam unable to perform search on all Fields ....

i created one query but it is quering only with one field ineed to have with all fields.... can any one help me.....

provide any code snippet...

public with sharing class ItemEditController {

    private ApexPages.StandardController controller {get; set;}
  public List<applicant__c> searchResults {get;set;}
   public List<position__c> searchResult {get;set;}
  public string searchText {get;set;}
   public string searchwith {get;set;}
 
  // standard controller - could also just use custom controller
  public ItemEditController(ApexPages.StandardController controller) { }
 
  // fired when the search button is clicked
  public PageReference search() {
 
String qry = 'select First_Name__C,Last_Name__c, mobile__c,Skill_set__c,Experience__C,Expected_Annual_Salary__C,current_salary__C from applicant__c ' +
      'where First_Name__C LIKE \'%'+searchText+'%\' ';
    searchResults = Database.query(qry);
   return null;
    return Page.SearchApplicants;
  }
 
  // fired when the save records button is clicked
  public PageReference save() {
 
    try {
      update searchResults;
    } Catch (DMLException e) {
      ApexPages.addMessages(e);
      return null;
    }
 
    return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
  }
 
  // takes user back to main record
  public PageReference cancel() {
    return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
  }

 

  i hwant to set default value below is code

but its give error,

"Compile Error: expecting right curly bracket, found '[' at line"

 

[DefaultValue('Not Available')]
     public String CompanyName{get; set;}

HI All,

 

I have declared a global variable in outer class and trying to access that varibale in inner class method it is showing error.

 

Can any one help me plz it very urgernt.

global class GlobalTest{   

    global String value='Situ';      

    public class Myclass{            

          public void  gtestMethod(){                  

               System.debug(value);     

          }

      }  

}

Error is like Variable does not exist: value at line 6 column 24

Thanks

Situ

i figured this should be pretty simple. I have a custom object called ONSITE_PRODUCT__c

onsite_product__c has a lookup field called product__c which has a lookup relationship to the salesforce products object. 

 

ive created a new picklist field called New_products__c which also has a list of the same products as the product__c lookup field. I want a user to select a product from the New_products__c picklist and have that same product value saved as the product lookup field value.

 

heres my trigger

 

trigger UpdateOnsiteProduct on Onsite_Product__c (before insert,before update) {
    { 
        for (Onsite_Product__c a : Trigger.new) 
        { 
            a.Product__c = a.New_Products__c;
        }
    }
}

 

 

and this is the error i keep receiving

 

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger UpdateOnsiteProduct caused an unexpected exception, contact your administrator: UpdateOnsiteProduct: data changed by trigger for field Product: id value of incorrect type: XYZ PRODUCT

 

Thanks.