• Pallav
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 21
    Replies
Hi All,

I am facing a issue with the trigger that I have developed, where validation takes place and shows the user with the custom error message. When I run the test class for the code coverage code. I throws the custom field validation messages that I have specified on the code of the trigger.

If any one has nay knowledge in these regard, I would request you to provide me with the same.

Here is the code.

trigger ValidateAccOnProject_trigg on SSI_Project__c (before insert, before update)
{
    try
    {
        for(SSI_Project__c sp : trigger.new)//loops through the Projets that have been updated or inserted
        {
            if(sp.System__c =='Majic')// checkes wheather the System field value is 'Majic'
            {
                //Retrives the value of the Site Id and Site In Buiness fields.
                List<Account> acc = new List<Account>([Select Site_ID__c, Site_In_Business__c from Account where Id =: sp.Account__c]);
                if(acc.get(0).Site_ID__c != null)//Checks if Site Id Exist on the related Account
                {
                    if(acc.get(0).Site_In_Business__c == true)//Chceks if Site In Business field is cheked or not.
                    {
                        sp.Site_ID__c = acc.get(0).Site_ID__c;// assigns the site id of the related account to the Site Id of the Project
                        sp.Company_ID__c = null;
                    }
                    else sp.addError(' Invalid Account :  Must select Active Account');
                }
                else sp.addError(' Invalid Account :  Must select Account with Site ID');
            }
            if(sp.System__c =='eSynergy')// checks if the System field value is 'eSynergy'
            {
                //Retrives the value of the Business Status and Customer Id field from Account
                List<Account> acc1 = new List<Account>([Select Business_Status__c, Customer_ID__c from Account where Id =: sp.Account__c]);
                if(acc1.get(0).Customer_ID__c != null)// cehcks if Customer Id exist on the related account
                {
                    if(acc1.get(0).Business_Status__c =='Active')// Checks if the value of the Business Status field is set to 'Active'.
                    {
                        sp.Company_ID__c = acc1.get(0).Customer_ID__c;// Assigns the value of the Customer id from Account to the Company Id field on Project.
                        sp.Site_ID__c = null;
                    }
                    else sp.addError('  Invalid Account:  Must select Active Account');
                }
                else sp.addError(' Invalid Account :  Must select Account with Customer ID');
            }
            if(sp.Billable__c == false)// Checks if Project's Billable field is checked or not.
            {
                if(sp.Parent_Project__c != null)// Checks if the project that we are creating or updating has a Parent project associated to it.
                {
                    // Retrives the Currency type of the Parent Project associated to a Sub Project.
                    List<SSI_Project__c> ssip = new List<SSI_Project__c>([Select CurrencyIsoCode from SSI_Project__c where Id =: sp.Parent_Project__c]);
                   
                    if(sp.CurrencyIsoCode != ssip.get(0).CurrencyIsoCode)// Checks if the Currency type of the the Sub Project Matches with the Currency type of the Sub Project
                        sp.addError('This project must be in ' + ssip.get(0).CurrencyIsoCode +' Currency');
                }
            }
        }
    }
    catch(Exception e)
    {}
}
  • August 05, 2008
  • Like
  • 0
Hi,

I just want to have a printable view of the Activity detail page as all other pages like in Opportunity or Accounts. Please advice.

thanks in anticipation of you response.

thanks and regards
Pallav
Hi All,
I am facing issue with trigger that I have to develop.

Problem: A newly created record inserts the current user id and username in the owner id and owner name fields natively on save.


Wanted: Apex trigger to keep the current owner id/name the same as existing owner id/name on saving of the record if it does not match the current userId or createdbyId.


Use Case:

1. Open record
2. Change record owner to someone else
3. Save record
4. Clone record

5. Save new record (with the same owner as original pre-cloned record)
6. The new cloned case should still be owned by the previous owner.

Notes: Standard clone code will show the original owner on the owner field. The new record gets updated to the userId/Name on Save.

Thanks in anticipation of your response.
Pallav
Hi All,
 I am facing a issue with the trigger that I have developed.

When ever any new record is inserted then after the insert a custom field get updated. The update section of the trigger get fired up where I have written the code for before upate. Here, the fields does not reflect the value automatically. for ever record after insert I have to manually go and click edit and save to reflect the value.

Below given is the piece of code for the trigger. Please let me know what I am doing wrong with it.

trigger LeadTrigger on Lead (before update, after insert)
{
    List<Id> OwnerIds = new List<Id>();
    for (Integer i = 0; i < Trigger.new.size(); i++)
    {
           OwnerIds.add(trigger.new[i].OwnerId);
    }
   
    Map <Id, Id> contactAcc = new Map <Id, Id>();
    for (User u : [Select Id, Contact.AccountId From User where ContactId  != null and UserType = 'PowerPartner' and Id in : OwnerIds])
    {
        contactAcc.put(u.Id, u.Contact.AccountId);
    }
   
    Map <Id, Id> CAMs = new Map <Id, Id>();
    for (Account  acc: [Select Id,  OwnerId From Account where Id in : contactAcc.values()])
    {
        CAMs.put(acc.Id, acc.OwnerId);
    }

    Map<Id, User> userRecords =  new Map<Id, User>([Select Id, UserType from User where Id In : OwnerIds]);
    if(trigger.isBefore && trigger.isUpdate)
    {
        try
        {
            for(Lead l : trigger.new)
            {
                for (Integer j = 0; j < Trigger.new.size(); j++)
                {
                    if(userRecords.get(l.OwnerId).UserType!=null && userRecords.get(l.OwnerId).UserType=='PowerPartner')
                    {
                        l.CAM__c=CAMs.get(contactAcc.get(trigger.new[j].OwnerId));
                    }
                    else
                    {
                        l.CAM__c= null;
                    }
                }
            }
        }
        catch(Exception e)
        {}
    }
    if(trigger.isAfter && trigger.isInsert)
    {
        List<Lead> savedLeads = new List<Lead>();
        try
        {
            for(Lead l : trigger.new)
            {
                for (Integer j = 0; j < Trigger.new.size(); j++)
                {
                    if(userRecords.get(l.OwnerId).UserType=='PowerPartner')
                    {
                        Lead newLead = new Lead(Id=l.Id, CAM__c=CAMs.get(contactAcc.get(trigger.new[j].OwnerId)));
                        //l.CAM__c=CAMs.get(contactAcc.get(trigger.new[j].OwnerId));
                        savedLeads.add(newLead);
                    }
                }
            }
            update savedLeads;
        }
        catch(Exception e)
        {}
    }
}


Hoping for a quick and positive response from you guys and thanks in anticipation of your answer.

Thanks and regards
Pallav
Hi All,

I am facing a very unusual situation in the Production instace. I have developed a trigger to populate some fields, it works absolutely fine in the sandbox instance. When I have moved the trigger to the production instance with 90% of code coverage. it is giving me the "Too many SOQL queries" exception when data loaded in bulk. But, in the Debug Log it shows only Number of SOQL queries: 3 out of 20 excuted. I am totally confused what is going on and have no idea what so ever why this is happening.

This is the line that is causing the error:

Map<Id, User> userRecords =  new Map<Id, User>([Select Id, UserType from User where Id In : OwnerIds])

Here, "OwnerIds" is a list of Ids, which was got by:-

List<Id> OwnerIds = new List<Id>();
for (Integer i = 0; i < Trigger.new.size(); i++)
{
        OwnerIds.add(trigger.new[i].OwnerId);
}


I would request you to kindly through some light on the situation that I am in. Hoping for a quick response from your side.

Also, thanks in anticipation of your answers.

Thanks and regards
Pallav
Hi All,

I am facing issue with my trigger running in bluk. When I have made the code to run in bulk it gives me errors.

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY and

Too many SOQL queries on line 16 of the trigger code.

permisions are all ok and there is no issue wthn run with 1 record. Pleae let me know what is the issue for it.

Code for the trigger is given below:-


trigger testOCMopp on Opportunity (after update)
{
    if(trigger.IsAfter)
    {
        if(trigger.IsUpdate)
           {
            Set<Id> OpportunityIds = new Set<Id>();
                      
               for (Integer i = 0; i < Trigger.new.size(); i++)
            {
                OpportunityIds.add(trigger.new[i].Id);
            }
            Map<Id, Opportunity> oppRecords = new Map<Id, Opportunity>([select Id, Marketing_Influence_Indicator__c,WP_Recipient__c from Opportunity where Id In : OpportunityIds]);
           
            Map<Id, Opportunity_Campaign_Member__c> OCM = new Map<Id, Opportunity_Campaign_Member__c>([Select Id from Opportunity_Campaign_Member__c where Opportunity__c In : OpportunityIds]);
            Map<Id, OpportunityContactRole> OCR = new Map<Id, OpportunityContactRole>([Select ContactId, IsPrimary, OpportunityId from OpportunityContactRole where OpportunityId In : OpportunityIds and IsPrimary=:true]);
                   
            for(Opportunity o: trigger.new)
               {
                   if(OCM.get(o.id)==null)
                   {
                       if (oppRecords.get(o.id).Marketing_Influence_Indicator__c!=0)
                       {
                           Opportunity opp=new Opportunity(Id=o.Id,Marketing_Influence_Indicator__c=0);
                           oppRecords.put(o.id,opp);
                           update oppRecords.values();
                    }
                   }
                   else
                   {
                       if (oppRecords.get(o.id).Marketing_Influence_Indicator__c!=1)
                    {
                        Opportunity opp=new Opportunity(Id=o.Id,Marketing_Influence_Indicator__c=1);
                           oppRecords.put(o.id,opp);
                           update oppRecords.values();
                    }
                   }
                   if(OCR.get(o.id)!=null)
                   {
                       if(oppRecords.get(o.id).WP_Recipient__c!=OCR.get(o.id).ContactId)
                       {
                           Opportunity opp=new Opportunity(Id=o.Id,WP_Recipient__c=OCR.get(o.id).ContactId);
                           oppRecords.put(o.id,opp);
                           update oppRecords.values();
                       }
                   }
                   else
                   {
                       if(oppRecords.get(o.id).WP_Recipient__c!=null)
                       {
                           Opportunity opp=new Opportunity(Id=o.Id,WP_Recipient__c=null);
                           oppRecords.put(o.id,opp);
                           update oppRecords.values();
                       }
                   }
               }
           }
    }
}

Thanks in anticipation of your answer

thanks and regards
Pallav
  • March 12, 2008
  • Like
  • 0
Hi All,

I am facing a issue with the SelectList, if I populate the SelectList with the name of an Account the select from and that is along with some more fields are mendetory. Then if I select the Account name from the SelectList and did not provide any input to any one of the the required fields. Then the page returns back itself and all other values along with the static picklists which are hard-coded their values remains unchanged except the value of the picklist that is feeded with the Account names in the salesforce instance.

Given below is the code for the page and controller:

<apex:selectList id="fcHotel" value="{!Accounts}" style="width: 140px" styleClass="std" size="1">
                <apex:selectOptions value="{!accList}"/>
              </apex:selectList>

Controller Section:

Map<String,String> accMap= new Map<String,String>();

public String getAccounts()
    {
        return accMap.get(selectedacc);
    }
    public void setAccounts(String selectedacc)
    {
        this.selectedacc= selectedacc;
    }

public List<SelectOption> getaccList()
{   
    List<SelectOption> options = new List<SelectOption>();
        Account[] accounts = [Select Id,Name from Account];
       
                options.add(new SelectOption('','-- Select One --'));
               
            for(Acocunt account : accounts )
            {   
                accMap.put(account .Id,account .Name);
                options.add(new SelectOption(account .Id,account .Name));
            }
         return options;           
}


Thanks in anticipation of your response.

Thanks and regards
Pallav
  • March 10, 2008
  • Like
  • 0
Hi All,

I am writting a unit testing method for my apex trigger and when running the following piece of code in the apex class I get the error message INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY while creating the "OpportunityLineItemSchedule". I have tried putting the "OpportunityLineItemId" hard coded then also it is showing the same error message. I cannot re move this as this is a required field.

public class testCodeCoverage
{
    static testMethod void myTest()
    {
        OpportunityLineItem acccobj = new OpportunityLineItem(OpportunityId = 'AAAAAAAAAA', Description='This is a test descriptiion',Quantity=3,UnitPrice=5000,PricebookEntryId='11111');
        insert acccobj;
        OpportunityLineItemSchedule acccobj1 = new OpportunityLineItemSchedule(OpportunityLineItemId=acccobj.Id,Description='This is a test description',Revenue=10000,ScheduleDate=Date.newInstance(2008,02,02),Quantity=2,Type='both');
        insert acccobj1;
    }
}

Thanks in anticipation of your kind and helpful response.

thanks and regards
pallav
  • February 05, 2008
  • Like
  • 0
Hi all,

I have created a trigger whose code is  running fine  on the dev instance but when I tried to deploy in the production instace the deployment failed and gives me a error message as given below, on the third step of deployment using the Eclips deployment wizard. while validating the trigger.

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required.

Test coverage of selected Apex Class and Trigger is 0%, at least 75% test coverage is required.

here is the code for the trigger:-
trigger trytrigger on OpportunityLineItem (after insert)
{
  if(trigger.isAfter)
   {
     if (trigger.isInsert)
      {
       for (OpportunityLineItem c :trigger.new)
        {
          Date strDate;
          Integer intDayTotal;
          Integer intMonth;
          OpportunityLineItemSchedule [] OLI = [Select Id, ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId=:c.Id order by ScheduleDate];
          OpportunityLineItem opp = new OpportunityLineItem(Id=c.Id);
          for(OpportunityLineItemSchedule o:OLI)
           {
               strDate=o.ScheduleDate;
               Integer strMonth=strDate.month();
               Integer intDay=strDate.day();
               if(strMonth==1 || strMonth==3 || strMonth==5 || strMonth==7  || strMonth== 8 || strMonth==10 || strMonth==12)
               {
                   intDayTotal=31;
                   intDayTotal=intDayTotal-intDay;
               }
               else if(strMonth==4 || strMonth==6 || strMonth==9 || strMonth==11)
               {
                   intDayTotal=30;
                   intDayTotal=intDayTotal-intDay;
               }
               else if(strMonth==2)
               {
                   intDayTotal=28;
                   intDayTotal=intDayTotal-intDay;
               }
               strDate=strDate.addDays(intDayTotal);
               opp.Test_Field__c=strDate;
           }
           update opp;
        }
      }
   }
}

Please let me know what I am doing wrong??
Thanks in anticipation of your reponse.

thanks and regards
pallav

  • January 31, 2008
  • Like
  • 0
Hi,

I have a issue with my code for the delete trigger. I have a custom field in the Product2 as Welcome_field__c and same is there in the opportunity page. The logic is when some one adds a product with that field name cheked and if the field in the opportunity is not checked then it should get updated with the checked value(minimum of one such product in needed to update the welcome_field__c in opportunity) and when deleted it should check for the remaining items that are there in the opportunityLineItem and if there is at least on of the product with the welcome_field__c, check is there then it should keep the field in the opportunity checed. else it should unchek it.
here is the code:-

if(trigger.isBefore)
  {
  if(trigger.isDelete)
    {
      try{
        OpportunityLineItem [] OpIds = [Select OpportunityId from OpportunityLineItem where Id In : trigger.old];
        List<Id> options= new List<Id>();
        for(OpportunityLineItem i: OpIds)
         {
           options.add(i.OpportunityId);
         }

       OpportunityLineItem [] oppIds = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId In: options];

        List<Id> opt= new List<Id>();
        for(OpportunityLineItem p: oppIds)
         {
           opt.add(p.Id);
         }
       for (OpportunityLineItem c :oppIds)
    {
         OpportunityLineItem [] OLI = [Select PricebookEntry.Product2Id from OpportunityLineItem where Id in : opt];
         Set<Id> Product2Ids = new Set<Id>();
         for(OpportunityLineItem o:OLI)
         {
           Product2Ids.add(o.PricebookEntry.Product2Id);
         }
        
         Product2 [] P2 = [Select Welcome_Program__c from Product2 where Id in :Product2Ids];
          Opportunity opp=new Opportunity(Id=c.OpportunityId);
          for(Product2 pro2: P2)
          {
           if(pro2.Welcome_Program__c==true)
            {
               opp.Welcome_Program__c=true;
               break;
            }
           else
            {
               opp.Welcome_Program__c=false;
            }
          }
          update opp;
         }        
       }

      catch(System.DmlException e)
      {
      System.assert(e.getDmlMessage(0).indexOf('Cannot Update opportunity') > -1);
      }
    }
  }
}

the issue that I am facing is that.. when i put the piece of code in the aftre delete trigger then it does not get the id of the opportunityLineItem and so the code does nothing and no records are fatched. when I put the code in the before delete trigger then it fatched the old data. For example if I have 3 opportunityLineItem and one of them is having the welcome_field__c as checked. then if I delete it it should uncheck the same named field in the opportunity but what it is doing is that is picking up the whole 3 opportunity data items and checks and finds one opportunity data items with welcome_field__c as checked and does nothing and then deltes the item. and in the second run if i delete the one that is not with the welcome_field__c as checked then it updates the welcome_field__c field in the opportunity.
the refection of result is one step late.

How to get the issue resolved.

Thanks in anticipation of your result.

reagards
Pallav
  • January 24, 2008
  • Like
  • 0
Hi All,

I am facing a issue with the my apex code trigger. I have the following queries:
 it is giving me some invalid data binding error message.

1: - Compile Error: Incompatible element type Id for collection of SOBJECT:OpportunityLineItem at line 11 column 12 ------that means   // options.add(i.OpportunityId); line.

2:- Compile Error: Invalid bind expression type of SOBJECT:OpportunityLineItem does not match domain of foreign key at line 15 column 116 ------ that means
OpportunityLineItem [] oppIds = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId In : options ];


here is the complete code of it......


if(trigger.isAfter)
 {
   if((trigger.isInsert)||(trigger.isUpdate))
   {
   try{
        OpportunityLineItem [] OpIds = [Select OpportunityId from OpportunityLineItem where Id In : trigger.new];
       
        List<OpportunityLineItem> options= new List<OpportunityLineItem>();
        for(OpportunityLineItem i: OpIds)
         {
           // options.add(i.OpportunityId);
         }


       OpportunityLineItem [] oppIds = [Select Id, OpportunityId from OpportunityLineItem where OpportunityId In : options ];// opportunity id bind exception

       for (OpportunityLineItem c :oppIds)
    {
         OpportunityLineItem [] OLI = [Select PricebookEntry.Product2Id from OpportunityLineItem where Id=: c.Id];
         Set<Id> Product2Ids = new Set<Id>();
         for(OpportunityLineItem o:OLI)
         {
           Product2Ids.add(o.PricebookEntry.Product2Id);
         }
         
         Product2 [] P2 = [Select Welcome_Program__c from Product2 where Id in :Product2Ids];
          for(Product2 pro2: P2)
          {
           if(pro2.Welcome_Program__c==true)
            {
               Opportunity opp=new Opportunity(Id=c.Id);
               opp.Welcome_Program__c=true;
               update opp;
            }
          }
         }         
       }

      catch(System.DmlException e)
      {
      System.assert(e.getDmlMessage(0).indexOf('Cannot Update opportunity') > -1);
      }
    }
   }


Your little help can solve my issue.

Thanks in anticipation of your response.

thanks and regards
Pallav
  • January 23, 2008
  • Like
  • 0
Hi All,

I would like to implement a paging sceam in datatable. from the VF developer guid I can see that we can only limit the number of records using the "ROW" attribute of the datatable but how can I display the next page or the previous page of data..

Thanks in anticipation of your humble response.

Thanks and regards
pallav
  • January 14, 2008
  • Like
  • 0
Hi,

I am having issue firing nested query :

Select p.Description, p.Family, p.Name from Product2 p  where id In (Select Product2Id from PricebookEntry where Pricebook2Id='01s60000000A7h5AAC')

if I provide with a ":" after In then it shows invalid token and if I do not provide it gives me a error message unexpected token "select". Please show me some light on this..

thanks in anticipation of your response and help.

regards
pallav
  • January 09, 2008
  • Like
  • 0
Greetings!!

I want to ask you two  questions:-

1. Is there any way in VF, where we can select a value from a "Selectlist" and upon selection of the that value the page will refresh and associated fields, or you can say details will be displayed.

2. with your help i have made the check box to appear inside the datalist but the header thing is not comming over there, how can I do that.

Thanks in anticipatino of your kind resolution to my issue.

regards
Pallav
  • January 04, 2008
  • Like
  • 0
I want to show the data that is being the result of query in to salesforce, in a grid and there has to be a check box along with each record displyed. I any one has any knowledge or have worked on this before, please share their knowledge.

Thanks in anticipation of your valuable response.
  • January 03, 2008
  • Like
  • 0
Hi,

I am having a issue opening the attachments that are there in the SFDC. I have a custom .NET application that use SFDC API to retrive the names of the attached files that are there under a object. I have queried and retrive the name of the attachment and now I want to click on the name of the attachment and it should open that file. I also have created the link to open the file... but when ever I click on the link it will open up a new window, which is as expected.. but it asked me to log in also....  that is the main issue... can any one tell me how to resolve this .. is there any way that while opening up the attachment it should not ask me to log in...


Note:- All the attached docs will be public and will be of type PDF, DOC and Excel or a TXT.


Thanks in advance for your help...

Pallav
  • November 14, 2007
  • Like
  • 1
Hi,

I am having a issue opening the attachments that are there in the SFDC. I have a custom .NET application that use SFDC API to retrive the names of the attached files that are there under a object. I have queried and retrive the name of the attachment and now I want to click on the name of the attachment and it should open that file. I also have created the link to open the file... but when ever I click on the link it will open up a new window, which is as expected.. but it asked me to log in also....  that is the main issue... can any one tell me how to resolve this .. is there any way that while opening up the attachment it should not ask me to log in...


Note:- All the attached docs will be public and will be of type PDF, DOC and Excel or a TXT.


Thanks in advance for your help...

Pallav
  • November 14, 2007
  • Like
  • 1
Do you know what "too many apex requests" exception mean? I'm getting this message randomly. Has it something to do with the Callouts Limit?
Hi..
 
        I have write one trigger for custom object Project__c. When I update Savings__c field that value is added into another custom object field Work__c.Overall_Savings__c..
 
       I want to know fetch before update value and after update value..
That is
      
             before update Savings__c =5
             After update I have changed into 10
            means  how can I fetch 5 and 10..
 
because before update  overall_savings__c =50
               After update Overall_Savings__c =55
That is I have to add just difference value to Work__c object field Overall_Savings__c...
 
Any one have a sample code please post me
 
 
     
         
Hi All,
I am facing issue with trigger that I have to develop.

Problem: A newly created record inserts the current user id and username in the owner id and owner name fields natively on save.


Wanted: Apex trigger to keep the current owner id/name the same as existing owner id/name on saving of the record if it does not match the current userId or createdbyId.


Use Case:

1. Open record
2. Change record owner to someone else
3. Save record
4. Clone record

5. Save new record (with the same owner as original pre-cloned record)
6. The new cloned case should still be owned by the previous owner.

Notes: Standard clone code will show the original owner on the owner field. The new record gets updated to the userId/Name on Save.

Thanks in anticipation of your response.
Pallav
Hi All,
 I am facing a issue with the trigger that I have developed.

When ever any new record is inserted then after the insert a custom field get updated. The update section of the trigger get fired up where I have written the code for before upate. Here, the fields does not reflect the value automatically. for ever record after insert I have to manually go and click edit and save to reflect the value.

Below given is the piece of code for the trigger. Please let me know what I am doing wrong with it.

trigger LeadTrigger on Lead (before update, after insert)
{
    List<Id> OwnerIds = new List<Id>();
    for (Integer i = 0; i < Trigger.new.size(); i++)
    {
           OwnerIds.add(trigger.new[i].OwnerId);
    }
   
    Map <Id, Id> contactAcc = new Map <Id, Id>();
    for (User u : [Select Id, Contact.AccountId From User where ContactId  != null and UserType = 'PowerPartner' and Id in : OwnerIds])
    {
        contactAcc.put(u.Id, u.Contact.AccountId);
    }
   
    Map <Id, Id> CAMs = new Map <Id, Id>();
    for (Account  acc: [Select Id,  OwnerId From Account where Id in : contactAcc.values()])
    {
        CAMs.put(acc.Id, acc.OwnerId);
    }

    Map<Id, User> userRecords =  new Map<Id, User>([Select Id, UserType from User where Id In : OwnerIds]);
    if(trigger.isBefore && trigger.isUpdate)
    {
        try
        {
            for(Lead l : trigger.new)
            {
                for (Integer j = 0; j < Trigger.new.size(); j++)
                {
                    if(userRecords.get(l.OwnerId).UserType!=null && userRecords.get(l.OwnerId).UserType=='PowerPartner')
                    {
                        l.CAM__c=CAMs.get(contactAcc.get(trigger.new[j].OwnerId));
                    }
                    else
                    {
                        l.CAM__c= null;
                    }
                }
            }
        }
        catch(Exception e)
        {}
    }
    if(trigger.isAfter && trigger.isInsert)
    {
        List<Lead> savedLeads = new List<Lead>();
        try
        {
            for(Lead l : trigger.new)
            {
                for (Integer j = 0; j < Trigger.new.size(); j++)
                {
                    if(userRecords.get(l.OwnerId).UserType=='PowerPartner')
                    {
                        Lead newLead = new Lead(Id=l.Id, CAM__c=CAMs.get(contactAcc.get(trigger.new[j].OwnerId)));
                        //l.CAM__c=CAMs.get(contactAcc.get(trigger.new[j].OwnerId));
                        savedLeads.add(newLead);
                    }
                }
            }
            update savedLeads;
        }
        catch(Exception e)
        {}
    }
}


Hoping for a quick and positive response from you guys and thanks in anticipation of your answer.

Thanks and regards
Pallav
I did a trigger on enterprise version sf with eclipse. which can't edit trigger on sfdc.
I can upload this trigger from eclipse to sfdc. but I can't upload the active config. I config the trigger.xml to <active>true<active> and upload it. but it doesn't work. In server the trigger is still deactive.
How can I active the trigger?
  • March 18, 2008
  • Like
  • 0
I am trying to get the value from the Pick List  " Account Rating " in my VisualForce custom Application data like "HOT,WARM,COLD ".

I have made the Custom Controller through which I am trying to add new Account 's .

Now I want to Add new field in my Application that is Account Rating Pick List .
trigger doJobPostingText on Requisition__c (before insert)
{
String str1=SELECT Id from Job_Category__c;
String str2=SELECT Job_Category__c from Requisition__c;
for (Requisition a : Trigger.new)
{
if((str1)==(str2))
{
insert a;
}
else
{
a.AddError('The Discipline should Be selected According to Job Category');
}
}
}
Hi All,

I am writting a unit testing method for my apex trigger and when running the following piece of code in the apex class I get the error message INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY while creating the "OpportunityLineItemSchedule". I have tried putting the "OpportunityLineItemId" hard coded then also it is showing the same error message. I cannot re move this as this is a required field.

public class testCodeCoverage
{
    static testMethod void myTest()
    {
        OpportunityLineItem acccobj = new OpportunityLineItem(OpportunityId = 'AAAAAAAAAA', Description='This is a test descriptiion',Quantity=3,UnitPrice=5000,PricebookEntryId='11111');
        insert acccobj;
        OpportunityLineItemSchedule acccobj1 = new OpportunityLineItemSchedule(OpportunityLineItemId=acccobj.Id,Description='This is a test description',Revenue=10000,ScheduleDate=Date.newInstance(2008,02,02),Quantity=2,Type='both');
        insert acccobj1;
    }
}

Thanks in anticipation of your kind and helpful response.

thanks and regards
pallav
  • February 05, 2008
  • Like
  • 0
Hi all,

I have created a trigger whose code is  running fine  on the dev instance but when I tried to deploy in the production instace the deployment failed and gives me a error message as given below, on the third step of deployment using the Eclips deployment wizard. while validating the trigger.

Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required.

Test coverage of selected Apex Class and Trigger is 0%, at least 75% test coverage is required.

here is the code for the trigger:-
trigger trytrigger on OpportunityLineItem (after insert)
{
  if(trigger.isAfter)
   {
     if (trigger.isInsert)
      {
       for (OpportunityLineItem c :trigger.new)
        {
          Date strDate;
          Integer intDayTotal;
          Integer intMonth;
          OpportunityLineItemSchedule [] OLI = [Select Id, ScheduleDate from OpportunityLineItemSchedule where OpportunityLineItemId=:c.Id order by ScheduleDate];
          OpportunityLineItem opp = new OpportunityLineItem(Id=c.Id);
          for(OpportunityLineItemSchedule o:OLI)
           {
               strDate=o.ScheduleDate;
               Integer strMonth=strDate.month();
               Integer intDay=strDate.day();
               if(strMonth==1 || strMonth==3 || strMonth==5 || strMonth==7  || strMonth== 8 || strMonth==10 || strMonth==12)
               {
                   intDayTotal=31;
                   intDayTotal=intDayTotal-intDay;
               }
               else if(strMonth==4 || strMonth==6 || strMonth==9 || strMonth==11)
               {
                   intDayTotal=30;
                   intDayTotal=intDayTotal-intDay;
               }
               else if(strMonth==2)
               {
                   intDayTotal=28;
                   intDayTotal=intDayTotal-intDay;
               }
               strDate=strDate.addDays(intDayTotal);
               opp.Test_Field__c=strDate;
           }
           update opp;
        }
      }
   }
}

Please let me know what I am doing wrong??
Thanks in anticipation of your reponse.

thanks and regards
pallav

  • January 31, 2008
  • Like
  • 0
Hi,
 
I am trying to get dabatable with a column with checkboxes which should decide which row to pick from the data table; but I am always running in problems, because the checkboxes are created for each row, so i couldnt manage to get the value of  the checkbox which is selected:
 

<apex:dataTable value="{!ent}" var="contact" cellPadding="4" border="1" align="center">

<apex:column>

<apex:selectRadio value="{!which}">

<apex:facet name="header">Ent_ID</apex:facet>

<apex:selectOption itemValue="{!contact.name}">{!contact.name}</apex:selectOption>

</apex:selectRadio>

</apex:column>

 

Is there a way to create one checkbox in a column. If I put the the selectRadio tags out of the column tags nothing is displayed in the column.

 

Thanks in advance.

  • January 07, 2008
  • Like
  • 0
Greetings!!

I want to ask you two  questions:-

1. Is there any way in VF, where we can select a value from a "Selectlist" and upon selection of the that value the page will refresh and associated fields, or you can say details will be displayed.

2. with your help i have made the check box to appear inside the datalist but the header thing is not comming over there, how can I do that.

Thanks in anticipatino of your kind resolution to my issue.

regards
Pallav
  • January 04, 2008
  • Like
  • 0