• Sanchit Dua
  • NEWBIE
  • 49 Points
  • Member since 2012
  • Senior Software Developer
  • Astrea IT Services


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 11
    Replies
When I click on edit link available at Global Publisher Layout, it throws an error as attached. Please help.User-added image

I needed to first create some Record Types for some custom objects using Metadata. After doing those, I was to upsert the records on those custom objects using the RecordTypeId.

I noticed one thing that one needs to set the visibility of the Record Types from Profile otherwise the Error comes - something like Invalide RecordTypeId for the User.

So, I have the flow of my application set from Java as

First create the Record Types, thereafter fetch the RecordTypeID and then upsert the records on the custom object I need to target.

So, I need to update the Profile using Metadata API itself to set the visibility of Record Types as:

ProfileRecordTypeVisibility[] prtv = new ProfileRecordTypeVisibility[recordTypes.size()];
prtv[0] = new ProfileRecordTypeVisibility();
prtv[0].setRecordType("abc");
prtv[0].setDefault(true);
prtv[0].setVisible(true);

Profile pr = new Profile();
pr.setRecordTypeVisibilities(prtv);
UpdateMetadata ut = new UpdateMetadata();
pr.setFullName("System_Administrator");
ut.setMetadata(pr);

 


So, I'm getting the Error like

com.sforce.ws.SoapFaultException: INVALID_CROSS_REFERENCE_KEY: In field: fullName - no Profile named System_Administrator found.

 



I have even tried System Administrator, Profile, Profile.System_Administrator but none worked for me.

The Salesforce doc says for the Profile object's fullName field: It must be specified when creating, updating, or deleting.

Please let me know what I'm doing wrong or is there anything else I can go for.

Thanks

 

I'm trying to make batches from a CSV file written using CSVWriter of opencsv as:
CSVWriter writer = new CSVWriter(new FileWriter(filePath+createFileName), ',', CSVWriter.DEFAULT_QUOTE_CHARACTER);

And BufferedReader to read the written file. The Csv file is written and I think read operation also goes well. So, far its working good. But when I chose particular data to be written to Csv using the same operations, creation of batches comes under error out of it.
An Exception is coming stating "Failed to parse CSV. Found unescaped quote. A value with quote should be within a quote" which is making the Application to not behave in a manner expected.

After going through this error it seems there's some ""(double quote) or "(double quote) symbol present in the data. (I 've the data in form of "asdf","1.0","",,"def").
As far as my understanding I tried to apply Regex to find double quotes but couldn't find any, as after examining the file it doesn't contain the repeated double quotes. The link I followed is:http://stackoverflow.com/questions/3180842/regular-expression-to-find-and-replace-unescaped-non-successive-double-quotes-in

Thereafter in the code, I'm making use of: File tmpFile = File.createTempFile("bulkAPIInsert", ".csv"); to hold the data in a temporary file and then deleting it.

After replacing the above code with the following I somehow handled the coming exception but it futher lead to another one stating "Failed to parse CSV. EOF reached before closing an opened quote".
File tmpFile = new File("bulkAPIInsert.csv");

I don't think the above workaround should be followed as it would be performance issues with the application.

By going through the CSVReader class I found a custom exception defined stating exactly the same Exception as I got. But I think it comes when a double quote is found within some double qoute (the cell value of CSV File). I referred the link as: https://github.com/mulesoft/salesforce-connector/blob/master/src/main/java/com/sforce/async/CSVReader.java

Can anybody suggest me where I'm doing wrong or any workaround for this Problem?

I'm sharing you the code snippet as:
Method1 then Method2 is called.

 

Method1: private List<BatchInfo> createBatchesFromCSVFile(RestConnection connection,
			JobInfo jobInfo, String csvFileName) throws Exception {
		List<BatchInfo> batchInfos = new ArrayList<BatchInfo>();
		BufferedReader rdr = new BufferedReader(new InputStreamReader(
				new FileInputStream(csvFileName)));

		// read the CSV header row
		String hdr = rdr.readLine();
		byte[] headerBytes = (hdr + "\n").getBytes("UTF-8");
		int headerBytesLength = headerBytes.length;
//      I was making use of the following code which I replaced with the next line of code.
//		File tmpFile = File.createTempFile("bulkAPIInsert", ".csv");
		File tmpFile = new File("bulkAPIInsert.csv");
		// Split the CSV file into multiple batches
		try {
			FileOutputStream tmpOut = new FileOutputStream(tmpFile);
			int maxBytesPerBatch = 10000000; // 10 million bytes per batch
			int maxRowsPerBatch = 10000; // 10 thousand rows per batch
			int currentBytes = 0;
			int currentLines = 0;
			String nextLine;

			while ((nextLine = rdr.readLine()) != null) {
				byte[] bytes = (nextLine + "\n").getBytes("UTF-8"); //TODO
				if (currentBytes + bytes.length > maxBytesPerBatch
						|| currentLines > maxRowsPerBatch) {
					createBatch(tmpOut, tmpFile, batchInfos, connection, jobInfo);
					currentBytes = 0;
					currentLines = 0;
				}
				if (currentBytes == 0) {
					tmpOut = new FileOutputStream(tmpFile);
					tmpOut.write(headerBytes);
					currentBytes = headerBytesLength;
					currentLines = 1;
				}
				tmpOut.write(bytes);
				currentBytes += bytes.length;
				currentLines++;
			}

			if (currentLines > 1) {
				createBatch(tmpOut, tmpFile, batchInfos, connection, jobInfo);
			}
		} finally {
			if(!tmpFile.delete())
				tmpFile.deleteOnExit();
			rdr.close();
		}
		return batchInfos;
	}

/**
	 * Wait for a job to complete by polling the Bulk API.
	 */
	Method2: private void awaitCompletion(RestConnection connection, JobInfo job,
			List<BatchInfo> batchInfoList) throws AsyncApiException { 
		try{
			/****
			Some code
			**/
				BatchInfo[] statusList = connection.getBatchInfoList(job.getId())
				.getBatchInfo();
				for (BatchInfo b : statusList) {
					if (b.getState() == BatchStateEnum.Completed) {
						if (incomplete.remove(b.getId())) 
							//Do Something
					}
					else if(b.getState() == BatchStateEnum.Failed){ 

						System.out.println("Reason: "+b.getStateMessage()+".\n  " +
								"Number of Records Processed: "+b.getNumberRecordsProcessed());
						throw (new Exception(""));
					}
				}
			}
		}catch(Exception ex){log.debug(" Exception occurred.");}
	}

 The getStateMessage() method of BatchInfo gives the discussed error messages.

When I click on edit link available at Global Publisher Layout, it throws an error as attached. Please help.User-added image
Hi Folks,

Whenever we create a custom field we go through 4 different pages where we start with
selecting the datatype -->CLICK NEXT --> Give name and label -->CLICK NEXT--> Security-->CLICK NEXT--> and finally select pagelayout and save.

why 4 different pages why not in a single page...?

I needed to first create some Record Types for some custom objects using Metadata. After doing those, I was to upsert the records on those custom objects using the RecordTypeId.

I noticed one thing that one needs to set the visibility of the Record Types from Profile otherwise the Error comes - something like Invalide RecordTypeId for the User.

So, I have the flow of my application set from Java as

First create the Record Types, thereafter fetch the RecordTypeID and then upsert the records on the custom object I need to target.

So, I need to update the Profile using Metadata API itself to set the visibility of Record Types as:

ProfileRecordTypeVisibility[] prtv = new ProfileRecordTypeVisibility[recordTypes.size()];
prtv[0] = new ProfileRecordTypeVisibility();
prtv[0].setRecordType("abc");
prtv[0].setDefault(true);
prtv[0].setVisible(true);

Profile pr = new Profile();
pr.setRecordTypeVisibilities(prtv);
UpdateMetadata ut = new UpdateMetadata();
pr.setFullName("System_Administrator");
ut.setMetadata(pr);

 


So, I'm getting the Error like

com.sforce.ws.SoapFaultException: INVALID_CROSS_REFERENCE_KEY: In field: fullName - no Profile named System_Administrator found.

 



I have even tried System Administrator, Profile, Profile.System_Administrator but none worked for me.

The Salesforce doc says for the Profile object's fullName field: It must be specified when creating, updating, or deleting.

Please let me know what I'm doing wrong or is there anything else I can go for.

Thanks

 

i am trying to connect to salesforce using post to get instance url and token..

but i am getting this error ...

how should i resolve this ??

i have also gicen proxy manually...

 

 

org.apache.http.conn.HttpHostConnectException: Connection to https://login.salesforce.com refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:158)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:561)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at com.sample.onpremise.ChatterIntegration.login2ForceDotCom(ChatterIntegration.java:70)
at com.sample.onpremise.ChatterIntegration.main(ChatterIntegration.java:39)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:375)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
... 9 more

Hi,

 

I am using Metada API to delete custom fields.

I can delete custom field of an Object, but the custom field is put in the 'Deleted Fields' with the following API name customfield_del__c

Is it possible to erase the custom field of the 'Deleted Fields' list? I need to delete them of that list as well

 

I am using the following code

 

    public static void deleteCustomField(String fullname) throws Exception 
    {
        CustomField customField = new CustomField();
        customField.setFullName(fullname);
        UpdateMetadata updateMetadata = new UpdateMetadata();
        updateMetadata.setMetadata(customField);
        updateMetadata.setCurrentName(fullname);
        
        AsyncResult[] asyncResults  = metadataConnection.delete(new Metadata[] {customField});
 
        long waitTimeMilliSecs = ONE_SECOND;
 
        do 
        {
            printAsyncResultStatus(asyncResults);
            waitTimeMilliSecs *= 2;
            Thread.sleep(waitTimeMilliSecs);
            asyncResults = metadataConnection.checkStatus(new String[]{asyncResults[0].getId()});
        } while (!asyncResults[0].isDone());
 
        printAsyncResultStatus(asyncResults);
    }

I'm trying to make batches from a CSV file written using CSVWriter of opencsv as:
CSVWriter writer = new CSVWriter(new FileWriter(filePath+createFileName), ',', CSVWriter.DEFAULT_QUOTE_CHARACTER);

And BufferedReader to read the written file. The Csv file is written and I think read operation also goes well. So, far its working good. But when I chose particular data to be written to Csv using the same operations, creation of batches comes under error out of it.
An Exception is coming stating "Failed to parse CSV. Found unescaped quote. A value with quote should be within a quote" which is making the Application to not behave in a manner expected.

After going through this error it seems there's some ""(double quote) or "(double quote) symbol present in the data. (I 've the data in form of "asdf","1.0","",,"def").
As far as my understanding I tried to apply Regex to find double quotes but couldn't find any, as after examining the file it doesn't contain the repeated double quotes. The link I followed is:http://stackoverflow.com/questions/3180842/regular-expression-to-find-and-replace-unescaped-non-successive-double-quotes-in

Thereafter in the code, I'm making use of: File tmpFile = File.createTempFile("bulkAPIInsert", ".csv"); to hold the data in a temporary file and then deleting it.

After replacing the above code with the following I somehow handled the coming exception but it futher lead to another one stating "Failed to parse CSV. EOF reached before closing an opened quote".
File tmpFile = new File("bulkAPIInsert.csv");

I don't think the above workaround should be followed as it would be performance issues with the application.

By going through the CSVReader class I found a custom exception defined stating exactly the same Exception as I got. But I think it comes when a double quote is found within some double qoute (the cell value of CSV File). I referred the link as: https://github.com/mulesoft/salesforce-connector/blob/master/src/main/java/com/sforce/async/CSVReader.java

Can anybody suggest me where I'm doing wrong or any workaround for this Problem?

I'm sharing you the code snippet as:
Method1 then Method2 is called.

 

Method1: private List<BatchInfo> createBatchesFromCSVFile(RestConnection connection,
			JobInfo jobInfo, String csvFileName) throws Exception {
		List<BatchInfo> batchInfos = new ArrayList<BatchInfo>();
		BufferedReader rdr = new BufferedReader(new InputStreamReader(
				new FileInputStream(csvFileName)));

		// read the CSV header row
		String hdr = rdr.readLine();
		byte[] headerBytes = (hdr + "\n").getBytes("UTF-8");
		int headerBytesLength = headerBytes.length;
//      I was making use of the following code which I replaced with the next line of code.
//		File tmpFile = File.createTempFile("bulkAPIInsert", ".csv");
		File tmpFile = new File("bulkAPIInsert.csv");
		// Split the CSV file into multiple batches
		try {
			FileOutputStream tmpOut = new FileOutputStream(tmpFile);
			int maxBytesPerBatch = 10000000; // 10 million bytes per batch
			int maxRowsPerBatch = 10000; // 10 thousand rows per batch
			int currentBytes = 0;
			int currentLines = 0;
			String nextLine;

			while ((nextLine = rdr.readLine()) != null) {
				byte[] bytes = (nextLine + "\n").getBytes("UTF-8"); //TODO
				if (currentBytes + bytes.length > maxBytesPerBatch
						|| currentLines > maxRowsPerBatch) {
					createBatch(tmpOut, tmpFile, batchInfos, connection, jobInfo);
					currentBytes = 0;
					currentLines = 0;
				}
				if (currentBytes == 0) {
					tmpOut = new FileOutputStream(tmpFile);
					tmpOut.write(headerBytes);
					currentBytes = headerBytesLength;
					currentLines = 1;
				}
				tmpOut.write(bytes);
				currentBytes += bytes.length;
				currentLines++;
			}

			if (currentLines > 1) {
				createBatch(tmpOut, tmpFile, batchInfos, connection, jobInfo);
			}
		} finally {
			if(!tmpFile.delete())
				tmpFile.deleteOnExit();
			rdr.close();
		}
		return batchInfos;
	}

/**
	 * Wait for a job to complete by polling the Bulk API.
	 */
	Method2: private void awaitCompletion(RestConnection connection, JobInfo job,
			List<BatchInfo> batchInfoList) throws AsyncApiException { 
		try{
			/****
			Some code
			**/
				BatchInfo[] statusList = connection.getBatchInfoList(job.getId())
				.getBatchInfo();
				for (BatchInfo b : statusList) {
					if (b.getState() == BatchStateEnum.Completed) {
						if (incomplete.remove(b.getId())) 
							//Do Something
					}
					else if(b.getState() == BatchStateEnum.Failed){ 

						System.out.println("Reason: "+b.getStateMessage()+".\n  " +
								"Number of Records Processed: "+b.getNumberRecordsProcessed());
						throw (new Exception(""));
					}
				}
			}
		}catch(Exception ex){log.debug(" Exception occurred.");}
	}

 The getStateMessage() method of BatchInfo gives the discussed error messages.

In java development, which api is best for getting the organisation currency format details(like currency symbol, thousand separator,decimal separator).  Using this api, i need to display the data in my application  with same format present in the Salesforce .

 

$ 1.000,00