+ Start a Discussion
kumarcrm bingikumarcrm bingi 

Submitting an Account Record into an approval when the Account Rating on warm Approved send an email automatically

User-added image
I do not understand which list variable assigned the values were I am missing it's my code
global class SAPRequest{

WebService static void SendApprovalRequest(string id) {


// create the new approval request to submit
Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
req.setComments('Submitted for approval. Please approve.');
 req.setObjectId(id);
 req.setNextApproverIds(Id[]);
// submit the approval request for processing
Approval.ProcessResult result = Approval.Process(req);


// display if the reqeust was successful
System.debug('Submitted for approval successfully: '+result.isSuccess());
}
}
Error is showing Error: Compile Error: Missing ')' at '[' at line 10 column 27
 
Narender Singh(Nads)Narender Singh(Nads)
Hi Kumar,
Try this code:
global class SAPRequest{

	WebService static void SendApprovalRequest(string id) {

		list<id> ls=new list<id>();
        ls.add(id);
		// create the new approval request to submit
		Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
        req.setComments('Submitted for approval. Please approve.');
		req.setObjectId(id);
        req.setNextApproverIds(ls);
		// submit the approval request for processing
		Approval.ProcessResult result = Approval.Process(req);


		// display if the reqeust was successful
		System.debug('Submitted for approval successfully: '+result.isSuccess());
}

Let me know if it helps.
Thanks.
kumarcrm bingikumarcrm bingi
User-added image
showing error Field Integrity Exception. can you please help me 
Narender Singh(Nads)Narender Singh(Nads)
Hi Kumar,
It appears to be that the ID you are passing as an parameter is not a valid ID as per salesforce standard ID datatype. Make sure the ID you are passing is a valid ID. I might be able to help you if you could just show me the script on have written for your button.
kumarcrm bingikumarcrm bingi
Hi 
Narender Singh(Nads),
This is my JavaScript code
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 
sforce.apex.execute("SAPRequest","SendApprovalRequest", {Id:"{!Account.Id}"}); 
window.alert("Record sent for approval" );
 
Narender Singh(Nads)Narender Singh(Nads)
Hi kumar,
I think i found out what is causing this field integrity error.

setNextApproverIds() method accepts a list of IDs where these IDs are associated with a user. But in the code an account record ID is being inserted into the list ls. But the method is expecting an ID which is of User type. Hence the error.

Perform an SOQL to get the ID of the user who you want to be the next approver. Add that id to the ls list. And you are good to go.

Let me know if that helps
Thanks!

 
kumarcrm bingikumarcrm bingi
Hi Narender Singh(Nads),
 if you don't mind i am not get it . can you please right code some more please 
Thank you
Giri Kumar
Narender Singh(Nads)Narender Singh(Nads)
Hi kumar,

Try this:
global class SAPRequest{

	WebService static void SendApprovalRequest(string id) {

		list<id> NextApproverIDlist=new list<id>();
		ID userId=userinfo.getUserId();// This will give you user ID
        NextApproverIDlist.add(userid);//Adding user ID to the list
		// create the new approval request to submit
		Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
        req.setComments('Submitted for approval. Please approve.');
		req.setObjectId(id);
        req.setNextApproverIds(NextApproverIDlist);
		// submit the approval request for processing
		Approval.ProcessResult result = Approval.Process(req);


		// display if the reqeust was successful
		System.debug('Submitted for approval successfully: '+result.isSuccess());
}
Let me know if it helps
Thanks!