• Michael_Kahle
  • NEWBIE
  • 100 Points
  • Member since 2009

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 16
    Replies

Hi all:

  Does anyone know how to format a number in Apex so that a number in VF appears correctly...

for example 25000 appears 25,000.00

Anyone have an idea or did this already??

Thanks

Let MMA guide you

hi i am creating "Email" as Custom object. & add to Create a lookup relation for "Email" in contact.Email object have the custom fields of name & email id.if I add one email to the email id equals to contacts then The contact details add to email's releated list.if is not mathes the email id nothing is happen in email - contact related list.If i update that mail id to new one it removes the old contact & update new contact in email related list..I am creating this Trigger but,it show the error in updating time.So How to handle this one for Trigger.new & Trigger.old concept????

 

trigger trg_Lookup_Contact on Email_Suppression__c (after insert,before update)
{
    for(Email_Suppression__c emailobj : Trigger.New)
    {
        contact[] conobj ;
        if(Trigger.Isupdate)
        {
            conobj = [select name,email,Email_Suppression__c from contact where email =: emailobj.EmailId__c OR email =: Trigger.old.EmailId__c];
        }
        else
        {
            conobj = [select name,email,Email_Suppression__c from contact where email =: emailobj.EmailId__c];
        }
        integer inte = conobj.size();
        for(integer i = 0;i < inte;i++)
        {
            if(emailobj.EmailId__c == conobj[i].email)
            {
                conobj[i].Email_Suppression__c = emailobj.id;
                update conobj[i];
            }
            else
            {
                conobj[i].Email_Suppression__c = null;
                update conobj[i];
            }
        }
    }
}

Message Edited by Krishna_ on 04-21-2009 02:59 PM

Hi,
 
I am trying to use the date method to modify a date but am unable to do so. The details are
Position is a custom object 
Opendate is a field with date data type
Count is a field with number date type
Closeddate is a field with date data type
I am trying to calculate the closedate from the Opendate and Count but i am not able to do so. The code is a follows

double c = position.Count__c;date mydate = date.valueof(position.Opendate__c);date newdate = mydate.adddays(c);position.Cdate__c = newdate;

If I replace the variable c with a constant number as 1 or 2, it performs the operation properly. I am unable to pass the value of Count there. How can i get this done.
 
Thanks
KD 

 

  • April 21, 2009
  • Like
  • 0

I have a trigger trying to access the name on the foreign key Contact:

 

 

trigger SAC_updateName on Support_Agreement_Contacts__c (before insert, before update) { for (Support_Agreement_Contacts__c sac:Trigger.new){ Contact[] c = [Select Name from Contact where Id =: sac.Contact_Id__c]; if (c.size() > 0) { sac.Name = c[0].Name; } else { sac.Name = 'John Doe'; } } }

 

Which obviously will generate a "Too many sql queries" on bulk updates, but it is like this because this doesn't work:

 

trigger SAC_updateName on Support_Agreement_Contacts__c (before insert, before update) { for (Support_Agreement_Contacts__c sac:Trigger.new){ if (sac.Contact_Id__c != null) { sac.Name = sac.Contact_Id__c.Name; } else { sac.Name = 'John Doe'; } } }

 

 

 

 

So - obviously, I don't get how this should work at all. I also tried the different __r and whatnots - but I could never get any real reference to the Contact object. Can anyone help a newbie out with this? 

Hi,

 

i'm writing a Visualforce Controller where i need to get the Api Names of the fields of a specific Object, but everything i get is only lower case. I actually need them like they are originally named, because of a WebService Call i'm doing with those field names.

 

Is there any way to get the api names of fields and objects original, and why are they lowercase anyway?

 

Thanks

Michael Kahle

Is this supported?  We're using the Twitter app, and I wrote a schedulable class that calls the AutomationWrapper included in this package to update our conversations every ten minutes.  The code in my class executes on its own as expected, but when it's run via the scheduler, it appears that the HTTP callouts are simply skipped.

 

This is the log.  This code takes an absolute minimum of 2 full seconds to execute when working properly.  When run from the scheduler, its' done in less than 300ms, which leads me to believe that the HTTP callouts are just being skipped.

 

 

18.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;VALIDATION,INFO;WORKFLOW,INFO1:30:0.26|EXECUTION_STARTED1:30:0.26|CODE_UNIT_STARTED|[EXTERNAL]Twitter Synch 41:30:0.41|SOQL_EXECUTE_BEGIN|[4,40]|Aggregations:0|select id from sf4twitter__twitter_account__c where name = 'logmeinhelp' limit 11:30:0.48|SOQL_EXECUTE_END|[4,40]|Rows:1|Duration:71:30:0.49|METHOD_ENTRY|[5,14]|sf4twitter.AutomationWrapper.doSearchAccount(Id, Integer)1:30:0.49|ENTERING_MANAGED_PKG|sf4twitter1:30:0.49|SOQL_EXECUTE_BEGIN|[116,42]|Aggregations:0| Select t.Username__c, t.Unknown_Twitter_Usernames__c, t.Twitter_User_Id__c, t.Twitter_Max_Twitter__c, t.Twitter_Max_Message__c, t.SystemModstamp, t.Password__c, t.OwnerId, t.Name, t.LastModifiedDate, t.LastModifiedById, t.IsDeleted, t.Id, t.Enable_Auto_Case_Creation__c, t.CreatedDate, t.CreatedById, t.Bit_ly_Username__c, t.Bit_ly_Password__c, associate_DM__c , ignore_maxid__c, closed_case_duration__c From Twitter_Account__c t Where Id =:taId 1:30:0.58|SOQL_EXECUTE_END|[116,42]|Rows:1|Duration:91:30:0.59|SOQL_EXECUTE_BEGIN|[27,34]|Aggregations:0|select id, name from Account where name = :Label.TWITTER_ACCOUNT_NAME1:30:0.114|SOQL_EXECUTE_END|[27,34]|Rows:0|Duration:551:30:0.115|SOQL_EXECUTE_BEGIN|[60,21]|Aggregations:0|Select Name, Id, OwnerId, Username__c, Unknown_Twitter_Usernames__c, Password__c, Twitter_Max_Message__c, Enable_Auto_Case_Creation__c, Bit_ly_Username__c, Bit_ly_Password__c, Twitter_Max_Twitter__c, associate_DM__c, associate_cases_same_username__c, closed_case_duration__c From Twitter_Account__c LIMIT 10001:30:0.118|SOQL_EXECUTE_END|[60,21]|Rows:2|Duration:31:30:0.132|SOQL_EXECUTE_BEGIN|[156,17]|Aggregations:0|select id, twitterId__c from Case where twitterId__c in :tids1:30:0.136|SOQL_EXECUTE_END|[156,17]|Rows:0|Duration:41:30:0.139|SOQL_EXECUTE_BEGIN|[399,20]|Aggregations:0|select id, twitter_username__c from Contact where twitter_username__c in :twitterUserNames LIMIT 10001:30:0.142|SOQL_EXECUTE_END|[399,20]|Rows:0|Duration:31:30:0.142|SOQL_EXECUTE_BEGIN|[402,17]|Aggregations:0|select id, twitter_username__c from Lead where IsConverted = false and twitter_username__c in :twitterUserNames LIMIT 10001:30:0.153|SOQL_EXECUTE_END|[402,17]|Rows:0|Duration:111:30:0.153|SOQL_EXECUTE_BEGIN|[361,18]|Aggregations:0|Select Id, twitterID__c, ContactId, Twitter_Username__c from Case where twitterID__c in :twitterIds1:30:0.155|SOQL_EXECUTE_END|[361,18]|Rows:0|Duration:21:30:0.156|SOQL_EXECUTE_BEGIN|[366,40]|Aggregations:0|select Id, Case__c, Case__r.ClosedDate, Case__r.Status, Contact__c, twitterid__c, Parent__c, type__c from Twitter_Conversation__c where twitterid__c in :twitterIds LIMIT 10001:30:0.164|SOQL_EXECUTE_END|[366,40]|Rows:0|Duration:81:30:0.164|SOQL_EXECUTE_BEGIN|[371,40]|Aggregations:0|select Id, Case__c, Case__r.ClosedDate, Case__r.Status, Contact__c, twitterid__c, Parent__c, Content__c, Author_Real_Name__c, Author_Name__c, type__c, In_Reply_To_Status_Id__c, In_Reply_To_User_Id__c from Twitter_Conversation__c where twitterid__c in :twitterReply LIMIT 10001:30:0.168|SOQL_EXECUTE_END|[371,40]|Rows:0|Duration:41:30:0.171|SOQL_EXECUTE_BEGIN|[663,18]|Aggregations:0|select id, twitterId__c, Twitter_Username__c, CreatedDate, ContactId, Contact.Twitter_Username__c from Case where ((Status != :Label.TWITTER_CASE_CLOSED or ClosedDate >= :closeDuration) and Twitter_Username__c IN :fromUsernames) or Id IN :repCasesId order by LastModifiedDate desc LIMIT 10001:30:0.181|SOQL_EXECUTE_END|[663,18]|Rows:0|Duration:101:30:0.181|SOQL_EXECUTE_BEGIN|[677,40]|Aggregations:0|select id, Content__c,Case__c, Parent__c, Author_Name__c from Twitter_Conversation__c where Case__c IN :casesIds LIMIT 10001:30:0.183|SOQL_EXECUTE_END|[677,40]|Rows:0|Duration:21:30:0.183|SOQL_EXECUTE_BEGIN|[705,36]|Aggregations:0|select In_Reply_To_Status_Id__c, id, Case__r.Status, Case__r.twitterId__c, Case__r.Twitter_Username__c, Case__r.CreatedDate, Case__r.ContactId, Author_Name__c from Twitter_Conversation__c where (In_Reply_To_Status_Id__c in :repliedRAStatusTwitterIds) and (Case__r.Status != :Label.TWITTER_CASE_CLOSED or Case__r.ClosedDate >= :closeDuration) order by Case__r.LastModifiedDate desc limit 10001:30:0.187|SOQL_EXECUTE_END|[705,36]|Rows:0|Duration:41:30:0.188|DML_BEGIN|[621,42]|Op:Upsert|Type:Case|Rows:01:30:0.188|DML_END|[621,42]|1:30:0.190|SOQL_EXECUTE_BEGIN|[561,20]|Aggregations:0|select id, twitter_username__c from Contact where twitter_username__c in :twitterUserNames LIMIT 10001:30:0.192|SOQL_EXECUTE_END|[561,20]|Rows:0|Duration:21:30:0.192|DML_BEGIN|[583,42]|Op:Upsert|Type:Case|Rows:01:30:0.193|DML_END|[583,42]|1:30:0.193|SOQL_EXECUTE_BEGIN|[411,42]|Aggregations:0|select TwitterID__c, Twitter_Account__c, Direct_Message__c,type__c from Twitter_Conversation__c where Type__c = :Label.TWITTER_TYPE_REPLIES and Twitter_Account__c in :accounts.keySet() order by TwitterID__c desc limit 11:30:0.201|SOQL_EXECUTE_END|[411,42]|Rows:1|Duration:81:30:0.201|SOQL_EXECUTE_BEGIN|[414,51]|Aggregations:0|select TwitterID__c, Twitter_Account__c, Direct_Message__c,type__c from Twitter_Conversation__c where Type__c = :Label.TWITTER_OUTBOUND_DIRECTMESSAGE and Twitter_Account__c in :accounts.keySet() and Direct_Message__c != null order by TwitterID__c desc limit 11:30:0.205|SOQL_EXECUTE_END|[414,51]|Rows:0|Duration:41:30:0.205|SOQL_EXECUTE_BEGIN|[418,45]|Aggregations:0|select TwitterID__c, Twitter_Account__c, Direct_Message__c,type__c from Twitter_Conversation__c where (Type__c = :Label.TWITTER_TYPE_REGISTERED_ACCOUNT or Type__c = :Label.TWITTER_OUTBOUND_REPLY) and Twitter_Account__c in :accounts.keySet() and Direct_Message__c = null order by TwitterID__c desc limit 11:30:0.211|SOQL_EXECUTE_END|[418,45]|Rows:1|Duration:61:30:0.211|SOQL_EXECUTE_BEGIN|[422,41]|Aggregations:0|select TwitterID__c, Twitter_Account__c, Direct_Message__c,type__c from Twitter_Conversation__c where Type__c = :Label.TWITTER_TYPE_DIRECT_MESSAGE and Twitter_Account__c in :accounts.keySet() order by TwitterID__c desc limit 11:30:0.215|SOQL_EXECUTE_END|[422,41]|Rows:0|Duration:41:30:0.218|DML_BEGIN|[443,3]|Op:Update|Type:sf4twitter__Twitter_Account__c|Rows:11:30:0.238|ENTERING_MANAGED_PKG|sf4twitter1:30:0.238|SOQL_EXECUTE_BEGIN|[5,42]|Aggregations:0|select id, Username__c from Twitter_Account__c where Username__c =: Trigger.new[0].Username__c and ownerId = :UserInfo.getUserId()1:30:0.243|SOQL_EXECUTE_END|[5,42]|Rows:1|Duration:51:30:0.243|CUMULATIVE_LIMIT_USAGE1:30:0.243|CUMULATIVE_LIMIT_USAGE_END1:30:0.256|DML_END|[443,3]|1:30:0.257|METHOD_EXIT|[5,14]|doSearchAccount(Id, Integer)1:30:0.257|METHOD_ENTRY|[6,3]|system.debug(String)1:30:0.258|USER_DEBUG|[6,3]|DEBUG|result: <?xml version="1.0" encoding="UTF-8"?><result><conversations>0</conversations><cases>0</cases><caseComments>0</caseComments><contacts>0</contacts><leads>0</leads><errorCode>null</errorCode><errorMsg>null</errorMsg><pageNumber>0</pageNumber></result>1:30:0.258|METHOD_EXIT|[6,3]|debug(ANY)1:30:0.258|CODE_UNIT_FINISHED1:30:0.258|EXECUTION_FINISHED

 

 The scheduler class that I'm running every 10 minutes

 

global class SynchTwitter Implements Schedulable{ global void Execute(SchedulableContext SC){ sf4twitter__twitter_account__c acc = [select id from sf4twitter__twitter_account__c where name = 'mytwitteraccountname' limit 1]; string s = sf4twitter.automationwrapper.doSearchAccount(acc.id,0); system.debug('result: ' + s); }}

 

 I let this run for an hour, and no results were ever pulled back.  I ran the code inside the execute method on its own via the system log window, and it pulled back the conversations I was expected to be pulled.

 

The documentation for the Spring '10 release does not indicate that HTTP callouts are not supported in Scheduled Apex.  I'm not willing to write a complete class just to confirm whether or not it's supported, and I can't see any issues with the Twitter class debug log (it's a managed package, so I can't see what's being done where). 

 

Please advise. 

 

 

Hi,

 

i'm writing a Visualforce Controller where i need to get the Api Names of the fields of a specific Object, but everything i get is only lower case. I actually need them like they are originally named, because of a WebService Call i'm doing with those field names.

 

Is there any way to get the api names of fields and objects original, and why are they lowercase anyway?

 

Thanks

Michael Kahle

Hello everyone!!

 

I've an object called Expediente__c, where I have two fields; Cerrado__c (It's a Checkbox) and Situacion__c (It's a text field)

 

I want to develop a trigger to make automatically an update, I mean, if Cerrado__c changes to False, I want  Situacion__c='Cerrado'

 

 

any idea?!?!? thanks!!

 The following code fails at the first reference to scale in inner class RGB. Is there a right way to do this?
 

public class MyClass {
Integer scale = 1;
class RGB {
Integer red;
Integer green;
Integer blue;
RGB(Integer red, Integer green, Integer blue) {
this.red = red * scale;
this.green = green * scale;
this.blue = blue * scale;
}
}
}

 

 
 
 

Error: Compile Error: Variable does not exist: scale at line 12 column 30

 

 
Message Edited by Shikibu on 04-25-2009 08:21 AM

Hi all:

  Does anyone know how to format a number in Apex so that a number in VF appears correctly...

for example 25000 appears 25,000.00

Anyone have an idea or did this already??

Thanks

Let MMA guide you

hi i am creating "Email" as Custom object. & add to Create a lookup relation for "Email" in contact.Email object have the custom fields of name & email id.if I add one email to the email id equals to contacts then The contact details add to email's releated list.if is not mathes the email id nothing is happen in email - contact related list.If i update that mail id to new one it removes the old contact & update new contact in email related list..I am creating this Trigger but,it show the error in updating time.So How to handle this one for Trigger.new & Trigger.old concept????

 

trigger trg_Lookup_Contact on Email_Suppression__c (after insert,before update)
{
    for(Email_Suppression__c emailobj : Trigger.New)
    {
        contact[] conobj ;
        if(Trigger.Isupdate)
        {
            conobj = [select name,email,Email_Suppression__c from contact where email =: emailobj.EmailId__c OR email =: Trigger.old.EmailId__c];
        }
        else
        {
            conobj = [select name,email,Email_Suppression__c from contact where email =: emailobj.EmailId__c];
        }
        integer inte = conobj.size();
        for(integer i = 0;i < inte;i++)
        {
            if(emailobj.EmailId__c == conobj[i].email)
            {
                conobj[i].Email_Suppression__c = emailobj.id;
                update conobj[i];
            }
            else
            {
                conobj[i].Email_Suppression__c = null;
                update conobj[i];
            }
        }
    }
}

Message Edited by Krishna_ on 04-21-2009 02:59 PM

trigger HonorariosAutomatico on Factura__c (before insert, before update)
{
  for (Factura__c fac: Trigger.new)
  {
    for (Tarifa__c tar: [select id, Corresponde__c from Tarifa__c where id = :fac.Tarifa__c])

    {
        fac.Honorarios__c = tar.Corresponde__c;

    }
  }
}



private class TestNewFactura
{
    static TestMethod void MiTest()
    {
           Factura__c f=new Factura__c();
           for (Tarifa__c t: [select id, Corresponde__c from Tarifa__c where Name = 'T-001'])
           {
               f.Honorarios__c = t.Corresponde__c;
               insert f;   
           }
           Integer prueba=[select Id from Factura__c where Honorarios__c =: f.Honorarios__c];
           if (prueba)
           {
               System.assert(true);
           }
           else
           {
               System.assert(false);
           }
    }
}

 

 

 

 

 

Error: Compile Error: expecting EOF, found 'private' at line 14 column 1

 

 

What's the matter?!?!?

 

Thank you ;)

Hi,
 
I am trying to use the date method to modify a date but am unable to do so. The details are
Position is a custom object 
Opendate is a field with date data type
Count is a field with number date type
Closeddate is a field with date data type
I am trying to calculate the closedate from the Opendate and Count but i am not able to do so. The code is a follows

double c = position.Count__c;date mydate = date.valueof(position.Opendate__c);date newdate = mydate.adddays(c);position.Cdate__c = newdate;

If I replace the variable c with a constant number as 1 or 2, it performs the operation properly. I am unable to pass the value of Count there. How can i get this done.
 
Thanks
KD 

 

  • April 21, 2009
  • Like
  • 0

I have a trigger trying to access the name on the foreign key Contact:

 

 

trigger SAC_updateName on Support_Agreement_Contacts__c (before insert, before update) { for (Support_Agreement_Contacts__c sac:Trigger.new){ Contact[] c = [Select Name from Contact where Id =: sac.Contact_Id__c]; if (c.size() > 0) { sac.Name = c[0].Name; } else { sac.Name = 'John Doe'; } } }

 

Which obviously will generate a "Too many sql queries" on bulk updates, but it is like this because this doesn't work:

 

trigger SAC_updateName on Support_Agreement_Contacts__c (before insert, before update) { for (Support_Agreement_Contacts__c sac:Trigger.new){ if (sac.Contact_Id__c != null) { sac.Name = sac.Contact_Id__c.Name; } else { sac.Name = 'John Doe'; } } }

 

 

 

 

So - obviously, I don't get how this should work at all. I also tried the different __r and whatnots - but I could never get any real reference to the Contact object. Can anyone help a newbie out with this? 

Hi,

 

I am trying to writh a dymanic class method, which would allow me to pass the sObject and field name as parameters in order to return the value from a single field. I have found the reverences to dynamic SOQL in the apex docs and am able to run a dynamic query to return an sObject which represents a single record of an Account type.

 

What I am having trouble with is then how to extract the field from that sObject (using the dynamic reference to the field name passed to the method) and return this out of the method as a string.

 

 

 

This is my current class method. At the moment, it is only dynamic for the field, and the sObject is hard-coded as being an Account. I have tried using the DescribeFieldResult method but believe this is not the correct approach.

 

private Object getObject(Id i, String s){

 

String r;

String sQuery = 'SELECT Id,' + s + 'FROM Account WHERE Id:= id';

Account a = Database.query(sQuery);

// Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.AS400_ID__c;

//Schema.DescribeFieldResult f = Account.AS400_ID__c.getDescribe();

//r = f.getDefaultValue();

return r;

}

 

Thanks

 

Jim