• John Pipkin
  • SMARTIE
  • 544 Points
  • Member since 2014

  • Chatter
    Feed
  • 16
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 111
    Replies
hello 
i have write a test class class that shows the following error 

(System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, offer: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddCSR: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.AddCSR: line 4, column 1: []

Trigger.offer: line 10, column 1: [])

what is problem with my test class
here i show my trigger and test class

trigger:-
trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}

the above is my trigger
and
the below is my test class
test class:-
@istest
public class updateaccount 
{
     static testMethod void verifyProductUpdation()
    {
       
        Account a=new Account(Name='ABC');
        insert a;
        
        a=[Select Id,Name from Account where Id =:a.Id];
        System.assertEquals(null, a.Product_Name__c);
        
        Product2 p=new Product2(Name='XYZ');
        insert p;
        test.startTest();
        Subsc__c sub=new Subsc__c(Name='CBZ',Company_Name__c=a.Id,Product__c=p.Id);
        insert sub;
        a.Product_Name__c=p.Id;
        update a;
        a=[Select Id,Product_Name__c from Account where Id=:a.Id];
        
        System.assertEquals(p.Id,a.Product_Name__c);
        test.stopTest();
    }   
}
thanks
Devendra 
I am kind of new to writing validation rules and I'm trying to write one for if the field "BillingState" = "OH" then the field "Industry must be populated. Any help would be greatly appreciated.
I have Custom Field called Start_Date__c in my Custom Object. I have written Validation Rule for that. my requirement is whenever user creating a record the Start_Date__c shouldnt be past date, for this i have given validation rule: START_DATE__c < Today() 
Validation Working fine,

My requirement is, when user Edits the record in future without editing the start date, at that time validation triggering, it shouldnot fire at that time...
Example: user created record on 1st  nov 2014 and user Edited record on 5th november 2014 without editing the start date, validation rule not allowing user to save record with 01st november 2014. its shouldnot happen like this, could you please help me out.

Thanks in Advance...
Hello,

I am new to Salesforce. I recently completed the Force.com Platform Fundamentals guide (An Introduction to Custom Application Development in the Cloud).

I know that I can pass data to a web service from Salesforce (this is shown in Chapter 11). However, everything I see relies on a trigger from the data or a user initiated action. My question is, in Salesforce, to call a web service on a given time interval? If so, how?

Thank you!
Hello,

i am trying to create a formula that doesn't allow usesr to edit certain fields once a record is save with a checkbox clicked, so i need the formulla to depend on whether or not the check box is clicked.

this is what i've got so far: 

AND(PRIORVALUE( Is_approved__c ), TRUE, 
ISCHANGED( Is_approved__c )) ||  ISCHANGED( Gross_Pay__c ) ||  ISCHANGED( End_Date_del__c ) ||  ISCHANGED( Has_dental_vision_insurance__c ) ||  ISCHANGED( Has_Medical_Insurance__c ) ||  ISCHANGED( Start_Date__c ) ||  ISCHANGED( Name ) ||  ISCHANGED( Net_Pay__c )
Hi all
i am a Beginner 
Please can anyone guide me to write test class for the following. 

Description: Based on Object1's fields input i am updating Object2's field. i have achieved the reqirement. But i couldn't write test class for my method. 
Object1 fields : a)Arrival time    b)Departure time 
Object2 field:Outofhours.
My code as follows
Public string CalculateOutOfOfficeHour(datetime inTime, datetime outTime){
    Map<String, String> listDayMap = new Map<String, String>{'Monday' => 'Monday', 'Tuesday' => 'Tuesday','Wednesday' => 'Wednesday' , 'Thursday' => 'Thursday' ,'Friday' => 'Friday','Saturday'=>'Saturday','Sunday'=>'Sunday'};
    String StartdayOfWeek =inTime.format('EEEE');
    String EnddayOfWeek = outTime.format('EEEE');
    time start = Time.newInstance(8,30,0,0);
    time stop = Time.newInstance(17,0,0,0);
    string bookingStarttime = string.valueOf( Time.newInstance(inTime.hour(),inTime.minute(),inTime.second(),inTime.millisecond()));
    string bookingEndtime = string.valueOf(Time.newInstance(outTime.hour(),outTime.minute(),outTime.second(),outTime.millisecond()));
    Date mysDate = Date.newInstance(inTime.year(), inTime.month(), inTime.day());
    Date myeDate = Date.newInstance(outTime.year(), outTime.month(), outTime.day());
    String result='';     
    integer numberDaysDue = mysDate.daysBetween(myeDate);

  if(numberDaysDue >= 5 )
  {
     result='BOTH';
  }            
  if((numberDaysDue == 0))
  {
     if((StartdayOfWeek == 'Saturday'||StartdayOfWeek =='Sunday')){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime < string.valueOf(start))&&(bookingEndtime < string.valueOf(start))){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(start))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(stop))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingEndtime > string.valueOf(stop))&&(bookingStarttime > string.valueOf(stop))){
             result='OUT';}
     else{
             result='IN';}
  }

 return result ;
  
}    
 

Hi everyone,

I'm sometimes asked to write code as part of my role, maybe once every 3/4 months. So although I can get by, my code isn't perfect.
I wrote a bunch of triggeres a while back and have just noticed that I left a SOQL query inside a For loop and I can't figure out how to move it out. Could anyone give me some pointers on how I can chieve this please? I'm concerned I will hit governour limits.

Thanks in advance.

Here's the part of the code in question:

trigger setupBonusFields on bc__c (before insert) {
   
        // Create a set of related opps
        set <id> ids = new set <id>();
            for (bc__c newSet : Trigger.new) {
                ids.add(newSet.opportunity__c);
            }

        // Add SA1 & SA2 to map
        map <id,Opportunity> sa1Oppmap= new map<id,Opportunity>();
            for (Opportunity o:[select Sales_Associate_1__c, Sales_Associate_2__c,
                 Sales_Associate_1__r.division__c, Sales_Associate_1__r.region__c, Sales_Associate_2__r.division__c, Sales_Associate_2__r.region__c
                 from opportunity where id in :ids]) {
                sa1Oppmap.put(o.id, o);
            }

  • November 24, 2014
  • Like
  • 0

Hi,
I want workflow to send email if the diffrence between created date and closed date of the opportunity is less than 15 days.............
I am getting this error in my code:
Non-void method might not return a value or might have statement after a return statement.
My code is as under:
public class ContactSearch {
    public static list<contact> searchForContacts(String Surname,String PCode)
    {    
        list<Contact> ListIDandName = [select ID, name, phone from contact];
        for(Contact search: ListIDandName)
        {
            if(search.name==surname && search.MailingPostalCode==PCode)
            {
                return ListIDandName;
            }
        }
    }
}
Standard Salesforce functionalty doesnt allow us to send Email Alert on Events (Task/Events - Activities). I need a trigger which will notify me or my user(s) when new Event is entered in Salesforce when custom checkbox field "Conference__C" is marked as yes. Can someone please help me with a code?
 

Hello guys, i'm trying to create a visualforce that returns the account and contacts, of the logged user but its returning this error List has no rows for assignment to SObject.

this is my controller

public with sharing class AnalyticsRevendaController {
	public Account contas   {get;set;} 
    public Contact contato  {get;set;}
    public User	   usuario  {get;set;}
    public String  userId 	{get;set;}
    
  
    // Detecta os valores do usuário ativo
	 public User activeUser = [SELECT AccountId,ContactId FROM User WHERE Id = :userId LIMIT 1];
     public String userAccount = activeUser.AccountId;
   	 public String userContact = activeUser.ContactId;
    
    public AnalyticsRevendaController(){
    //Retorna os dados do usuário Logado
    contas = new Account();
    userId = UserInfo.getUserId(); 
    if(userId != null && ''.equals(userId))
    	getAccount();
    } 
    
    //retorna os valores da conta do usuário ativo.
    public Account getAccount(){
			//Set<Id> setConta = new Set<Id>();
		List<Account> listContas = [SELECT Id,Name,OwnerId FROM Account WHERE Id = :userAccount];
			if(listContas.size()> 0)
				contas = listContas[0];
			return contas;
    }
    
    //retorna os valores do contato	ativo.
    public Contact getContact(){
    		 contato = [Select c.LastName, c.FirstName, c.AccountId,c.Email From Contact c
    				    WHERE Id=:userContact];
    		return contato;		   
    	}	
	}
 

my visualforce

 

<apex:page controller="AnalyticsRevendaController">
	
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection  title="Conta">
                <apex:outputtext value ="{!contas.Name}" />
                <apex:outputtext value ="{!contas.OwnerId}" />
            </apex:pageBlockSection>
              <apex:pageBlockSection  title="Contato">
                <apex:outputtext value ="{!Contact.FirstName}" />
                <apex:outputtext value ="{!Contact.LastName}" />
                <apex:outputtext value ="{!Contact.Email}" />
            </apex:pageBlockSection>
            <apex:pageBlockSection  title="Usuario">
                <apex:outputtext value ="{!$User.FirstName}" />
                <apex:outputtext value ="{!$User.LastName}" />
                <apex:outputtext value ="{!$User.Email}" />
                <apex:outputtext value ="{!userId}" />  
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 

 


<apex:pageBlockSectionItem rendered="{!recurrenceTrue}">
<apex:outputLabel >End Date</apex:outputLabel> <apex:inputfield value="{!newEvent.Date__c}" required="true" id="alo" onchange="checkValue2()" />
</apex:pageBlockSectionItem>

input4 is a checkbox and input5 is a date field

<script>

function checkValue2(){ if(jQuery('[id$=alo]').val() != null && jQuery('[id$=alo]').val() != '')
{
jQuery('[id$=input4]').hide();
jQuery('[id$=input5]').hide();
}

</script>

When a new date is chosen in the newEvent.Date__c field it should hide the checkbox(input4) and another datefield(input5).These elements are under separate PageBlockSectionItem.

The funny part is last evening everything was working and this morning this function is not working and I have not changed anything. Is there a way to see in the log if this function got called and executed? Is there a difference in save and quicksave?
I have other jQuery functions in this vf page as well. I have one question regarding this - should i have this under separate script tag?
 
Hi everyone!  I'm a fairly new Apex coder (I'm an old Assembler programmer from back in the day :-)  but still learning Java and Apex), and I can't figure out why this test class won't compile.  I have a feeling it's something very obvious that I'm overlooking, because 1) it's a very basic test class, and 2) I'm using virtually the same code in another test class and it works swimmingly.  If someone would be kind enough to take a look and point out the error, I'd really appreciate it!

Here's the test class:
@isTest(SeeAllData=true)
private class UtilGetPickListValuesTest {
   static testmethod void testPickListValues() {

	Test.startTest();
	list<SelectOption> plValues = new list<SelectOption>();	
	plValues = UtilGetPickListValues.getPicklistValues(Opportunity, 'StageName');
	System.debug('plValues = ' + plValues); 
	Test.stopTest();
	
	System.assert(plValues.size() > 0);
   }
}
and here's the utility class it will cover:
global without sharing class UtilGetPickListValues {
	
// Get a list of picklist values from an existing object field.
   global static list<SelectOption> getPicklistValues(SObject obj, String fld)
   {
      list<SelectOption> options = new list<SelectOption>();
      // Get the object type of the SObject.
      Schema.sObjectType objType = obj.getSObjectType(); 
      // Describe the SObject using its object type.
      Schema.DescribeSObjectResult objDescribe = objType.getDescribe();       
      // Get a map of fields for the SObject
      map<String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap(); 
      // Get the list of picklist values for this field.
      list<Schema.PicklistEntry> values =
         fieldMap.get(fld).getDescribe().getPickListValues();
      // Add these values to the selectoption list.
      for (Schema.PicklistEntry a : values)
      { 
         options.add(new SelectOption(a.getLabel(), a.getValue())); 
      }
      return options;
   }

}

And while I'm writing, I'd like to say thanks to all of you who take time to offer your help and advice on the developer community!  It is an invaluable resource to me, and I'm sure to many others as well!

Deb



 
Hello friends
i have created an trigger that  copy one obj to another 
but i have  three record type like recordtype1, recordtype2, recordtype3  when i selected recordtype3 only the case the trigger have been fire otherwise it will not fire 
so what i needed, to do this

following is my trigger

trigger copypro  on Subsc__c  (after insert,after update) 
{
  Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();
  set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's

  for (Subsc__c s : Trigger.new)
  {
    listIds.add(s.Company_Name__c);
      
    if(s.Product__c     != null)
    {
       cObjectID.add(s.Product__c    );//takes the Lookup Record & Add that ID's in cObjectID set
     }
  }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        
        for(Subsc__c s : trigger.new)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                 Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
                Account myacc = acc.get(s.Company_Name__c);
                 myacc.Product_Name__c =pro;
                update Acc.values();
            }
        }
    }
   
}
Hi I have a scenario where the contact has a checkbox called IS user active which has to be updated as and when user becomes inactive to false.

I wrote a trigger to do it showed me a mixed DML error and wrote the below code using future method as well now I am getting another error. Need some help on this

Trigger.

trigger Checkuseractive on User (after update) {

    user u=[select id,Isactive,contactid from user where id=:trigger.new[0].id];
    Id cid=u.ContactId;
if(trigger.new[0].IsActive=='false') 
{
    contactactivecheckboxclass.updatecnt(cid);
}
    
}

Future Method

public class contactactivecheckboxclass {
@future
    public static void Updatecnt(id x)
    contact c=[select Is_user_Active__c from Contact where id=:x];
    c.Is_User_Active__c=false;
    update c;
}

Error : Unexpected token :Contact on class line 4
hellow all
i dont no how to write a test class of trigger please help me and tell the test class of below trigger
thankss
here is my trigger 

trigger CopyRolltoStudent1 on class__c (before insert,before update) //You want it on update too, right?
{
  Map<ID, Student__c> parentroll = new Map<ID, Student__c>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (class__c childObj : Trigger.new)
  {
    listIds.add(childObj.student__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentroll = new Map<Id, Student__c>([SELECT id, Roll_No__c,(SELECT ID, Roll_No__c FROM Class__r) FROM Student__c WHERE ID IN :listIds]);

  for (class__c cl : Trigger.new)
  {
     Student__c myParentroll = parentroll.get(cl.student__c);
     myParentroll.Roll_No__c = Decimal.valueOf(cl.Roll_No__c);
  }
    
  update parentroll.values();
}
I am trying to create a Customer Portal User through a force.com site with Apex but keep getting the following error:

"That operation is only allowed from within an active site."

I am running the code from the Guest User on the force.com site, the site is active and it's connected to the customer portal, and the account owner has a role. 

Here's the method I'm using:
 
@future
public static void createPortalUser(String acctId, string email){
    
    User cu = new User(Username=email,CommunityNickName='test', email=email);
    Site.createPortalUser(cu, acctId, 'test123', true);
}
What am I missing?
 
I have a detail page button that executes Javascript on click. In the button there are multiple DML statements but I would like to set save points so if an error occurs, I can roll back the changes. Is this possible without creating webservice apex methods?
I have a detail page button that executes Javascript on click. In the button there are multiple DML statements but I would like to set save points so if an error occurs, I can roll back the changes. Is this possible without creating webservice apex methods?
I have 1 User that is receiving this error and i do not know why. I have even created a new profile; didn't work. So I created a new user for him; still get same error.
This is a visualforce page of the users tasks that can be modified and saed on the page without having to open the Task.


Attempt to de-reference a null object
Error is in expression '{!saveRecord}' in component <apex:commandButton> in page allopentasks: Class.TaskController.saveRecord: line 145, column 1
Hi All,

Intaially i got Collection size is exceed error, so i used readonly = true
Then i got View state error in my vf page ............
Total records are 1100 Now............

Adv Thnx
Siv
 
  • January 07, 2016
  • Like
  • 0
Hi,

I am not sure if this is possible, but I would like to see a list of products a certain company has purchased, and the quantity purchased over a period of time.
ie
General Co Item A 25
General Co Item B 50

I have done some things on my own but can't quite get this.  I am still a bit new to SOQL.

This query works: (No rollup)
SELECT Description__c, Order_Quantity__c, Stock_Code__c, Order_Header__r.Customer_Name__C FROM Order_Detail__C WHERE Stock_Code__C = '6195'

This query works: (With Rollup, but no products) (it essentially shows how many Sales Orders we have in the system per Account.)
SELECT customer_Name__C, COUNT(id) total
    FROM Order_header__c
    GROUP BY ROLLUP(customer_Name__C) LIMIT 25

This query doesn't work (MALFORMED_QUERY: Field must be grouped or aggregated: Customer_Name__c)
SELECT Description__c, Order_Quantity__c, Stock_Code__c, Order_header__r.Order_Date__C, Order_Header__r.Customer_Name__C, COUNT(id) total
 FROM Order_Detail__C
 WHERE Order_Header__r.Customer_Name__C LIKE 'Conney' AND Order_header__r.Order_Date__C >= 2015-01-01
 GROUP BY ROLLUP(Stock_Code__C)

I have done some digging and found some possible terms to use but not sure which to use here or how.
count(id)
sum(pid= )
union all

Any help would be appreciated

Aron
Here am writing the parent -child query ...account parent and Entitlement is child...why it is not working..

select id,name,(select Entitlement.name,Entitlement.Status from entitlement) from account



Help me in this ...thanks in advance...
hello 
i have write a test class class that shows the following error 

(System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, offer: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddCSR: execution of BeforeInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.AddCSR: line 4, column 1: []

Trigger.offer: line 10, column 1: [])

what is problem with my test class
here i show my trigger and test class

trigger:-
trigger copypro  on Subsc__c  (after insert,after update) 
{
    //Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'User Group Membership'].Id;
    Id recordTypeId = Schema.SObjectType.Subsc__c.getRecordTypeInfosByName().get('User Group Membership').getRecordTypeId();

    List<Subsc__c> subscList = new List<Subsc__c>();

    for (Subsc__c s : Trigger.new){
        if(s.RecordTypeId == recordTypeId)
            subscList.add(s);
    }

    Map<ID, Account> Acc = new Map<ID, Account>(); //Making it a map instead of list for easier lookup
    List<Id> listIds = new List<Id>();        
    set<ID>cObjectID = new set<ID>();   //Making a set of Product ID's
    Map<ID, Account> updateMap = new Map<ID, Account>();
  
    for (Subsc__c s : subscList)
    {
        listIds.add(s.Company_Name__c);
      
        if(s.Product__c     != null)
        {
            cObjectID.add(s.Product__c    );//takes the Lookup Record &     Add that ID's in cObjectID set
        }
    }
    if(!cObjectID.isEmpty()){
        
        Map<ID,Product2> cObjectMap = new Map<ID,Product2>([select Id,Name from Product2 where Id IN: cObjectID]);
        Acc = new Map<Id, Account>([SELECT id, Product_Name__c,(SELECT ID,Product__c FROM Subscs__r) FROM Account WHERE ID IN :listIds]);
        
        for(Subsc__c s : subscList)
        {            
            if(cObjectMap.get(s.Product__c    ).Name != Null)
            {
                // fill the country name on Opportunity with Country Name on Country_Object__c
                String pro= cObjectMap.get(s.Product__c    ).Name;
                Account myacc = acc.get(s.Company_Name__c);
                if(myacc != null){ //always check for nulls to avoid null pointer exceptions
                    myacc.Product_Name__c =pro;
                    updateMap.put(myacc.Id,myacc);
                }
            }
        }
        update updateMap.values();
    }
   
}

the above is my trigger
and
the below is my test class
test class:-
@istest
public class updateaccount 
{
     static testMethod void verifyProductUpdation()
    {
       
        Account a=new Account(Name='ABC');
        insert a;
        
        a=[Select Id,Name from Account where Id =:a.Id];
        System.assertEquals(null, a.Product_Name__c);
        
        Product2 p=new Product2(Name='XYZ');
        insert p;
        test.startTest();
        Subsc__c sub=new Subsc__c(Name='CBZ',Company_Name__c=a.Id,Product__c=p.Id);
        insert sub;
        a.Product_Name__c=p.Id;
        update a;
        a=[Select Id,Product_Name__c from Account where Id=:a.Id];
        
        System.assertEquals(p.Id,a.Product_Name__c);
        test.stopTest();
    }   
}
thanks
Devendra 
I am kind of new to writing validation rules and I'm trying to write one for if the field "BillingState" = "OH" then the field "Industry must be populated. Any help would be greatly appreciated.
I am looking to have tasks triggered based on line items within an opportunity when the opportunty is closed. 
I am trying to create a Customer Portal User through a force.com site with Apex but keep getting the following error:

"That operation is only allowed from within an active site."

I am running the code from the Guest User on the force.com site, the site is active and it's connected to the customer portal, and the account owner has a role. 

Here's the method I'm using:
 
@future
public static void createPortalUser(String acctId, string email){
    
    User cu = new User(Username=email,CommunityNickName='test', email=email);
    Site.createPortalUser(cu, acctId, 'test123', true);
}
What am I missing?
 
Hi all,

I was wondering if it is possible to convert a lead into a custom object? I am creating a web-to-lead form which has feilds that relate to a custom object.

Hi Everyone,

I am working on my sandbox on CS7 and all of a sudden my classes cannot be saved in the Developer console (they get stuck "saving"). If I go into the Salesforce Apex Test Execution page and try to run any tests these also get stuck and never finish.

Is this a known error? I am pressed with time and time is holding me back from testing and deploying a huge project.. so time is something i dont have

Many thanks in advance,
Ines

I have an object Timecard <pse__Timecard_Header__c> and a lookup field PD <PD__c> which is related to another object called Period i.e. <c2g__codaPeriod__c>. I want to fill this lookup field everytime I create a new Timecard.

Iam trying to count the number of contacts on account, Iam getting the following error message

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Account> at line 10 column 1    

Trigger counting on contact(after update,after insert){
Set<account> accids=New Set<Account>();
For(contact c:trigger.new){
Accids.add(c.Account);
}
List<Contact> con = [select id  from contact where AccountID IN:accids];
List<Account> Acc=[Select count__C from account where id IN:accids ];
For(contact c:trigger.new)
{
Acc.count__c=con.size();
}
}
Hi all
i am a Beginner 
Please can anyone guide me to write test class for the following. 

Description: Based on Object1's fields input i am updating Object2's field. i have achieved the reqirement. But i couldn't write test class for my method. 
Object1 fields : a)Arrival time    b)Departure time 
Object2 field:Outofhours.
My code as follows
Public string CalculateOutOfOfficeHour(datetime inTime, datetime outTime){
    Map<String, String> listDayMap = new Map<String, String>{'Monday' => 'Monday', 'Tuesday' => 'Tuesday','Wednesday' => 'Wednesday' , 'Thursday' => 'Thursday' ,'Friday' => 'Friday','Saturday'=>'Saturday','Sunday'=>'Sunday'};
    String StartdayOfWeek =inTime.format('EEEE');
    String EnddayOfWeek = outTime.format('EEEE');
    time start = Time.newInstance(8,30,0,0);
    time stop = Time.newInstance(17,0,0,0);
    string bookingStarttime = string.valueOf( Time.newInstance(inTime.hour(),inTime.minute(),inTime.second(),inTime.millisecond()));
    string bookingEndtime = string.valueOf(Time.newInstance(outTime.hour(),outTime.minute(),outTime.second(),outTime.millisecond()));
    Date mysDate = Date.newInstance(inTime.year(), inTime.month(), inTime.day());
    Date myeDate = Date.newInstance(outTime.year(), outTime.month(), outTime.day());
    String result='';     
    integer numberDaysDue = mysDate.daysBetween(myeDate);

  if(numberDaysDue >= 5 )
  {
     result='BOTH';
  }            
  if((numberDaysDue == 0))
  {
     if((StartdayOfWeek == 'Saturday'||StartdayOfWeek =='Sunday')){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime < string.valueOf(start))&&(bookingEndtime < string.valueOf(start))){
             result='OUT';}
     else if((StartdayOfWeek == 'Monday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(start))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingStarttime <= string.valueOf(start))&&(bookingEndtime > string.valueOf(stop))){
             result='BOTH';}
     else if((StartdayOfWeek == 'Friday')&&(bookingEndtime > string.valueOf(stop))&&(bookingStarttime > string.valueOf(stop))){
             result='OUT';}
     else{
             result='IN';}
  }

 return result ;
  
}