+ Start a Discussion
ALEX YAN 7ALEX YAN 7 

add new values to picklist when use metadata api

Hello,I want to add new values to picklist ,I import all class  which from https://github.com/financialforcedev/apex-mdapi  into my org.
I write a class named AddSegment.cls and  a test class  ,when I run test class to create Field ,it show error:Attempt to de-reference a null object, can someone tell me what wrong and what should I do.Thank you very much.
User-added image
User-added image

 
Best Answer chosen by ALEX YAN 7
sukanya banekarsukanya banekar
Hi,
I don't know what is your code returning? Need to check your whole code then only I can tell you why is it returning null.

Thanks,
Sukanya Banekar

All Answers

ALEX YAN 7ALEX YAN 7
I think results ==null, but I don't know why.
List<MetadataService.SaveResult> results = service.createMetadata( new MetadataService.Metadata[] { customField });
sukanya banekarsukanya banekar
Hi,
Write below statement before line no.102
if()
If(results <> NULL && !results.isEmpty()){
   handleSaveResults(results[0]);
}
Let me know if this works

Thanks,
Sukanya Banekar
 
ALEX YAN 7ALEX YAN 7
Thank you for your reply. If I add "If(results <> NULL && !results.isEmpty())" ,there is no error.  
But when use metadata api to create customField , results  should return something ? But I get results null. Is there anything wrong.
sukanya banekarsukanya banekar
Hi,
I don't know what is your code returning? Need to check your whole code then only I can tell you why is it returning null.

Thanks,
Sukanya Banekar
This was selected as the best answer