• mariagus
  • NEWBIE
  • 100 Points
  • Member since 2011

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 24
    Replies

How i can create the test class of this code................

 

  public List<String> availableFields {
        get {
        controller.addFields(new List<String>(bookFields));
        return new List<String>(bookFields);
        }
    }
  • December 21, 2011
  • Like
  • 0

Hi All,

 

I'm working with a couple of custom objects that have a master-detail relationship with one another.  The master's api name is zqu_Quote__c and the detail's api name is zqu__QuoteCharge__c.

 

I'm trying to write a simple trigger that will query for the field "zqu__Discount__c" in the detail object and assign that value to the field Discount__c in the master object.  Unfortunately, I'm having trouble accessing the master object in my query.  My code is below - I think my issue has to do with the syntax I'm using to call for the ID of the zqu__Quote__c object.  Any suggestions?

 

 

trigger DiscountUpdate on zqu__QuoteCharge__c (after insert) {

	 list<QuoteCharges__c> myList = [select q.Id,    q.zqu__Discount__c, q.zqu__Quote__r.Discount__c from zqu__QuoteCharge__c q where q.Quote__c =:quoteID];
	 
	 for (QuoteCharge__c qc: myList) {
	 	qc.zqu__Quote__r.Discount__c = qc.zqu__Discount__c;
	 	}
	 update mylist;
}

 

 

Hi,

 

I saw several posts asking the same question. Is there a way to unzip a file in Apex in the latest release?

 

I could see that the best solution would be to use an external app, but I think this could be a risk for several reasons. I was also thinking about a JavaScript solution, but I'm not sure if this will work.

 

I would really appreciate any idea that I could follow to finish the process and make our customer happy.

 

Thanks

Hi,

 

I have a flow which creates a record of a custom object, where user enters its name. This data must be unique so I have a trigger that validates that.

 

If I try to create a record with an existing name, I get an e-mail with the exception, but what I would like to get is a screen with this error message. I don't mind creating a variable which will be populate with this error and show it in a new screen in the flow or just create a page with the flow target and show the error message there. Both optios are valid for me but I don't know how to develope it.

 

Any idea?

 

Thanks in advance.

Hi all,

 

I'm working on a development that gets a JSON file with a father and child objects information. After that, I could do some changes in the JSON file directly and after importing, I create with this new data a new father and child record. It used the old JSONObejct class and it was working fine, but I got a too many script statament error so I decide to take a look at the new JSON Winter'12 feature.

 

The current JSON.serialize(SObject) method works fine and returns me this:

 

{
    "attributes": {
        "type": "MyObject__c",
        "url": "..................................."
    },
    "Id": "a1SD00000005Hk5MAE",
    "Field1__c": "Test1-complex",
    "Field2__c": "Test2-complex",
    "MyObjectLineItems__r": {
        "size": 1,
        "totalSize": 1,
        "done": true,
        "records": [
            {
                "attributes": {
                    "type": "MyObjectLineItem__c",
                    "url": "............................................................."
                },
                "Id": "a1TD0000000FFAJMA4",
                "Field1__c": "text1",
                "Field2__c": 150,
                "Field3__c": 155.55,
                "Field4__c": true,
                "Field5__c": "2011-12-20",
                "Field6__c": "2011-12-20T15:24:00.000+0000",
                "Field7__c": "No",
                "MyObject__c": "a1SD00000005Hk5MAE"
            }
        ],
        "queryLocator": null
    }
}

 

But I don't know how to use the deserialize method because it's second argument is the type, and here I have two objects.

 

I tried to create my own deseriaze method, using the JSON.createParser(JSONString); but, in order to make my code as easier as possible, I wanted to use the parser.readValueAs() method. But I'm not sure how to do it because, I don't have in the JSON string the name of my father object, and if I try to do it with my child one, it doesn't work either.

 

This is my code:

 

List<MyObject__c> myObjectList = [Select Id,
                                                                             Field1__c, //Text
                                                                             Field2__c, //Text
                                                                            (Select Id, 
                                                                                          Field1__c, //Text
                                                                                          Field2__c, //Integer
                                                                                          Field3__c, //Decimal
                                                                                          Field4__c, //Checkbox
                                                                                          Field5__c, //Date
                                                                                          Field6__c, //DateTime
                                                                                          Field7__c, //Picklist
                                                                                          MyObject__c
                                                                             From MyObjectLineItems__r)               
                                                             From MyObject__c
                                                             Where Id = :myObjectId];
   
   if(myObjectList.isEmpty())
   {
               throw new MyJSONException('There is no object which ID is ' + myObjectId);   
   }
   else
   {
                String JSONString = JSON.serialize(myObjectList.get(0));
               

                // Parse JSON response
               JSONParser parser = JSON.createParser(JSONString);
    
               while(parser.nextToken() != null)
               {
                      if(parser.getCurrentToken() == System.JSONToken.FIELD_NAME)
                      {
                              if(parser.getText() == 'MyObjectLineItems__r')
                              {
                                             Type lineItem = Type.forName('MyObjectLineItem__c');
                                             MyObjectLineItem__c so = (MyObjectLineItem__c)parser.readValueAs(lineItem);       
                              }
                       }
                }
   }

 

I know that I could go throw each line, and read the field and the value, but I would like to do as quicker as possible.

 

Can someone help me?

 

 

Many thanks in advance.

 

Hi,

 

I have a new custom object, and I would like to include also chatter.

 

The chatter consist of Post's by the users and Post's by the system(like "Peter: Created this New record"). Post's by the user are implemented successfully but the issue is with System Generated Post's

 

We are trying to implement the 'System Generated Messages' for the chatter. But for the system generated posts 'feedPostId' and the 'Body' fields are null in the web response.

 

We are using the following query for fetching the post's

 

"SELECT Type, CreatedById, ParentId, Id, FeedPost.Body, FeedPostId, CreatedDate, (Select CreatedById, CreatedDate, FeedItemId, CommentBody From FeedComments ORDER BY CreatedDate) FROM myObject__Feed WHERE  ParentId = :parentId ORDER BY CreatedDate DESC LIMIT 50"

 

If I run the query without the Where clause, I can see that some other records has the FeedPost.Body filled.

 

Has anybody and idea about why some records has no information?

 

Many thanks in advance



Hi all,

 

My piece of code, tries to get some information about the records that make the upsert fails, so for instance, instead of getting just "duplicate External Id" as an error, I would like to know which record is causing this error and why

 

I tried this:

 

transient List<Database.UpsertResult> upsertResult = new List<Database.UpsertResult>();

try

{

    Schema.SObjectField externalIdField = myObject__c.Fields.ExternalId__c;

    List<UpsertResult> upsertResult = Database.upsert(myObjectList, externalIdField,true);

}

catch(Exception ex)

{

       String error = upsertResult + '';

       sendEmail(error);

}

 

But e-mail returns to me null,

 

Does anybody know how can I fix it or if there is other way to get which record is causing the error and why?

 

Many thanks in advance

 

Hi all,

 

I was trying to know where my upsert was failing and which record was making the mistake.

 

After doing some research, I found that Database.Upsert method gives me the information that I need but when I tryied to run it on my batch apex process, where my upsert is, I got this error: "  Not Serializable: LIST<Database.UpsertResult> 

 

  "

 

Does anybody know how can I fix it?

 

This is part of my code:

 

List<Database.UpsertResult> upsertResults;

Schema.SObjectField externalIdField = SalesAgreement__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementDtoList,externalIdField,false)

externalIdField = SalesAgreementLineItem__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementLineItemDtoList,externalIdField,false);

 

Many thanks in advance

HI,

 

I am Nagesh. I am new dev for Force.com.

I want to find, How can we read files using apex language on force.com platform.

 

Is there any way to read property files???

 

I have tried following ways to read file but i havn't get success.

1) create simple file 'Temp.properties' in staticResource in force IDE. and try to populate it from StaticResource Table.

2) Using file app upload a file and try to populate it from Document Table.

In both case, No rows generated.

 

Please help me to solve this problem.

Send mail on::

nagesh.takle@gmail.com

 

Thanks in advanced

--Nagesh

Hi,

 

I saw several posts asking the same question. Is there a way to unzip a file in Apex in the latest release?

 

I could see that the best solution would be to use an external app, but I think this could be a risk for several reasons. I was also thinking about a JavaScript solution, but I'm not sure if this will work.

 

I would really appreciate any idea that I could follow to finish the process and make our customer happy.

 

Thanks

hi,

 

i import data though csv file but when data is more than 1000 then it gives me Error

 

 

System.LimitException: Regex too complicated

 

Can anybody give me Explanation ?

Hi All,

We have the following requirements:

1. Load ~300,000 records into a custom object. There are 22 fields.

2. Validations - no duplicates (unique combination of four fields), no null values and correct data type.

3. Need to capture the errors at the record level and display to the user.

4. Insertion of records should not happen at all even if there is a single error in the data.

The system is financial in nature and users do not want to use the apex data loader.

SOLUTION:

Custom data loader (using apex code) to insert records into the custom object.

While loading records, we are getting multiple errors based on file size - Regex too complicated, view state exceeded etc.

 

Is there any alternative for this process OR any way to optimise the current code (even if it is fully optimised - will it validate and upload all the records)?

  • January 11, 2012
  • Like
  • 0

How i can create the test class of this code................

 

  public List<String> availableFields {
        get {
        controller.addFields(new List<String>(bookFields));
        return new List<String>(bookFields);
        }
    }
  • December 21, 2011
  • Like
  • 0

Hi all,

 

I'm working on a development that gets a JSON file with a father and child objects information. After that, I could do some changes in the JSON file directly and after importing, I create with this new data a new father and child record. It used the old JSONObejct class and it was working fine, but I got a too many script statament error so I decide to take a look at the new JSON Winter'12 feature.

 

The current JSON.serialize(SObject) method works fine and returns me this:

 

{
    "attributes": {
        "type": "MyObject__c",
        "url": "..................................."
    },
    "Id": "a1SD00000005Hk5MAE",
    "Field1__c": "Test1-complex",
    "Field2__c": "Test2-complex",
    "MyObjectLineItems__r": {
        "size": 1,
        "totalSize": 1,
        "done": true,
        "records": [
            {
                "attributes": {
                    "type": "MyObjectLineItem__c",
                    "url": "............................................................."
                },
                "Id": "a1TD0000000FFAJMA4",
                "Field1__c": "text1",
                "Field2__c": 150,
                "Field3__c": 155.55,
                "Field4__c": true,
                "Field5__c": "2011-12-20",
                "Field6__c": "2011-12-20T15:24:00.000+0000",
                "Field7__c": "No",
                "MyObject__c": "a1SD00000005Hk5MAE"
            }
        ],
        "queryLocator": null
    }
}

 

But I don't know how to use the deserialize method because it's second argument is the type, and here I have two objects.

 

I tried to create my own deseriaze method, using the JSON.createParser(JSONString); but, in order to make my code as easier as possible, I wanted to use the parser.readValueAs() method. But I'm not sure how to do it because, I don't have in the JSON string the name of my father object, and if I try to do it with my child one, it doesn't work either.

 

This is my code:

 

List<MyObject__c> myObjectList = [Select Id,
                                                                             Field1__c, //Text
                                                                             Field2__c, //Text
                                                                            (Select Id, 
                                                                                          Field1__c, //Text
                                                                                          Field2__c, //Integer
                                                                                          Field3__c, //Decimal
                                                                                          Field4__c, //Checkbox
                                                                                          Field5__c, //Date
                                                                                          Field6__c, //DateTime
                                                                                          Field7__c, //Picklist
                                                                                          MyObject__c
                                                                             From MyObjectLineItems__r)               
                                                             From MyObject__c
                                                             Where Id = :myObjectId];
   
   if(myObjectList.isEmpty())
   {
               throw new MyJSONException('There is no object which ID is ' + myObjectId);   
   }
   else
   {
                String JSONString = JSON.serialize(myObjectList.get(0));
               

                // Parse JSON response
               JSONParser parser = JSON.createParser(JSONString);
    
               while(parser.nextToken() != null)
               {
                      if(parser.getCurrentToken() == System.JSONToken.FIELD_NAME)
                      {
                              if(parser.getText() == 'MyObjectLineItems__r')
                              {
                                             Type lineItem = Type.forName('MyObjectLineItem__c');
                                             MyObjectLineItem__c so = (MyObjectLineItem__c)parser.readValueAs(lineItem);       
                              }
                       }
                }
   }

 

I know that I could go throw each line, and read the field and the value, but I would like to do as quicker as possible.

 

Can someone help me?

 

 

Many thanks in advance.

 

Hi,

 

I have a new custom object, and I would like to include also chatter.

 

The chatter consist of Post's by the users and Post's by the system(like "Peter: Created this New record"). Post's by the user are implemented successfully but the issue is with System Generated Post's

 

We are trying to implement the 'System Generated Messages' for the chatter. But for the system generated posts 'feedPostId' and the 'Body' fields are null in the web response.

 

We are using the following query for fetching the post's

 

"SELECT Type, CreatedById, ParentId, Id, FeedPost.Body, FeedPostId, CreatedDate, (Select CreatedById, CreatedDate, FeedItemId, CommentBody From FeedComments ORDER BY CreatedDate) FROM myObject__Feed WHERE  ParentId = :parentId ORDER BY CreatedDate DESC LIMIT 50"

 

If I run the query without the Where clause, I can see that some other records has the FeedPost.Body filled.

 

Has anybody and idea about why some records has no information?

 

Many thanks in advance



Hi, I am trying following code from the Chatter workbook but it is throwing error below. Any suggestion?

 

 

private static void displayNewsFeed() throws Exception {

System.out.println("Querying for status updates...");

QueryResult queryResults = connection.query

("SELECT Id, Type, CreatedDate, CreatedBy.name, Body FROM NewsFeed WHERE Type= 'UserStatus' ORDER BY CreatedDate DESC, ID DESC LIMIT 10");

if (queryResults.getSize() > 0) {

for (SObject s : queryResults.getRecords()) {

System.out.println(s.getChild("NewsFeed").getField("Body") );

}

}

}

 

 

^

Exception in thread "main" [InvalidFieldFault [ApiQueryFault [ApiFault exceptionCode='INVALID_FIELD'

exceptionMessage='

CreatedDate, CreatedBy.name, Body FROM NewsFeed WHERE Type= 'UserStatus'

ERROR at Row:1:Column:47

No such column 'Body' on entity 'NewsFeed'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.'

]

row='1'

column='47'

]

]

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(

Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at java.lang.Class.newInstance0(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at com.sforce.ws.bind.TypeMapper.readSingle(

TypeMapper.java:627)

at com.sforce.ws.bind.TypeMapper.readObject(

TypeMapper.java:504)

at com.sforce.ws.transport.SoapConnection.parseDetail(

SoapConnection.java:226)

at com.sforce.ws.transport.SoapConnection.createException(

SoapConnection.java:200)

at com.sforce.ws.transport.SoapConnection.receive(

SoapConnection.java:146)

at com.sforce.ws.transport.SoapConnection.send(

SoapConnection.java:98)

at com.sforce.soap.partner.PartnerConnection.query(

PartnerConnection.java:1158)

at com.developerforce.chatter.ChatterMain.displayNewsFeed(

ChatterMain.java:65)

at com.developerforce.chatter.ChatterMain.main(

ChatterMain.java:35)

 

 

 

 

 

 

 

 

 

  • August 12, 2011
  • Like
  • 0

Hi all,

 

My piece of code, tries to get some information about the records that make the upsert fails, so for instance, instead of getting just "duplicate External Id" as an error, I would like to know which record is causing this error and why

 

I tried this:

 

transient List<Database.UpsertResult> upsertResult = new List<Database.UpsertResult>();

try

{

    Schema.SObjectField externalIdField = myObject__c.Fields.ExternalId__c;

    List<UpsertResult> upsertResult = Database.upsert(myObjectList, externalIdField,true);

}

catch(Exception ex)

{

       String error = upsertResult + '';

       sendEmail(error);

}

 

But e-mail returns to me null,

 

Does anybody know how can I fix it or if there is other way to get which record is causing the error and why?

 

Many thanks in advance

 

Hi all,

 

I was trying to know where my upsert was failing and which record was making the mistake.

 

After doing some research, I found that Database.Upsert method gives me the information that I need but when I tryied to run it on my batch apex process, where my upsert is, I got this error: "  Not Serializable: LIST<Database.UpsertResult> 

 

  "

 

Does anybody know how can I fix it?

 

This is part of my code:

 

List<Database.UpsertResult> upsertResults;

Schema.SObjectField externalIdField = SalesAgreement__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementDtoList,externalIdField,false)

externalIdField = SalesAgreementLineItem__c.Fields.Id;

upsertResults = Database.upsert(salesAgreementLineItemDtoList,externalIdField,false);

 

Many thanks in advance

Hi All,

 

I'm working with a couple of custom objects that have a master-detail relationship with one another.  The master's api name is zqu_Quote__c and the detail's api name is zqu__QuoteCharge__c.

 

I'm trying to write a simple trigger that will query for the field "zqu__Discount__c" in the detail object and assign that value to the field Discount__c in the master object.  Unfortunately, I'm having trouble accessing the master object in my query.  My code is below - I think my issue has to do with the syntax I'm using to call for the ID of the zqu__Quote__c object.  Any suggestions?

 

 

trigger DiscountUpdate on zqu__QuoteCharge__c (after insert) {

	 list<QuoteCharges__c> myList = [select q.Id,    q.zqu__Discount__c, q.zqu__Quote__r.Discount__c from zqu__QuoteCharge__c q where q.Quote__c =:quoteID];
	 
	 for (QuoteCharge__c qc: myList) {
	 	qc.zqu__Quote__r.Discount__c = qc.zqu__Discount__c;
	 	}
	 update mylist;
}

 

 

I am getting a ‘Regex too complicated’ error below when loading data into our org using the following process:

 

1) an email service to receive the CSV data,

2) an APEX class to split and validate the CSV data, and then

3) a set of @future calls to upsert the data.

 

The same data works in smaller volumes, but not beyond a certain threshold. This applies whether we reduce the number of rows, or reduce the width of certain columns of data by truncating them to 3000 characters (a small number of columns have 10,000 characters of text included). When we do either or both of these steps in any combination to reduce the file size, we don't get this problem. It’s not a problem with a specific badly formatted row either, because reducing the number of rows in various combinations always causes the problem to go away.

 

So we don’t believe it is actually a regex problem, because the regular expression is just finding commas to split up a comma separated file/string - i.e. it's very simple.

 

This is why we think there's an undocumented storage or capacity limit somewhere within the APEX processing that is being exceeded - but one that doesn't have a governor limit associated with it, or indeed an accurate error message. We think it is an erroneous error message - i.e. it's not to do with complicated regex – and that this error message is a symptom of another issue.

 

This error has occurred in code that has been stable to date, but has appeared since the filesize we're uploading has increased to beyond about 4600-4800KB, which seems to be the threshold beyond which this problem occurs. There seem to be some undocumented limits in the volume of data than can be processed using the solution architecture we've designed.

 

We want to be able to code around this problem, but unless we know exactly what the error is, any changes we make to our code may not actually fix the problem and result in wasted effort. So I don't want to start changing this until I know exactly which part of the solution needs to be changed!

 

I’ve raised this with Salesforce as a potential bug or to see if they could clarify any undocumented limits on processing large volume datasets using the process we’ve designed, but they seem to have decided it’s a developer issue so won’t help.

 

The error message is below:

 

Apex script unhandled exception by user/organization: 

Failed to invoke future method 'public static void PrepareCSV(String, String, String, Integer, Boolean)'

caused by: System.Exception: Regex too complicated

Class.futureClassToProcess.GetList: line 98, column 17
Class.futureClassToProcess.parseCSV: line 53, column 38
Class.futureClassToProcess.PrepareCSV: line 35, column 20 External entry point

 The relevant code snippet is below:

 

 

 

public static list<List<String>> GetList(String Content)
        {
        Content = Content.replaceAll(',"""',',"DBLQT').replaceall('""",','DBLQT",');
            Content = Content.replaceAll('""','DBLQT');
            List<List<String>> lstCSV = new List<List<String>>();
            Boolean Cont = true;
            while (Cont == true){
                List<String> lstS = Content.Split('\r\n',500);
                if(lstS.size() == 500){
                    Content =lstS[499];
                    lstS.remove(499);
                }else{
                    Cont = false;
                }
                lstCSV.add(lstS);
            }
            return lstCSV;
        }

 

Any suggestions gratefully received as to whether we're missing something obvious, whether 4MB+ files just can't be processed this way, or whether this might actually be a SFDC APEX bug.

 

 

 

public static list<List<String>> GetList(String Content)
        {
            //Sanjeeb
            Log('GetList started.');
            Content = Content.replaceAll(',"""',',"DBLQT').replaceall('""",','DBLQT",');
            Log('Replaing DBLQT.');
            Content = Content.replaceAll('""','DBLQT');
            Log('Replaing DBLQT.');
            List<List<String>> lstCSV = new List<List<String>>();
            Boolean Cont = true;
            while (Cont == true){
                List<String> lstS = Content.Split('\r\n',500);
                Log('Split upto 500 Rows.');
                //List<String> lstS = Content.Split('\r\n',1000);
                if(lstS.size() == 500){
                    Content =lstS[499];
                    lstS.remove(499);
                }else{
                    Cont = false;
                }
                lstCSV.add(lstS);
            }
            Log('GetList ends.');
            return lstCSV;
        }

I am developing an Apex class to create records by parsing a .csv file.  

I was expecting a CSV file to appear as a textAttachment in the email object. The MIME type for a CSV file is (according to RFC 4180) is text/csv. This actually appears as a binaryAttachment with MIME type application/vnd.ms-excel. I am saving the file as CSV (comma separated values) in Excel

 

Is there a way to get a CSV file as a text attachment (whose body is then a Apex String instead of a blob)?  

Any pointers would be greatly appreciated.

 

Thanks.  

 

 

  • March 04, 2009
  • Like
  • 0