• randombard
  • NEWBIE
  • 50 Points
  • Member since 2010

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 26
    Replies

Hi All,

 

Trying to get this but cant seem to work it out.

 

I assume I need to create an sObject list and then test that the keyprefix is the same as the start of the parentID.

 

But I have to be honest I have no idea how to go about that one.

 

Or am I well off base?

 

R

Hi All,

 

how would I multiply the unitprice on an opportuniy line item by another field value.

 

   IF(PE.Product2Id == OL.PricebookEntry.Product2Id){
        NOL = New OpportunityLineItem();
            NOL.Opportunityid = op.id;
            NOL.PricebookEntryId = PE.id;
            NOL.Quantity = OL.Quantity;
            NOL.UnitPrice = OL.UnitPrice * IncPer;
            NLI.add(NOL);
        }
    }

 I get

 

Error: Arithmetic expressions must use numeric arguments

 


Is this because Incper is:

 

 String IncPer = '1.' + o.account.Agreed_price_Increase__c;

 In this example IncPer returns 1.10

 

R

 

Hi All,

 

So here is what I am trying to do..

 

I want to create a list of all opportunity line items that are in next years price book keep the salesprice from the previose year and add them to a new opportunity.

 

creating the opp shouldnt be a problem but I am having trouble getting my head arround bilding the list of products to add to the new opp, I have as follows.

 

trigger RenewOp on Opportunity (before update) {
for(opportunity o: trigger.new){
IF(o.iswon==true && o.Renew_With_what_year_pricebook__c !=null){
       String opptyId = o.Id;
       String PBName = o.Renew_With_what_year_pricebook__c + ' ' + o.PricebookName__c.abbreviate(0,5);      
List<OpportunityLineItem> OLI = [Select UnitPrice, Quantity, ServiceDate, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c
From OpportunityLineItem 
where OpportunityId = :opptyId];
List <PricebookEntry> PBE =[Select ID, Product2Id, PricebookEntry.Pricebook2.Name 
FROM PricebookEntry 
Where PricebookEntry.Pricebook2.Name =:PBName and Product2Id in :OLI.PricebookEntry.Product2Id];
}
}
}

 but get the following error:

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<OpportunityLineItem> at line 11 column 66

 

Any pointers greatfully apreciate.

R

 

Hi All,

 


Trying to work out how to achieve this, so far I have the following but nothing appears to happen.

 

please note where is states emailfgoeshere I usually place an email address, just not in this example.  :-)

 

trigger IncludeTechnicalSuppoer on FeedItem (before insert) {
String oppKeyPrefix = Opportunity.sObjectType.getDescribe().getKeyPrefix();
    for (FeedItem f: trigger.new)
     {
         String parentId = f.parentId;
          //We compare the start of the 'parentID' field to the Opportunity key prefix to
          //restrict the trigger to act on posts made to the Opportunity object.
          if (parentId.startsWith(oppKeyPrefix) &&
              f.Body == '#Tech')
          {           
                //Send message to technical support
               String[] toaddress = new String[]{};
                toaddress.add('emailgoeshere');
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setToAddresses(toaddress);
                mail.setsubject('TechnicalMessage');
                mail.saveAsActivity = false;
              
          }
      }
  }

 First question what do I need to do to make this actually send and second question should I really be using a template to send richer content?

 

Thanks

 

R

Hi All getting this error:

 

tom_test_error_conditions.test_package_error_conditions()Class111

 

Failure Message: "System.QueryException: List has more than 1 row for assignment to SObject", Failure Stack Trace: "Class.tom_test_error_conditions.test_package_error_conditions: line 11, column 1"

 

Now there is only one queue that matches these criteria, but it does relate to multiple objects.

 

the line of code is.

 

  Group payroll_queue = [select Id, Name from Group where (Name = 'Time_Off_Manager_Payroll') and (Type = 'Queue')];

 

Any help greatly apreciated.

 

R

Hi All,

 

Is there any way to render as PDF but with no page breaks, its only supposed to be used on screen and not printed out.

 

R

Hi All,

 

when an opportunity is closed won I want to insert on the account multiple records based on the number selected from a dropdown,

 

IE. Opp1 closed won Multi Select = 15

15 Account suport token records inserted on the account record.

 

the account tokens have auto number for the name. in the past I would have used do until and then just counted down until the insert = 0 but I expect that there is a better way to do this with apex.

 

Thanks in advance.

R

 

HI All,

 

I have had a search arround but coulnt find anything.

 

I want to test if a field was previosly blank and now is not then if its not blank execute code. i have everything for if its not blank but i cant work out out to test if it was previosly blank.

 

do I need to make use of trigger.old?

 

Thanks

R

Hi All,

 

I have the following that works perfectly however I have noticed that anything more then 365 das old doesnt get re-arented.

 

I assume this is due to it being archived in some way?

 

I can re-parent manualy so they dont become read only, is it just that they cant be re-parrented programaticly when they are that old?

 

Code:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
trigger MigrateRelatedOb on lead (After insert, After update) 
{
for(lead L: trigger.new)
if((L.Old_Contact_ID__c<>''))
{
//move tasks
For(Contact C:[select id from Contact where Contact.ID = :L.Old_Contact_ID__c])
    {
    List<Task> TaskToMove = new List<Task>();
    {For(Task T:[select id, WhoID, WhatID from Task where WhoID = :C.Id])
    {
    T.WhoID = L.Id;
    T.WhatID=null;
    TaskToMove.add(T);
    }
Update TaskToMove;
     System.debug('Success');
}
{
//move events
List<Event> EventToMove = new List <Event>();
{For(Event E:[select id, WhoID, WhatID from Event where WhoID = :C.Id])
    {
    E.WhoID = L.Id;
    E.whatID=null;
    EventToMove.add(E);
    }
Update EventToMove;
     System.debug('Success');
}
}
//delete The contact
delete C;
}
}
else
{
System.debug('No Lead Found');
}
}

Hi All,

 

trying to re-parent all activityhisory on a contact to a lead, I have this working for all open tasks and events but not for activity history.

 

I was hoping to use something as follows but its clearly not right.

 

{
//move Taskhistory
List<Task> TaskHistory = new List <Task>();
{For(Task TH:[select (SELECT id, WhoID from ActivityHistories) FROM CONTACT where ID = :C.Id])
    {
    TH.WhoID = L.Id;
    TaskHistory.add(TH);
    }
Update TaskHistory;
     System.debug('Success');
}
}

 

This is my first try at this after taks I want to move all historic events as well.

 

Any help greatly apreciated.

Hi All,

 

My apologies for not learning more I am gradually learning Apex but I have hit an error and I am hoping its something simpler then I think it seems to be saying.

 

I am getting the following error:

 

Error: Compile Error: Invalid initial expression type for field Account, expecting: SOBJECT:Account (or single row query result of that type) at line 20 column 11

 

Code

 

@isTest
Public class TestMigrateRelatedOb{
static testMethod void myPage_Test()
{

//Test converage for the myPage visualforce page

Account newAccount = new Account (name='XYZ Organization',
BillingCity ='TestCity',
BillingCountry ='TestCountry',
BillingStreet ='TestStreet',
BillingPostalCode ='t3stcd3'
);

insert newAccount;

Contact NewContact = new Contact (
FirstName = 'xyzFirst',
LastName = 'XyZLast',
Account = newAccount.id,
Email = 'xyzmail@mail.com'
);

Insert NewContact;

Task NewTask = new Task (Who = NewContact.id,
Subject = 'TestTask',
ActivityDate = date.today()
);

Insert NewTask;

Event NewEvent = new Event (Who = NewContact.id,
Subject = 'TestEvemt',
ActivityDate = date.today()
);

Insert NewEvent;

Lead NewLead = new Lead (Company = 'XYZ Organization',
FirstName = 'xyzFirst',
LastName = 'XyZLast',
Email = 'xyzmail@mail.com',
Old_Contact_ID__c = NewContact.ID
);

Insert NewLead;
}
}

 

 

Now I am hoping that the error doeans meen I have to do and SOQL query to get the ID of the new account when inserting the new contact for the test.

 

Thanks for any help.

 

R

For some reason this works fine when i replace the :C.ID with a hard coded ID.

 

I have used this method before but not with .old so I am wondering if that changes something.

 

trigger MigrateRelatedObjects on Contact (before delete)
{
for(Contact C: trigger.old)
if([select id from Lead where Old_Contact_ID__c = :C.Id].size() > 0 )
{
For(Lead L:[select id from Lead where Old_Contact_ID__c = :C.Id])
    {List<Task> TaskToMove = new List<Task>();
    {For(Task T:[select id, WhoID from Task where WhoID = :C.Id])
    {
    T.WhoID = L.Id;
    TaskToMove.add(T);
    }
Update TaskToMove;
     System.debug('Success');
}
}
}
else
{
System.debug('No Lead Found');
}
}

specificaly I am getting this erroe for line 3 column 1

 

Please note this is all a work in progress I am trying to move all of the related records to a lead that was created via a custom button thought I would start with the tasks.

 

trigger MigrateRelatedObjects on Contact (before delete)
{
for(Contact C: trigger.new)
if([select id from Lead where Old_Contact_ID__c = :C.id].size() > 0 )
{
For(Lead L:[select id from Lead where Old_Contact_ID__c = :C.id])
    {List<Task> TaskToMove = new List<Task>();
    {For(Task T:[select id, WhoID from Task where WhoID =:C.id])
    {
    T.WhoID = L.id;
    TaskToMove.add(T);
    }

{
}
}
}
}
}

Hi All,

 

Little stuck on this one in the following code how do I first add another variable to the SOQL to only include Tasks with the Subject Line 'Opportunity Past Close Date' and then go through the list as a for each loop closing them.

 

The code I have right now will just close one and I can tell that's because of the line

 

TasksToClose[0].Status = 'Completed';}

 

But I can't work out how to make that an integer

 

trigger Close_Tasks on Opportunity (after insert, after update) 
{
for(Opportunity o: trigger.new)
{
    If((o.stagename=='Closed Won'))
        {List<Task> TasksToClose = new List<Task>();
        {TasksToClose = [select Id,WhatID,Status from Task where WhatID=:o.Id]; TasksToClose[0].Status = 'Completed';}
        update  TasksToClose;
        }
    else
{
}
}
}

 

Thanks

R

 

Hi All,

 

When trying to put together a roll up summary for the list price of all products on an opportunity it always returns a blank value.

 

I have checked and the list price is there, on the product record as well as showing as a summable field.

 

What have I missed.

 

R

Hi All,

 

I am very sorry if I have posted this in the wrong place but this seems to be the best pace to ask.

 

Is it possible to show the assets from the related account (master detail) on the custom object.

 

I dont want to create a joining object or do a many to many so a visual force page seems to be the best option but I just cant work out how to get to what I want.

 

R

Hi All,

 

I want to update the "Type" of task that has been created by a workflow.

 

I know workflows cant trigger other workflows and for some reason when creating workflows to create a task you cant use the "Type" field.

 

I assume I am going to have to write some kind of trigger?

 

Any help would be really apreciated, thanks.

R

I want to test if a field that contains the ip adress range of our customer is acceptable

 

I thought

 

OR(NOT(isnull(FIND(10.*.*.*, IP_Address__c))),NOT(isnull(FIND(192.168.*.*, IP_Address__c))))

 

however the * is used for multiply and wrapping in " doesnt help

Hi All,

 

So here is what I am trying to do..

 

I want to create a list of all opportunity line items that are in next years price book keep the salesprice from the previose year and add them to a new opportunity.

 

creating the opp shouldnt be a problem but I am having trouble getting my head arround bilding the list of products to add to the new opp, I have as follows.

 

trigger RenewOp on Opportunity (before update) {
for(opportunity o: trigger.new){
IF(o.iswon==true && o.Renew_With_what_year_pricebook__c !=null){
       String opptyId = o.Id;
       String PBName = o.Renew_With_what_year_pricebook__c + ' ' + o.PricebookName__c.abbreviate(0,5);      
List<OpportunityLineItem> OLI = [Select UnitPrice, Quantity, ServiceDate, PricebookEntry.Product2Id, PricebookEntry.Product2.Name, Description, Converted_to_Asset__c
From OpportunityLineItem 
where OpportunityId = :opptyId];
List <PricebookEntry> PBE =[Select ID, Product2Id, PricebookEntry.Pricebook2.Name 
FROM PricebookEntry 
Where PricebookEntry.Pricebook2.Name =:PBName and Product2Id in :OLI.PricebookEntry.Product2Id];
}
}
}

 but get the following error:

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<OpportunityLineItem> at line 11 column 66

 

Any pointers greatfully apreciate.

R

 

Hi All,

 


Trying to work out how to achieve this, so far I have the following but nothing appears to happen.

 

please note where is states emailfgoeshere I usually place an email address, just not in this example.  :-)

 

trigger IncludeTechnicalSuppoer on FeedItem (before insert) {
String oppKeyPrefix = Opportunity.sObjectType.getDescribe().getKeyPrefix();
    for (FeedItem f: trigger.new)
     {
         String parentId = f.parentId;
          //We compare the start of the 'parentID' field to the Opportunity key prefix to
          //restrict the trigger to act on posts made to the Opportunity object.
          if (parentId.startsWith(oppKeyPrefix) &&
              f.Body == '#Tech')
          {           
                //Send message to technical support
               String[] toaddress = new String[]{};
                toaddress.add('emailgoeshere');
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                mail.setToAddresses(toaddress);
                mail.setsubject('TechnicalMessage');
                mail.saveAsActivity = false;
              
          }
      }
  }

 First question what do I need to do to make this actually send and second question should I really be using a template to send richer content?

 

Thanks

 

R

Hi All,

 

when an opportunity is closed won I want to insert on the account multiple records based on the number selected from a dropdown,

 

IE. Opp1 closed won Multi Select = 15

15 Account suport token records inserted on the account record.

 

the account tokens have auto number for the name. in the past I would have used do until and then just counted down until the insert = 0 but I expect that there is a better way to do this with apex.

 

Thanks in advance.

R

 

HI All,

 

I have had a search arround but coulnt find anything.

 

I want to test if a field was previosly blank and now is not then if its not blank execute code. i have everything for if its not blank but i cant work out out to test if it was previosly blank.

 

do I need to make use of trigger.old?

 

Thanks

R

Hi All,

 

trying to re-parent all activityhisory on a contact to a lead, I have this working for all open tasks and events but not for activity history.

 

I was hoping to use something as follows but its clearly not right.

 

{
//move Taskhistory
List<Task> TaskHistory = new List <Task>();
{For(Task TH:[select (SELECT id, WhoID from ActivityHistories) FROM CONTACT where ID = :C.Id])
    {
    TH.WhoID = L.Id;
    TaskHistory.add(TH);
    }
Update TaskHistory;
     System.debug('Success');
}
}

 

This is my first try at this after taks I want to move all historic events as well.

 

Any help greatly apreciated.

Hi All,

 

My apologies for not learning more I am gradually learning Apex but I have hit an error and I am hoping its something simpler then I think it seems to be saying.

 

I am getting the following error:

 

Error: Compile Error: Invalid initial expression type for field Account, expecting: SOBJECT:Account (or single row query result of that type) at line 20 column 11

 

Code

 

@isTest
Public class TestMigrateRelatedOb{
static testMethod void myPage_Test()
{

//Test converage for the myPage visualforce page

Account newAccount = new Account (name='XYZ Organization',
BillingCity ='TestCity',
BillingCountry ='TestCountry',
BillingStreet ='TestStreet',
BillingPostalCode ='t3stcd3'
);

insert newAccount;

Contact NewContact = new Contact (
FirstName = 'xyzFirst',
LastName = 'XyZLast',
Account = newAccount.id,
Email = 'xyzmail@mail.com'
);

Insert NewContact;

Task NewTask = new Task (Who = NewContact.id,
Subject = 'TestTask',
ActivityDate = date.today()
);

Insert NewTask;

Event NewEvent = new Event (Who = NewContact.id,
Subject = 'TestEvemt',
ActivityDate = date.today()
);

Insert NewEvent;

Lead NewLead = new Lead (Company = 'XYZ Organization',
FirstName = 'xyzFirst',
LastName = 'XyZLast',
Email = 'xyzmail@mail.com',
Old_Contact_ID__c = NewContact.ID
);

Insert NewLead;
}
}

 

 

Now I am hoping that the error doeans meen I have to do and SOQL query to get the ID of the new account when inserting the new contact for the test.

 

Thanks for any help.

 

R

For some reason this works fine when i replace the :C.ID with a hard coded ID.

 

I have used this method before but not with .old so I am wondering if that changes something.

 

trigger MigrateRelatedObjects on Contact (before delete)
{
for(Contact C: trigger.old)
if([select id from Lead where Old_Contact_ID__c = :C.Id].size() > 0 )
{
For(Lead L:[select id from Lead where Old_Contact_ID__c = :C.Id])
    {List<Task> TaskToMove = new List<Task>();
    {For(Task T:[select id, WhoID from Task where WhoID = :C.Id])
    {
    T.WhoID = L.Id;
    TaskToMove.add(T);
    }
Update TaskToMove;
     System.debug('Success');
}
}
}
else
{
System.debug('No Lead Found');
}
}

specificaly I am getting this erroe for line 3 column 1

 

Please note this is all a work in progress I am trying to move all of the related records to a lead that was created via a custom button thought I would start with the tasks.

 

trigger MigrateRelatedObjects on Contact (before delete)
{
for(Contact C: trigger.new)
if([select id from Lead where Old_Contact_ID__c = :C.id].size() > 0 )
{
For(Lead L:[select id from Lead where Old_Contact_ID__c = :C.id])
    {List<Task> TaskToMove = new List<Task>();
    {For(Task T:[select id, WhoID from Task where WhoID =:C.id])
    {
    T.WhoID = L.id;
    TaskToMove.add(T);
    }

{
}
}
}
}
}

Hi,

I have an MS Accesss program that we have used for months now, with no problem, whish connects to Salesforce and pulls data to our application. However, now I am geting the following error:

SFWinTnet::

Send Win32Error::

A connection with the server could not be established

 

I am using the SF_MSApi4.dll in my application.

I tryed this on a couple of applications and I get the same thing.

I have hard other people ar having the samething but have not hard of a solution.

Can anyone give an idea of what I can do here? 

Thank you

itm

  • May 18, 2012
  • Like
  • 0

Hi All,

 

Little stuck on this one in the following code how do I first add another variable to the SOQL to only include Tasks with the Subject Line 'Opportunity Past Close Date' and then go through the list as a for each loop closing them.

 

The code I have right now will just close one and I can tell that's because of the line

 

TasksToClose[0].Status = 'Completed';}

 

But I can't work out how to make that an integer

 

trigger Close_Tasks on Opportunity (after insert, after update) 
{
for(Opportunity o: trigger.new)
{
    If((o.stagename=='Closed Won'))
        {List<Task> TasksToClose = new List<Task>();
        {TasksToClose = [select Id,WhatID,Status from Task where WhatID=:o.Id]; TasksToClose[0].Status = 'Completed';}
        update  TasksToClose;
        }
    else
{
}
}
}

 

Thanks

R

 

Hi All,

 

When trying to put together a roll up summary for the list price of all products on an opportunity it always returns a blank value.

 

I have checked and the list price is there, on the product record as well as showing as a summable field.

 

What have I missed.

 

R

Hi All,

I want three fields should be mendatory once the Stage(picklist) is declined. These three fields are of type Lookup,Text and Number.

Hi All,

 

I am very sorry if I have posted this in the wrong place but this seems to be the best pace to ask.

 

Is it possible to show the assets from the related account (master detail) on the custom object.

 

I dont want to create a joining object or do a many to many so a visual force page seems to be the best option but I just cant work out how to get to what I want.

 

R

when i am deploying i am getting an following error 

 

GoalAssetAssociation__c.Goal__c       Cannot update relationshipOrder

 

GoalAssetAssociation__c.Asset__c Cannot update referenceTo

 

Asset__c.Allocated_Amount__c invalid parameter value

 

here i have a 

custom objects called as Asset__c in which  Allocated_Amount__c Roll-Up Summary (SUM GoalAssetAssociation)

but in GoalAssetAssociation__c i have Asset__c masterdeail-relationship(Asset__c) can u help me out what will be the way to tackel the problem